Build of v6.26/00 failed in compiling CPPConstructor.cxx

Hi,

The build of v6.26/00 with Python 3.10.2 failed in compiling CPPConstructor.cxx as the following:


In file included from /usr/include/python3.11/Python.h:42,
                 from /home/furutaka/work/root/root.git/bindings/pyroot/cppyy/CPyCppyy/src/CPyCppyy.h:35,
                 from /home/furutaka/work/root/root.git/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx:2:
/home/furutaka/work/root/root.git/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx: In member function ‘virtual PyObject* CPyCppyy::CPPConstructor::Call(CPyCppyy::CPPInstance*&, PyObject*, PyObject*, CPyCppyy::CallContext*)’:
/home/furutaka/work/root/root.git/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx:125:17: error: lvalue required as left operand of assignment
  125 |                 Py_TYPE(self) = (PyTypeObject*)pyclass;
      |                 ^~~~~~~

The following change seems to fix this, according to this report:

diff --git a/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx b/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx
index 0c564aff83..395fb27bdb 100644
--- a/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx
+++ b/bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx
@@ -12,6 +12,12 @@
 // Standard
 #include <string>
 
+// https://bugzilla.redhat.com/show_bug.cgi?id=2021796
+#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
+static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
+{ ob->ob_type = type; }
+#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
+#endif
 
 //- protected members --------------------------------------------------------
 bool CPyCppyy::CPPConstructor::InitExecutor_(Executor*& executor, CallContext*)
@@ -122,7 +128,7 @@ PyObject* CPyCppyy::CPPConstructor::Call(
             if (pyclass) {
                 self->SetSmart((PyObject*)Py_TYPE(self));
                 Py_DECREF((PyObject*)Py_TYPE(self));
-                Py_TYPE(self) = (PyTypeObject*)pyclass;
+                Py_SET_TYPE(self,(PyTypeObject*)pyclass);
             }
         }

Please read tips for efficient and successful posting and posting code

ROOT Version: v6.26/00
Platform: Fedora 35 (x86_64)
Compiler: c++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)


Hello,

Thank you for reporting, does this happen with Python 3.10.2 or with Python 3.11 as both the error you pasted and the report you linked seem to suggest?

According to this:

https://docs.python.org/3.11/whatsnew/3.11.html

it’s a change in 3.11 and they propose the same solution as you reported.

PR is up:

Well, I tried to check with 3.11 and found that it’s already installed and, I do not understand why, but on one hand I got

$ python --version
Python 3.10.2
$ which python
/usr/bin/python
$ ls -l `which python`
lrwxrwxrwx. 1 root root 9 Jan 18 03:49 /usr/bin/python -> ./python3
$ ls -l /usr/bin/python3
lrwxrwxrwx. 1 root root 10 Jan 18 03:27 /usr/bin/python3 -> python3.10
$ ls -l /usr/bin/python3.{[0-9],1?}
-rwxr-xr-x. 1 root root 15944 Jan 18 03:27 /usr/bin/python3.10
-rwxr-xr-x. 1 root root 15944 Feb  5 00:26 /usr/bin/python3.11
-rwxr-xr-x. 2 root root 15648 Sep 18 00:55 /usr/bin/python3.5
-rwxr-xr-x. 2 root root 15952 Sep  7 16:30 /usr/bin/python3.6
-rwxr-xr-x. 2 root root 15944 Feb 18 01:42 /usr/bin/python3.7
-rwxr-xr-x. 1 root root 15944 Feb 17 21:45 /usr/bin/python3.8
-rwxr-xr-x. 1 root root 15944 Jan 18 03:24 /usr/bin/python3.9

grepping the CMakeCache.txt returns

$ grep PYTHON root-v6-26-00-bld/CMakeCache.txt 
CLANG_PYTHON_BINDINGS_VERSIONS:STRING=
CMAKE_INSTALL_PYTHONDIR:PATH=lib
//ADVANCED property for variable: CLANG_PYTHON_BINDINGS_VERSIONS
CLANG_PYTHON_BINDINGS_VERSIONS-ADVANCED:INTERNAL=1
PYTHON_INCLUDE_DIRS:INTERNAL=/usr/include/python3.11
PYTHON_LIBRARIES:INTERNAL=/usr/lib64/libpython3.11.so
PYTHON_LIBRARY_DIR:INTERNAL=/usr/lib64
PYTHON_VERSION_MAJOR:INTERNAL=3
PYTHON_VERSION_MINOR:INTERNAL=11
PYTHON_VERSION_STRING:INTERNAL=3.11.0

:roll_eyes:

Do cmake try to find the latest python?

Kazuyoshi

Hello,

Yes, in this case CMake picked the highest it could find.

You can use -DPython3_EXECUTABLE=path/to/3.10.2/python to point CMake to the 3.10.2 installation instead.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.