Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4043

Re: Py_INCREF() incomprehension

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <airween@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'pointer': 0.05; 'fine,': 0.07; 'implicit': 0.07; 'ret': 0.07; ':-)': 0.07; 'called.': 0.09; 'description.': 0.09; 'question:': 0.09; 'api': 0.11; 'above?': 0.16; 'allocate': 0.16; 'answer,': 0.16; 'borrowed': 0.16; 'btw:': 0.16; 'ever...': 0.16; 'great!': 0.16; 'pyobject*': 0.16; 'reference"': 0.16; 'ret;': 0.16; 'subject:() ': 0.16; 'code.': 0.18; 'input': 0.18; 'maybe': 0.21; '(which': 0.21; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'doc': 0.23; 'vs.': 0.23; 'example': 0.24; 'memory': 0.24; "didn't": 0.25; 'parameters': 0.26; 'object': 0.27; "doesn't": 0.28; 'thanks': 0.29; 'depends': 0.29; "python's": 0.29; 'probably': 0.30; 'called': 0.32; 'to:addr :python-list': 0.32; 'another': 0.32; "i've": 0.33; 'sorry': 0.33; 'using': 0.34; 'there': 0.35; 'concepts': 0.35; 'header:User- Agent:1': 0.35; 'hello,': 0.36; 'some': 0.37; 'should': 0.37; 'be,': 0.38; 'but': 0.38; 'so,': 0.38; 'to:addr:python.org': 0.39; 'could': 0.39; 'where': 0.39; 'how': 0.39; 'works': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'received:86': 0.60; 'free': 0.62; 'and,': 0.63; 'faster...': 0.84; 'received:hu': 0.84
X-Spam-Score -1.345
X-Spam-Level
X-Spam-Status No, score=-1.345 tagged_above=-20 required=4 tests=[AWL=0.024, BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, RDNS_NONE=0.1]
Date Tue, 26 Apr 2011 16:03:21 +0200
From Hegedüs Ervin <airween@gmail.com>
To python-list@python.org
Subject Re: Py_INCREF() incomprehension
References <mailman.830.1303811297.9059.python-list@python.org> <ip6dc5$m7d$1@r03.glglgl.eu>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
In-Reply-To <ip6dc5$m7d$1@r03.glglgl.eu>
User-Agent Mutt/1.5.20 (2009-06-14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.839.1303826380.9059.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 82.94.164.166
X-Trace 1303826381 news.xs4all.nl 41114 [::ffff:82.94.164.166]:37287
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4043

Show key headers only | View raw


Hello,

thanks for the answer,

> >Everything works fine, but sorry for the recurrent question: where
> >should I use the Py_INCREF()/Py_DECREF() in code above?
> 
> That depends on the functions which are called. It should be given
> in the API description. The same counts for the incoming parameters
> (which are borrowed AFAIR - but better have a look).

I've read API doc (which you've included in another mail), but
that's not clear for me. :(
 
> The most critical parts are indeed
> 
> * the input parameters
> 
> and
> 
> * Py_BuildValue()
> 
> . Maybe you could as well have a look at some example code.
> 
> Especially look at the concepts called "borrowed reference" vs.
> "owned reference".
> 
> And, for your other question:
> 
> > if (cRes == 0) {
> >       return Py_BuildValue("s", outdata);
> > }
> 
> You ask how to stop leaking memory? Well, simply by not leaking it :-)

great! :)
 
> Just free the memory area:
> 
> if (cRes == 0) {
>     PyObject* ret = Py_BuildValue("s", outdata);
>     free(outdata);
>     return ret;
> }

so, it means when I implicit allocate a new object (whit
Py_BuildValue()), Python's GC will free that pointer when it
doesn't require anymore?
 
> BTW: Is there any reason for using calloc()? malloc() would probably
> be faster...

may be, I didn't measure it ever... but calloc() gives clear
space... :)


thanks:

a.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Py_INCREF() incomprehension Ervin Hegedüs <airween@gmail.com> - 2011-04-26 11:48 +0200
  Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-26 14:23 +0200
  Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-26 14:21 +0200
    Re: Py_INCREF() incomprehension Hegedüs Ervin <airween@gmail.com> - 2011-04-26 16:03 +0200
      Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-26 18:08 +0200
        Re: Py_INCREF() incomprehension Hegedüs Ervin <airween@gmail.com> - 2011-04-26 19:28 +0200
          Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-26 19:45 +0200
            Re: Py_INCREF() incomprehension Hegedüs Ervin <airween@gmail.com> - 2011-04-26 20:44 +0200
              Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-27 11:58 +0200
                Re: Py_INCREF() incomprehension Hegedüs Ervin <airween@gmail.com> - 2011-05-01 22:00 +0200
                Re: Py_INCREF() incomprehension Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-02 10:48 +1200
                Re: Py_INCREF() incomprehension Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-02 02:59 +0200
                Re: Py_INCREF() incomprehension Hegedüs, Ervin <airween@gmail.com> - 2011-05-02 08:41 +0200
                Re: Py_INCREF() incomprehension Stefan Behnel <stefan_ml@behnel.de> - 2011-05-02 09:07 +0200

csiph-web