Closed mgedmin closed 3 years ago
In Python 3.9 and earlier, Py_SIZE
is a macro, and Py_SIZE(self)
expands to (((PyVarObject*)self)->ob_size)
. This is just an integer field of the object, and as such it can be used as a value (rvalue) and assignment target (lvalue).
In 3.10, as part of a broader project to overhaul the C API, some uses of macros have been replaced with functions:
static inline Py_ssize_t _Py_SIZE(const PyVarObject *ob) {
return ob->ob_size;
}
#define Py_SIZE(ob) _Py_SIZE((PyVarObject*)(ob))
A function call is not a valid assignment target, so all uses of Py_SIZE
on the left-hand side have to be changed. Given that the function is declared inline anyway, and thus not part of the stable ABI, it's probably OK to define our own macro equivalent to the original Py_SIZE
macro and use that.
_PyUnicode_AsStringAndSize
is also a simple define for backwards compatibility:
#define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize
PyUnicode_AsUTF8AndSize
exists all the way back in 3.4 so that should be a simple replacement.
Upstream added a macro, Py_SET_SIZE
, in python 3.9, in case that is helpful for you. I understand that Py_SIZE
will be an lvalue in python 3.10 after all, due to a lot of breakage of this sort.
We are hitting another problem while trying to build Fedora packages with python 3.10 alpha versions:
Traceback (most recent call last):
File "/builddir/build/BUILD/zodbpickle-2.0.0/setup.py", line 45, in <module>
setup(
File "/usr/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in
setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python3.10/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.10/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.10/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.10/site-packages/setuptools/command/test.py", line
232, in run
self.run_tests()
File "/usr/lib/python3.10/site-packages/setuptools/command/test.py", line
250, in run_tests
test = unittest.main(
File "/usr/lib64/python3.10/unittest/main.py", line 100, in __init__
self.parseArgs(argv)
File "/usr/lib64/python3.10/unittest/main.py", line 147, in parseArgs
self.createTests()
File "/usr/lib64/python3.10/unittest/main.py", line 158, in createTests
self.test = self.testLoader.loadTestsFromNames(self.testNames,
File "/usr/lib64/python3.10/unittest/loader.py", line 220, in
loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib64/python3.10/unittest/loader.py", line 220, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib64/python3.10/unittest/loader.py", line 205, in
loadTestsFromName
test = obj()
File
"/builddir/build/BUILD/zodbpickle-2.0.0/src/zodbpickle/tests/test_pickle.py",
line 27, in test_suite
from .test_pickle_3 import test_suite
File
"/builddir/build/BUILD/zodbpickle-2.0.0/src/zodbpickle/tests/test_pickle_3.py",
line 7, in <module>
from .pickletester_3 import AbstractPickleTests
File
"/builddir/build/BUILD/zodbpickle-2.0.0/src/zodbpickle/tests/pickletester_3.py",
line 10, in <module>
from test.support import (
ImportError: cannot import name 'TESTFN' from 'test.support'
(/usr/lib64/python3.10/test/support/__init__.py)
test.support
is an internal module; it does not provide a stable API. TESTFN
was removed:
https://bugs.python.org/issue40275
As a stop-gap measure, it can be imported from test.support.os_helper
instead (still internal and unstable).
I posted a pull request (#60) that does build and test fine on 3.9/3.10 but doesn't support older versions - if that is helpful at all.
The change to Py_SIZE
was reverted because it broke the world..
Trying to build zodbpickle on Python 3.10.0a2 fails with