diff options
-rw-r--r-- | psycopg/python.h | 65 | ||||
-rw-r--r-- | psycopg/utils.h | 3 |
2 files changed, 32 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) */ diff --git a/psycopg/utils.h b/psycopg/utils.h index bb9f0c3..ab4aacd 100644 --- a/psycopg/utils.h +++ b/psycopg/utils.h @@ -58,4 +58,7 @@ HIDDEN RAISES BORROWED PyObject *psyco_set_error( HIDDEN PyObject *psyco_GetDecimalType(void); +HIDDEN PyObject *Bytes_Format(PyObject *format, PyObject *args); + + #endif /* !defined(UTILS_H) */ |