f



PyCFunction_New(): to Py_DECREF() or not to Py_DECREF()

Hello,

if creating new CFunction

PyObject *function = PyCFunction_New(function_name, NULL);

and then this is the only thing which uses it ("dictionary" stays
alive...)

PyDict_SetItemString(dictionary, "function", function);

do I have to

Py_DECREF(function)

or not?
0
ecir.hana (26)
12/26/2009 10:27:58 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

2 Replies
794 Views

Similar Articles

[PageSpeed] 53

Ecir Hana <ecir.hana <at> gmail.com> writes:
> do I have to
> 
> Py_DECREF(function)
> 
> or not?

Yes, you still own the reference to the function.


0
Benjamin
12/27/2009 2:15:23 AM
On Dec 27, 3:15=A0am, Benjamin Peterson <benja...@python.org> wrote:

> Yes, you still own the reference to the function.

Thanks!
0
Ecir
12/27/2009 3:41:38 AM
Reply:

Similar Artilces:

Embedding Python
Hello, I'm embedding Python interpreter in a Win32 console application. I use C++. I would like to use the WinAPI LoadLibrary function to load the python dll at runtime (followed by GetProcAddress calls), so that I have to make no assumptions about the location of the dll. However I can't use the macro Py_DECREF if I load the dll this way. Is there a way to properly free python objects (specifically - dictionaries created by PyDict_New() and the object returned by PyRun_String()) not using Py_DECREF? Alternatively, is there a way to include the python header - to make the macro Py...

python is a python
python is a python ...

Py_DECREF after an exception
I'm wondering what happens with the exception info during object cleanup immediately after an exception is thrown. Consider this code: PyObject *args = PyBuild_Value("(O(O){})", name, parent); if (!args) return NULL; PyObject *val = some_python_func(x, args, NULL); Py_DECREF(args); if (!val) return NULL; The idea is to propagate the exception possibly raised by some_python_func and at the same time avoid leaking memory. But Py_DECREF can cause arbitrary Python code to get executed, including the code that eventually ends up calling PyErr_Clear when it wants ...

Py_DECREF Question:
When I add an object created locally to a mapping or sequence (that will be returned from a function into an running instance of the Python interpreter), I need to call Py_DECREF on the object, right? Unfortunately, I really feel like the following code leaks memory... --- for example --- PyObject* list = Py_Buildvalue("[]"); while(go) { PyObject* num = Py_BuildValue("i", 10); PyList_Append(list, num); Py_DECREF(num); } return list; /* The responsibility of decrementing the list now lies within the scope of Python. */ --- end example --- Secondly, __and most im...

Py_DECREF/Py_INCREF as Functions?
I'm trying to use Python from another application that allows me to load functions from a DLL. While I have most of the API working, I have one big problem: Py_DECREF and PyINCREF are macros which I can't load from the Python DLL. Since I can't decref any objects, I'm leaking memory all over the place. Is there any way to decref an object with a function that can be loaded from the Python DLL? -- Kevin D. Smith En Fri, 30 Mar 2007 20:21:53 -0300, Kevin D.Smith <Kevin.Smith@sas.com> escribi�: > I'm trying to use Python from another application that al...

python and s-lang
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I was just wondering if anyone has looked into using Python instead of, or in additon to, s-lang modules. Does slrn support the use of other interpreted languages ? (I hate the term scripted languages; very innacurate of modern interpreted languages). Given the fact that Python is as flexible and powerful as it is, and given the fact that it was designed to interface with such languages as C, it seemed natural that someone must have done this if it is possible. I would like to hear from those individuals, or anyone with programming experience (a...

best .lang. python
Any ideas on what to do? Stop attempting to negotiate. Contact your state insurance commission. Be prepared to divulge the name of your insurer. Keep detailed records of all your contacts. ----- - gpsman website--> http://www.win2job.info/ ...

Embedding Python in Python
Hi, I've been programming in Python for a couple of weeks now and am quite impressed with the language - it was very easy to learn (it actually reminds me a lot of programming in BASIC many many years ago - it's very fast to hack together a couple lines of code in interactive mode). I'm throwing together a simple little game (sort of a MUD-type thing) as my first 'big' project, and I thought it would be cool to be able to script the game in Python. Basically, I want to be able to type scripts in from within the game and attach them to objects, monsters, rooms, whatever. N...

Python to Python communication
Hello, I have a group of Python programms which I want to teach to "talk to each other". All run on Windows, on the same computer or in the same intranet. Security of communication is not an issue (encryption on lower level protocols / intra computer communication). Partially these programs are using wxPython. It is important that the communcation is "only an added feature", I am not willing to spend big memory / computing ressources on it. So I googled and came up with at least the following opportunities: XMLRPC - quite "simple" to implement within py...

Invoking Python from Python
Hi all, I have a need to create a Python script on the fly from another Python program and then execute the script so created. Do I need to invoke Python through os.spawnl or is there a better way? Thanks, -- John Am Tue, 08 Nov 2005 08:10:25 -0800 schrieb John Henry: > Hi all, > > I have a need to create a Python script on the fly from another Python > program and then execute the script so created. Do I need to invoke > Python through os.spawnl or is there a better way? Hi, creating source code with a script, is no good solution. Once I had to maintain lisp code w...

Python mascot? How about a Pythoneer?
I've been thinking that a good Python mascot might help in raising public awareness of Python. The problem with a snake as a mascot is that it is not anthropomorphic enough. An effective mascot has to have something approximating two arms, two legs, and a head, so that he can be put into various interesting situations and adventures. (At the very least, he has to be able to work a keyboard and a mouse!) Good examples can be found in some of the imaginative things that have been done with Linux's Tux. So a snake is out. So are Terry Gilliam's wonderful cartoons for the Flyin...

Py_XDECREF/Py_DECREF evaluating its argument more than once
Okay, this is mainly a tale of a stupid C++ programmer who forgot the rules of C... I simplified a whole lot of code recently, cut out some temporary variables, did some general tidying-up, and then found that my program was segfaulting occasionally. Sure that I hadn't made any substantive changes, I went tinkering, and pinned it down to this change: Old code: PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0); if (v) Py_DECREF(v); New code: Py_XDECREF(PyRun_StringFlags(code,Py_file_input,py_globals,locals,0)); It's the same, right? Py_XDECREF is just Py_DECREF ...

2008 computer new lang-python
thia is new ode adbbfy hsadhj http://www.freewebs.com/thuiss/ http://indianfriendfinder.com/go/g906725-pmem ...

ironpython (.net python) and dynamic langs on CLR
This might interest some of you :) A (fast) python implementation targeting .net and Mono has been released as open source today. Apparently this was announced at OSCON today. If anyone attended the talk I would be interested in hearing about it. I've been waiting for this for a while, not because I program in python but because it's supposed to have some good solutions for implementing dynamic languages on the CLR. Interestingly the author, Jim Hugunin, is going to join the CLR team at Microsoft and he (quote from website:) "will also reach out to other languages to help overcome...

Web resources about - PyCFunction_New(): to Py_DECREF() or not to Py_DECREF() - comp.lang.python

List of issues - Issues with patch - Python tracker
open all Python Home About News Documentation Download Community Foundation Core Development Issue Tracker Issues Search Random Issue Summaries ...

Resources last updated: 2/4/2016 8:58:09 PM