summaryrefslogtreecommitdiff
path: root/psycopg/python.h
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-09-04 12:27:16 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-09-04 12:30:18 +0100
commit80df0553a6450df25fa96ee4dbb6acf63efb8ffc (patch)
treef6eed1aea6492155cbc2a33e8c164b42f1780290 /psycopg/python.h
parent4d10f1235fed1c0aa5958cc4a9248688c3345aad (diff)
downloadpsycopg2-fix-961.tar.gz
Fixed handling large Oid valuesfix-961
Oid is defined as unsigned 32. On some Python implementations (probably the ones where maxint = 2 ** 31) this can cause int overflow for large values (see #961). On my 64 box it doesn't seem the case. Oid handling was sloppy here and there (messages, casts...): trying to use uint everywhere, and added a couple of helper macros to treat Oid consistently. Close #961.
Diffstat (limited to 'psycopg/python.h')
-rw-r--r--psycopg/python.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/psycopg/python.h b/psycopg/python.h
index 521c568..f45aeb5 100644
--- a/psycopg/python.h
+++ b/psycopg/python.h
@@ -91,6 +91,11 @@ typedef unsigned long Py_uhash_t;
#define INIT_MODULE(m) init ## m
+/* fix #961, but don't change all types to longs. Sure someone will complain. */
+#define PyLong_FromOid(x) (((x) & 0x80000000) ? \
+ PyLong_FromUnsignedLong((unsigned long)(x)) : \
+ PyInt_FromLong((x)))
+
#endif /* PY_2 */
#if PY_3
@@ -133,6 +138,11 @@ typedef unsigned long Py_uhash_t;
#define INIT_MODULE(m) PyInit_ ## m
+#define PyLong_FromOid(x) (PyLong_FromUnsignedLong((unsigned long)(x)))
+
#endif /* PY_3 */
+/* expose Oid attributes in Python C objects */
+#define T_OID T_UINT
+
#endif /* !defined(PSYCOPG_PYTHON_H) */