pycxx

Should {tp_alloc, tp_dealloc} and {tp_new, tp_free} be considered as pairs?

蓝咒 提交于 2020-07-08 18:32:46
问题 Is it true that whatever is created in tp_alloc should be destroyed in tp_dealloc? And similarly for {tp_new, tp_free}? It looks like an obvious symmetry, but I would be grateful for clarification. My actual use case is this: I have: class OSClass : PyObject {...} class Final : OSClass {...} So the corresponding PyTypeObject pto has: pto->tp_basicsize = sizeof(FinalClass) pto->tp_dealloc = (destructor) [](PyObject* pyob) { PyMem_Free(pyob); }; However the new style class stores the PyObject

Why does PyCXX handle new-style classes in the way it does?

孤街浪徒 提交于 2019-12-31 04:44:05
问题 I'm picking apart some C++ Python wrapper code that allows the consumer to construct custom old style and new style Python classes from C++. The original code comes from PyCXX, with old and new style classes here and here. I have however rewritten the code substantially, and in this question I will reference my own code, as it allows me to present the situation in the greatest clarity that I am able. I think there would be very few individuals capable of understanding the original code

How to tidy/fix PyCXX's creation of new-style Python extension-class?

若如初见. 提交于 2019-12-02 09:45:54
问题 I've nearly finished rewriting a C++ Python wrapper (PyCXX). The original allows old and new style extension classes, but also allows one to derive from the new-style classes: import test // ok a = test.new_style_class(); // also ok class Derived( test.new_style_class() ): def __init__( self ): test_funcmapper.new_style_class.__init__( self ) def derived_func( self ): print( 'derived_func' ) super().func_noargs() def func_noargs( self ): print( 'derived func_noargs' ) d = Derived() The code

How to tidy/fix PyCXX's creation of new-style Python extension-class?

风格不统一 提交于 2019-12-02 04:20:33
I've nearly finished rewriting a C++ Python wrapper (PyCXX). The original allows old and new style extension classes, but also allows one to derive from the new-style classes: import test // ok a = test.new_style_class(); // also ok class Derived( test.new_style_class() ): def __init__( self ): test_funcmapper.new_style_class.__init__( self ) def derived_func( self ): print( 'derived_func' ) super().func_noargs() def func_noargs( self ): print( 'derived func_noargs' ) d = Derived() The code is convoluted, and appears to contain errors ( Why does PyCXX handle new-style classes in the way it