[pypy-dev] PyCXX and PyPy status

Barry Scott barry at barrys-emacs.org
Tue Oct 2 14:52:37 EDT 2018


I'm the maintainer of the PyCXX C++ extension interface to Python C API.

PyCXX source code is a SVN repo at: https://svn.code.sf.net/p/cxx/code/trunk/CXX

I have been working to get PyCXX to build and run against PyPy C API.

I am happy to have PyPy specific code in PyCXX where necessary.

Using PyPy 0.6.0 on macOS I managed to build a .so that crashed when imported.

The reason is that the PyPy's C API does not allow tuples to be created.
The pattern in CPython is like this:

explicit Tuple (const Sequence& s)
        {
            sequence_index_type limit( sequence_index_type( s.length() ) );

            set(PyTuple_New (limit), true);
            validate();

            for(sequence_index_type i=0; i < limit; i++)
            {
                if(PyTuple_SetItem (ptr(), i, new_reference_to(s[i])) == -1)
                {
                    ifPyErrorThrowCxxException();
                }
            }
        }

The PyTuple_SetItem() always fails. Its a must have to create tuples.
How do you expect a tuple to be created?

I have a build of the tip from the PyPy HG repo. This has regressed from the 0.6.0 release:

g++ -c -g -Wall -fPIC -fexceptions -frtti -I. -ISrc -I/home/barry/tmpdir/usession-default-barry/build/pypy-qqq/include -DNDEBUG  -oobj/simple.obj  Demo/Python2/simple.cxx
In file included from ./CXX/Objects.hxx:40,
                 from Demo/Python2/simple.cxx:15:
./CXX/Python2/Objects.hxx: In member function ‘void Py::MapBase<T>::delItem(const string&)’:
./CXX/Python2/Objects.hxx:3041:17: error: there are no arguments to ‘PyMapping_DelItemString’ that depend on a template parameter, so a declaration of ‘PyMapping_DelItemString’ must be available [-fpermissive]
             if (PyMapping_DelItemString (ptr(), const_cast<char*>(s.c_str())) == -1)
                 ^~~~~~~~~~~~~~~~~~~~~~~
./CXX/Python2/Objects.hxx:3041:17: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
./CXX/Python2/Objects.hxx: In member function ‘void Py::MapBase<T>::delItem(const Py::Object&)’:
./CXX/Python2/Objects.hxx:3049:17: error: there are no arguments to ‘PyMapping_DelItem’ that depend on a template parameter, so a declaration of ‘PyMapping_DelItem’ must be available [-fpermissive]
             if (PyMapping_DelItem (ptr(), *s) == -1)
                 ^~~~~~~~~~~~~~~~~

It seems that PyMapping_DelItem and PyMapping_DelString have been removed since 0.6.0.
Can they be restored?

Oh and where does the magic "44" come from that I had to use in the <extension>.pypy-44.so file name?

Barry



More information about the pypy-dev mailing list