LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2008, 09:27 AM   #1
spacepigeon
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
Thumbs up Extending Python with C (reference counting questions)


Hi there,

I have been using Python for a while and recently have started to extend with C modules. I am a little confused about reference counting though. Suppose we have the following:
Code:
static PyObject *SomeFunction(PyObject *self, PyObject *args){
	  
  	PyObject *storage_for_python_list;

        if(!PyArg_ParseTuple(args, "O", &storage_for_python_list))
    	return NULL;

        ...do something with list
        
        Py_INCREF(Py_None);
  	return Py_None;
do we need to Py_DECREF(storage_for_python_list)??

Second, is doing the following a bad idea?
Code:
Py_Object *list;
list= PyList_New(n);
PyList_SetItem(list, index, PyFloat_FromDouble(some_double_value));
I'm not sure what happens to the reference created from PyFloat_FromDouble in this case.

Thanks in advance for any suggestions/feedback.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tough (to me) c++ questions about pointer to class object reference and more parv Programming 6 01-11-2008 09:26 PM
Python: making a reference to a function not yet defined JRR883 Programming 1 02-08-2006 11:28 AM
Python Questions ... any gurus here? diz12 Programming 9 06-11-2005 01:16 PM
Considering Python and have a few questions prophet621 Programming 21 09-10-2004 07:06 AM
Two python questions squirreldogger Programming 0 01-06-2004 04:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration