mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 02:13:44 +03:00
Merge pull request #1131 from jouve/py3.10compat
use Py_SET_TYPE for compat with python 3.10
This commit is contained in:
commit
3aadecebaa
|
@ -918,7 +918,7 @@ add_module_types(PyObject *module)
|
||||||
for (i = 0; typetable[i].name; i++) {
|
for (i = 0; typetable[i].name; i++) {
|
||||||
PyObject *type = (PyObject *)typetable[i].type;
|
PyObject *type = (PyObject *)typetable[i].type;
|
||||||
|
|
||||||
Py_TYPE(typetable[i].type) = &PyType_Type;
|
Py_SET_TYPE(typetable[i].type, &PyType_Type);
|
||||||
if (0 > PyType_Ready(typetable[i].type)) { return -1; }
|
if (0 > PyType_Ready(typetable[i].type)) { return -1; }
|
||||||
|
|
||||||
Py_INCREF(type);
|
Py_INCREF(type);
|
||||||
|
@ -950,7 +950,7 @@ datetime_init(void)
|
||||||
if (0 > repl_curs_datetime_init()) { return -1; }
|
if (0 > repl_curs_datetime_init()) { return -1; }
|
||||||
if (0 > replmsg_datetime_init()) { return -1; }
|
if (0 > replmsg_datetime_init()) { return -1; }
|
||||||
|
|
||||||
Py_TYPE(&pydatetimeType) = &PyType_Type;
|
Py_SET_TYPE(&pydatetimeType, &PyType_Type);
|
||||||
if (0 > PyType_Ready(&pydatetimeType)) { return -1; }
|
if (0 > PyType_Ready(&pydatetimeType)) { return -1; }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -962,7 +962,7 @@ mxdatetime_init(PyObject *module)
|
||||||
Dprintf("psycopgmodule: initializing mx.DateTime module");
|
Dprintf("psycopgmodule: initializing mx.DateTime module");
|
||||||
|
|
||||||
#ifdef HAVE_MXDATETIME
|
#ifdef HAVE_MXDATETIME
|
||||||
Py_TYPE(&mxdatetimeType) = &PyType_Type;
|
Py_SET_TYPE(&mxdatetimeType, &PyType_Type);
|
||||||
if (0 > PyType_Ready(&mxdatetimeType)) { return -1; }
|
if (0 > PyType_Ready(&mxdatetimeType)) { return -1; }
|
||||||
|
|
||||||
if (mxDateTime_ImportModuleAndAPI()) {
|
if (mxDateTime_ImportModuleAndAPI()) {
|
||||||
|
@ -1082,13 +1082,13 @@ INIT_MODULE(_psycopg)(void)
|
||||||
libcrypto_threads_init();
|
libcrypto_threads_init();
|
||||||
|
|
||||||
/* initialize types and objects not exposed to the module */
|
/* initialize types and objects not exposed to the module */
|
||||||
Py_TYPE(&typecastType) = &PyType_Type;
|
Py_SET_TYPE(&typecastType, &PyType_Type);
|
||||||
if (0 > PyType_Ready(&typecastType)) { goto exit; }
|
if (0 > PyType_Ready(&typecastType)) { goto exit; }
|
||||||
|
|
||||||
Py_TYPE(&chunkType) = &PyType_Type;
|
Py_SET_TYPE(&chunkType, &PyType_Type);
|
||||||
if (0 > PyType_Ready(&chunkType)) { goto exit; }
|
if (0 > PyType_Ready(&chunkType)) { goto exit; }
|
||||||
|
|
||||||
Py_TYPE(&errorType) = &PyType_Type;
|
Py_SET_TYPE(&errorType, &PyType_Type);
|
||||||
errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
|
errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
|
||||||
if (0 > PyType_Ready(&errorType)) { goto exit; }
|
if (0 > PyType_Ready(&errorType)) { goto exit; }
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,14 @@ typedef long Py_hash_t;
|
||||||
typedef unsigned long Py_uhash_t;
|
typedef unsigned long Py_uhash_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Since Py_TYPE() is changed to the inline static function,
|
||||||
|
* Py_TYPE(obj) = new_type must be replaced with Py_SET_TYPE(obj, new_type)
|
||||||
|
* https://docs.python.org/3.10/whatsnew/3.10.html#id2
|
||||||
|
*/
|
||||||
|
#if PY_VERSION_HEX < 0x030900A4
|
||||||
|
#define Py_SET_TYPE(obj, type) ((Py_TYPE(obj) = (type)), (void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* FORMAT_CODE_PY_SSIZE_T is for Py_ssize_t: */
|
/* FORMAT_CODE_PY_SSIZE_T is for Py_ssize_t: */
|
||||||
#define FORMAT_CODE_PY_SSIZE_T "%" PY_FORMAT_SIZE_T "d"
|
#define FORMAT_CODE_PY_SSIZE_T "%" PY_FORMAT_SIZE_T "d"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user