test/upcast.cpp does not compile since python 3.10

Open
#479 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp, python
Domain
testing-qa

Research direction

Start by reading test/upcast.cpp at lines 16-17 and reproducing the reported compilation with Python 3.10 or 3.13 headers. Compare the Py_REFCNT usage with the changed Python C API, then verify that test/upcast.cpp compiles successfully with the newer Python versions.

Written by the indexing model from the issue text.

Description

revision: 3e7be69e1e405e1d5ddd232c69c024ee441592c5

Since Python 3.10, compilation of test/upcast.cpp fails.

https://github.com/boostorg/python/blob/3e7be69e1e405e1d5ddd232c69c024ee441592c5/test/upcast.cpp#L16-L17

$ g++ -Iinclude -I/opt/miniconda3/envs/py310/include/python3.10 test/upcast.cpp
In file included from /usr/include/boost/detail/lightweight_test.hpp:15,
                 from ./test/upcast.cpp:7:
./test/upcast.cpp: In function 'int main()':
/opt/miniconda3/envs/py310/include/python3.10/object.h:133:33: error: lvalue required as unary '&' operand
  133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
./test/upcast.cpp:16:17: note: in expansion of macro 'Py_REFCNT'
   16 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&o)) == &Py_REFCNT(&o));
      |                 ^~~~~~~~~
/opt/miniconda3/envs/py310/include/python3.10/object.h:133:33: error: lvalue required as unary '&' operand
  133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
./test/upcast.cpp:16:68: note: in expansion of macro 'Py_REFCNT'
   16 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&o)) == &Py_REFCNT(&o));
      |                                                                    ^~~~~~~~~
/opt/miniconda3/envs/py310/include/python3.10/object.h:133:33: error: lvalue required as unary '&' operand
  133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
./test/upcast.cpp:17:17: note: in expansion of macro 'Py_REFCNT'
   17 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&y)) == &Py_REFCNT(&y));
      |                 ^~~~~~~~~
/opt/miniconda3/envs/py310/include/python3.10/object.h:133:33: error: lvalue required as unary '&' operand
  133 | #define Py_REFCNT(ob) _Py_REFCNT(_PyObject_CAST_CONST(ob))
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
./test/upcast.cpp:17:68: note: in expansion of macro 'Py_REFCNT'
   17 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&y)) == &Py_REFCNT(&y));
      |                                                                    ^~~~~~~~~
$ g++ -Iinclude -I/usr/include/python3.13 test/upcast.cpp
In file included from /usr/include/boost/detail/lightweight_test.hpp:15,
                 from test/upcast.cpp:7:
test/upcast.cpp: In function 'int main()':
/usr/include/python3.13/object.h:330:34: error: lvalue required as unary '&' operand
  330 | #  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
test/upcast.cpp:16:17: note: in expansion of macro 'Py_REFCNT'
   16 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&o)) == &Py_REFCNT(&o));
      |                 ^~~~~~~~~
/usr/include/python3.13/object.h:330:34: error: lvalue required as unary '&' operand
  330 | #  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
test/upcast.cpp:16:68: note: in expansion of macro 'Py_REFCNT'
   16 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&o)) == &Py_REFCNT(&o));
      |                                                                    ^~~~~~~~~
/usr/include/python3.13/object.h:330:34: error: lvalue required as unary '&' operand
  330 | #  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
test/upcast.cpp:17:17: note: in expansion of macro 'Py_REFCNT'
   17 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&y)) == &Py_REFCNT(&y));
      |                 ^~~~~~~~~
/usr/include/python3.13/object.h:330:34: error: lvalue required as unary '&' operand
  330 | #  define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
test/upcast.cpp:17:68: note: in expansion of macro 'Py_REFCNT'
   17 |     BOOST_TEST(&Py_REFCNT(boost::python::upcast<PyObject>(&y)) == &Py_REFCNT(&y));
      |                                                                    ^~~~~~~~~

This is because Py_REFCNT() is changed to the inline static function.

Unfortunately, the CI images use python upto 3.8, so the issue has not been found.

Dominant language
C++
Stars
537
Forks
223
Avg merge
11h 22m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/python

All issues in boostorg/python

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.