summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorCyril Jouve <jv.cyril@gmail.com>2020-07-26 15:41:53 +0200
committerCyril Jouve <jv.cyril@gmail.com>2020-07-26 15:41:53 +0200
commit442f300e9152aa6c57a50fc797dc0828b5fb979b (patch)
treee1bceaca2b3c2ecdc4d2789d3d495c00af6f0703 /psycopg
parentcecff195fc17a83d593dd62c239aa188883a844e (diff)
downloadpsycopg2-442f300e9152aa6c57a50fc797dc0828b5fb979b.tar.gz
use Py_SET_TYPE for compat with python 3.10
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/psycopgmodule.c12
-rw-r--r--psycopg/python.h8
2 files changed, 14 insertions, 6 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 14e4436..36fd1f9 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -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; }
diff --git a/psycopg/python.h b/psycopg/python.h
index 2a5f9d8..f7f5396 100644
--- a/psycopg/python.h
+++ b/psycopg/python.h
@@ -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"