question about SWIG_ConvertPtr and python 3.11

"Langer, Stephen A. \(Fed\) via Swig-user" <[email protected]> Mon, 21 Aug 2023 23:03:08 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <PH0PR09MB1054367AF983679EB1063CC52E61EA@PH0PR09MB10543.namprd09.prod.outlook.com>
Hi --

I have a C++ base class that is swigged, and a python class is derived from it.  An object of the derived class is passed back to a C++ routine.  In that routine I want access to both the PyObject* for the derived python object and also the C++ pointer to the base class.   So in the C++ routine I've been converting the PyObject* to a base class pointer like this:
     void f(PyObject *obj)
    {
        Base *bptr;
        SWIG_ConvertPtr(obj, (void**) &bptr, ((SwigPyObject*) obj)->ty, 0);
       etc.
   }
This works (or seems to work) with swig 4.1.1 and python 3.8 through 3.10, but it seg faults with 3.11.  The seg fault occurs when evaluating iter->type in SWIG_TypeCheck.

Is extracting the type information by accessing SwigPyObject::ty legal?  Is there a better way to do what I want to do?  It seems that the type information is easily available in typemaps via $descriptor, but not so easily in C++ code outside of a typemap.

Thanks.
-- Steve

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user