Subclassing set from C: updating the set

Hi all,

I have a project which provides type validated version of the standard list, dict and set object. For performance, the implementation is in C. As a consequence all methods adding new entries need to be wrapped to validate the new values.

My specific problem is with updating a set. Currently the project uses _PySet_Update (atom/atom/src/atomset.cpp at main · nucleic/atom · GitHub). However this function is now masked in Python 3.13 and I as a consequence I tried to move away from. One experiment can be found at atomset experiments · nucleic/atom@ff93bb3 · GitHub (in which I load the method definition from the type ahead of time). It does compile but segfault. What I do not understand is that I checked that the input parameters are not null but looking at a backtrace it appears the segfault comes from a Py_INCREF deep into the set update function.
I also tried to access the method using PyObject_GetAttrString and then use PyCall_CallFunctionObjArgs with the same result.

If anybody has a idea of what could cause this behavior or explain how to access _PySet_Update under 3.13 I am very keen to hear it.

Best

Matthieu

Maybe also try PyObject_CallMethodOneArg.

I cannot since I am overwriting update in my subclass I need to call the parent class method, hence the dance to get the function from PySet_Type object. To be honest I tried and ended with an infinite recursion as could be expected.

Regular Python invokes super() to call the parent class method. The C API works the same way.

PyObject* parent = PyObject_CallFunctionObjArgs(&PySuper_Type, sint->ob_type,self, NULL);

In your example what does sint refers to.

Turns out my main issue was not how I retrieved the set.update unbound method but how I called it. I skipped over PyObject_CallFunctionObjArgs docs too fast and missed the need for a trailing NULL…
Thanks for the help and sorry for the noise.