jevinskie[m] has quit [Quit: Bridge terminating on SIGTERM]
<Hodgestar> Wat. :|
jboi has quit [Quit: Bridge terminating on SIGTERM]
jboi has joined #hpy
jevinskie[m] has joined #hpy
<antocuni> I am confused by PyObject_New. The CPython docs say:
<antocuni> Allocate a new Python object using the C structure type TYPE and the Python type object type. [...]
<antocuni> but looking at the source code, it seems to completely bypasses the tp_* slots. Apart from ignoring tp_new and tp_init, it seems to bypass also tp_alloc
<antocuni> so, what happens if you define a custom tp_alloc/tp_free and create an object using PyObject_New? Will it just crash when calling free?
<antocuni> and, if I am right: what are the reasonable use cases to call it?
the_drow has joined #hpy
<mattip> it is used in the top 4000 pypi packages
<ronan> antocuni: PyObject_New is lower-level than tp_alloc. All it does is malloc the object and initialise ob_type and ob_refcnt.
<ronan> I guess the only sensible use case is to use it inside tp_alloc, or maybe tp_new.
<antocuni> ronan: yes, I think I got it now
<antocuni> I think the confusing part is that PyObject_New and e.g. PyObject_GetAttr refers to two different ideas of "PyObject"
<antocuni> for PyObject_New it's "create a new instance of the struct PyObject"
<antocuni> for most other things, e.g. PyObject_GetAttr is "perform a GetAttr on this Python-level object"
<antocuni> so, it's just a matter of bad naming
<antocuni> but it's still confusing
<antocuni> FWIW, the C API is full of bad names :(
<antocuni> e.g., tp_alloc goes in pair with tp_free and NOT with tp_deallo
<antocuni> tp_dealloc
<antocuni> and PyObject_Del deallocs the memory (i.e. tp_free) and has nothing to do with tp_del, obviously
<antocuni> and of course there is also PyObject_Free which does a slightly different thing
<antocuni> speaking of which, I wonder whether we should rename HPy_New into e.g. HPy_AllocateInstance or something like that