Skip to content

Commit

Permalink
Use Py_SET_SIZE() to support Python 3.11
Browse files Browse the repository at this point in the history
* Replace "Py_TYPE(obj) = type" with "Py_SET_TYPE(obj, type)"
* Replace "Py_SIZE(obj) = size" with "Py_SET_SIZE(obj, size)"
* Replace "Py_REFCNT(obj) = refcnt" with "Py_SET_REFCNT(obj, refcnt)"
* Add pythoncapi_compat.h to get these functions on Python 3.8 and
  older. File copied from:
  https://github.com/pythoncapi/pythoncapi_compat

On Python 3.10, Py_REFCNT() can no longer be used as an l-value to
set a reference count:

* https://docs.python.org/dev/c-api/structures.html#c.Py_REFCNT
* https://docs.python.org/dev/whatsnew/3.10.html#id2

On Python 3.11, Py_TYPE() and Py_SIZE() can no longer as l-values be used to set
an object type and size:

* https://docs.python.org/dev/c-api/structures.html#c.Py_TYPE
* https://docs.python.org/dev/c-api/structures.html#c.Py_SIZE
* https://docs.python.org/dev/whatsnew/3.11.html#id2
  • Loading branch information
vstinner authored and zhuyifei1999 committed Jan 27, 2022
1 parent 366f3a0 commit 4cb9fcb
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/heapy/heapyc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ char heapyc_doc[] =
#include "compile.h"
#include "frameobject.h"
#include "../include/guppy.h"
#include "../include/pythoncapi_compat.h"
#include "../sets/nodeset.h"
#include "hpinit.h"
#include "heapdef.h"
Expand Down Expand Up @@ -224,7 +225,7 @@ INITFUNC (void)
PyObject *m = NULL;
PyObject *d;

Py_TYPE(&_Ny_RootStateStruct) = &NyRootState_Type;
Py_SET_TYPE(&_Ny_RootStateStruct, &NyRootState_Type);

// This has to be here because of 'initializer is not a constant'
// build error on Windows.
Expand Down
Loading

0 comments on commit 4cb9fcb

Please sign in to comment.