Merge pull request #1131 from jouve/py3.10compat

use Py_SET_TYPE for compat with python 3.10
This commit is contained in:
Daniele Varrazzo 2020-08-24 01:54:57 +01:00 committed by GitHub
commit 3aadecebaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -918,7 +918,7 @@ add_module_types(PyObject *module)
for (i = 0; typetable[i].name; i++) {
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; }
Py_INCREF(type);
@ -950,7 +950,7 @@ datetime_init(void)
if (0 > repl_curs_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; }
return 0;
@ -962,7 +962,7 @@ mxdatetime_init(PyObject *module)
Dprintf("psycopgmodule: initializing mx.DateTime module");
#ifdef HAVE_MXDATETIME
Py_TYPE(&mxdatetimeType) = &PyType_Type;
Py_SET_TYPE(&mxdatetimeType, &PyType_Type);
if (0 > PyType_Ready(&mxdatetimeType)) { return -1; }
if (mxDateTime_ImportModuleAndAPI()) {
@ -1082,13 +1082,13 @@ INIT_MODULE(_psycopg)(void)
libcrypto_threads_init();
/* 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; }
Py_TYPE(&chunkType) = &PyType_Type;
Py_SET_TYPE(&chunkType, &PyType_Type);
if (0 > PyType_Ready(&chunkType)) { goto exit; }
Py_TYPE(&errorType) = &PyType_Type;
Py_SET_TYPE(&errorType, &PyType_Type);
errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
if (0 > PyType_Ready(&errorType)) { goto exit; }

View File

@ -52,6 +52,14 @@ typedef long Py_hash_t;
typedef unsigned long Py_uhash_t;
#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: */
#define FORMAT_CODE_PY_SSIZE_T "%" PY_FORMAT_SIZE_T "d"