Skip to content

Commit 79c54ee

Browse files
committed
fix building with python 3.12
1 parent e68e47b commit 79c54ee

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

IfxPy/ifxpyc.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,13 @@ static PyObject* getSQLWCharAsPyUnicodeObject(SQLWCHAR* sqlwcharData, SQLLEN sql
21962196
if (maxuniValue <= 65536)
21972197
{
21982198
/* this is UCS2 python.. nothing to do really */
2199-
return PyUnicode_FromUnicode((Py_UNICODE *)sqlwcharData, sqlwcharBytesLen / sizeof(SQLWCHAR));
2199+
#if PY_VERSION_HEX >= 0x03030000
2200+
// For Python 3.3 and above
2201+
return PyUnicode_FromWideChar((Py_UNICODE *)sqlwcharData, sqlwcharBytesLen / sizeof(SQLWCHAR));
2202+
#else
2203+
// For Python versions below 3.3
2204+
return PyUnicode_FromUnicode((Py_UNICODE *)sqlwcharData, sqlwcharBytesLen / sizeof(SQLWCHAR));
2205+
#endif
22002206
}
22012207

22022208
if (is_bigendian())
@@ -2230,8 +2236,14 @@ static SQLWCHAR* getUnicodeDataAsSQLWCHAR(PyObject *pyobj, int *isNewBuffer)
22302236
Py_ssize_t nCharLen = 0;
22312237

22322238
*isNewBuffer = 0;
2233-
nCharLen = PyUnicode_GET_SIZE(pyobj);
2234-
2239+
#if PY_VERSION_HEX >= 0x03030000
2240+
// For Python 3.3 and above
2241+
nCharLen = PyUnicode_GetSize(pyobj);
2242+
#else
2243+
// For Python versions below 3.3
2244+
nCharLen = PyUnicode_GET_SIZE(pyobj);
2245+
#endif
2246+
22352247
pNewBuffer = (SQLWCHAR *)ALLOC_N(SQLWCHAR, nCharLen + 1);
22362248
if ( pNewBuffer != NULL)
22372249
{
@@ -2251,7 +2263,14 @@ static SQLWCHAR* xgetUnicodeDataAsSQLWCHAR(PyObject *pyobj, int *isNewBuffer)
22512263
long maxuniValue;
22522264
PyObject *pyUTFobj;
22532265
SQLWCHAR* pNewBuffer = NULL;
2266+
#if PY_VERSION_HEX >= 0x03030000
2267+
// For Python 3.3 and above
2268+
Py_ssize_t nCharLen = PyUnicode_GetSize(pyobj);
2269+
#else
2270+
// For Python versions below 3.3
22542271
Py_ssize_t nCharLen = PyUnicode_GET_SIZE(pyobj);
2272+
#endif
2273+
22552274

22562275
sysmodule = PyImport_ImportModule("sys");
22572276
maxuni = PyObject_GetAttrString(sysmodule, "maxunicode");

IfxPy/ifxpyc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ typedef int Py_ssize_t;
8383
#define StringOBJ_FromASCII(str) PyUnicode_DecodeASCII(str, strlen(str), NULL)
8484
#define PyString_Check PyUnicode_Check
8585
#define StringObj_Format PyUnicode_Format
86-
#define StringObj_Size PyUnicode_GET_SIZE
86+
#if PY_VERSION_HEX >= 0x03030000
87+
#define StringObj_Size PyUnicode_GetSize
88+
89+
#else // For Python versions below 3.3
90+
#define StringObj_Size PyUnicode_GET_SIZE
91+
#endif
8792
#define MOD_RETURN_ERROR NULL
8893
#define MOD_RETURN_VAL(mod) mod
8994
#define INIT_IfxPy PyInit_IfxPy

IfxPy/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
include_dirs = [py_home + '\\include', csdk_home + '\\incl\\cli'],
173173
libraries = ['iclit09b'],
174174
define_macros=definitions,
175-
library_dirs = [ py_home + '\libs', csdk_home + '\lib'],
175+
library_dirs = [ py_home + r'\libs', csdk_home + r'\lib'],
176176
sources = ['ifxpyc.c'])
177177
else:
178178
IfxPyNative_ext_modules = Extension('IfxPy',

0 commit comments

Comments
 (0)