diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-03-16 17:56:07 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-03-16 19:54:40 +0000 |
commit | e922e2a96e2437d8a0d9c73a3239e4da0cf031ee (patch) | |
tree | 501bab865a4b2a1e589f9ba4ff2ad7fea4c0dac8 /psycopg/python.h | |
parent | fec0a5587df4be1800e6b86926aed74308759e92 (diff) | |
download | psycopg2-e922e2a96e2437d8a0d9c73a3239e4da0cf031ee.tar.gz |
Py2/3 compatibility macro definitions rationalized
Diffstat (limited to 'psycopg/python.h')
-rw-r--r-- | psycopg/python.h | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/psycopg/python.h b/psycopg/python.h index 487cd4a..521c568 100644 --- a/psycopg/python.h +++ b/psycopg/python.h @@ -63,22 +63,44 @@ typedef unsigned long Py_uhash_t; #define FORMAT_CODE_SIZE_T "%zu" #endif -/* Abstract from text type. Only supported for ASCII and UTF-8 */ #if PY_2 + #define Text_Type PyString_Type #define Text_Check(s) PyString_Check(s) #define Text_Format(f,a) PyString_Format(f,a) #define Text_FromUTF8(s) PyString_FromString(s) #define Text_FromUTF8AndSize(s,n) PyString_FromStringAndSize(s,n) -#else + +#define Bytes_Type PyString_Type +#define Bytes_Check PyString_Check +#define Bytes_CheckExact PyString_CheckExact +#define Bytes_AS_STRING PyString_AS_STRING +#define Bytes_GET_SIZE PyString_GET_SIZE +#define Bytes_Size PyString_Size +#define Bytes_AsString PyString_AsString +#define Bytes_AsStringAndSize PyString_AsStringAndSize +#define Bytes_FromString PyString_FromString +#define Bytes_FromStringAndSize PyString_FromStringAndSize +#define Bytes_FromFormat PyString_FromFormat +#define Bytes_ConcatAndDel PyString_ConcatAndDel +#define _Bytes_Resize _PyString_Resize + +#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days) +#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds) +#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) + +#define INIT_MODULE(m) init ## m + +#endif /* PY_2 */ + +#if PY_3 + #define Text_Type PyUnicode_Type #define Text_Check(s) PyUnicode_Check(s) #define Text_Format(f,a) PyUnicode_Format(f,a) #define Text_FromUTF8(s) PyUnicode_FromString(s) #define Text_FromUTF8AndSize(s,n) PyUnicode_FromStringAndSize(s,n) -#endif -#if PY_3 #define PyInt_Type PyLong_Type #define PyInt_Check PyLong_Check #define PyInt_AsLong PyLong_AsLong @@ -90,33 +112,11 @@ typedef unsigned long Py_uhash_t; #define Py_TPFLAGS_HAVE_ITER 0L #define Py_TPFLAGS_HAVE_RICHCOMPARE 0L #define Py_TPFLAGS_HAVE_WEAKREFS 0L + #ifndef PyNumber_Int #define PyNumber_Int PyNumber_Long #endif -#endif /* PY_3 */ - -#if PY_2 -#define Bytes_Type PyString_Type -#define Bytes_Check PyString_Check -#define Bytes_CheckExact PyString_CheckExact -#define Bytes_AS_STRING PyString_AS_STRING -#define Bytes_GET_SIZE PyString_GET_SIZE -#define Bytes_Size PyString_Size -#define Bytes_AsString PyString_AsString -#define Bytes_AsStringAndSize PyString_AsStringAndSize -#define Bytes_FromString PyString_FromString -#define Bytes_FromStringAndSize PyString_FromStringAndSize -#define Bytes_FromFormat PyString_FromFormat -#define Bytes_ConcatAndDel PyString_ConcatAndDel -#define _Bytes_Resize _PyString_Resize - -#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days) -#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds) -#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) - -#else - #define Bytes_Type PyBytes_Type #define Bytes_Check PyBytes_Check #define Bytes_CheckExact PyBytes_CheckExact @@ -131,15 +131,8 @@ typedef unsigned long Py_uhash_t; #define Bytes_ConcatAndDel PyBytes_ConcatAndDel #define _Bytes_Resize _PyBytes_Resize -#endif - -HIDDEN PyObject *Bytes_Format(PyObject *format, PyObject *args); - -/* Mangle the module name into the name of the module init function */ -#if PY_3 #define INIT_MODULE(m) PyInit_ ## m -#else -#define INIT_MODULE(m) init ## m -#endif + +#endif /* PY_3 */ #endif /* !defined(PSYCOPG_PYTHON_H) */ |