Embedding Python crash on PyTuple_New

MRAB python at mrabarnett.plus.com
Tue Nov 23 12:44:07 EST 2021


On 2021-11-23 17:31, MRAB wrote:
> On 2021-11-23 16:04, Arnaud Loonstra wrote:
[snip]
>> 
>> I would turn my attention to s_py_zosc function but I'm not sure. Since
>> the errors are GC related it could caused anywhere?
>> 
> Basically, yes, but I won't be surprised if it was due to too few
> INCREFs or too many DECREFs somewhere.
> 
>> https://github.com/hku-ect/gazebosc/blob/505b30c46bf3f78d188c3f575c80e294d3db7e5d/Actors/pythonactor.c#L286
>> 
> Incidentally, in s_py_zosc_tuple, you're not doing "assert(rc == 0);"
> after "after zosc_pop_float" or "zosc_pop_double".
>
Here's something interesting in s_py_zosc:

             PyTypeObject* type = Py_TYPE(item);
             const char * typename = _PyType_Name(type);
             if (streq(typename, "c_int"))
             {
                 zsys_warning("Unsupported ctypes.c_int until we find a 
way to access the value :S");
             }
             else
                 zsys_warning("unsupported python type");

             Py_DECREF(type);

According to the docs, Py_TYPE returns a borrowed reference, but you're 
DECREFing it. If you call s_py_zosc enough times, the reference count of 
the type will drop to 0. I think that might be the problem.


More information about the Python-list mailing list