Python API and Deallocation

08/01/2019 16:48 martinx1#1
Hi, im courrently making a bot just for fun in C++, althought for sake of compatibility, im calling the CFunctions that the client exports to the python interpreter.
But i can't understand if i need to do Py_DECREF after calling a function, or if there is somesort of garbage collector, i find this Python API a bit confusing.
This is my code:
[Only registered and activated users can see links. Click Here To Register...]

Are this Py_DECREF really necessary?
And please note that im calling a CFunction not the python function from the interpreter, in those examples im calling these 2 functions:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
Thanks in advance
08/01/2019 18:34 Mi4uric3#2
Not sure if this is an option for you: The exported python functions are just wrappers around C++ functions. You could call the inner C++ function instead, then you don't have to handle the unnecessary Python additions.
08/01/2019 20:54 martinx1#3
Quote:
Originally Posted by Mi4uric3 View Post
Not sure if this is an option for you: The exported python functions are just wrappers around C++ functions. You could call the inner C++ function instead, then you don't have to handle the unnecessary Python additions.
Yes I know, the problem is that I want it to be compatible with most servers without the need to reverse every function again and some servers modify the code of some of those functions. I even have a system in my bot where it first try to search for each function using a pattern, and if not found, uses the python functionif there is one.
And on python documentation, it says nothing about how PyObject are created and deallocated, they just say that buffers need to be manually freed. I just would like to know if there is some connection between the PyObject and the interpreter where it takes care of freeing the PyObject. I just hate this API.