Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4055
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!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; 'ok.': 0.04; 'arguments': 0.05; 'parameter': 0.05; 'pointer': 0.05; 'exception,': 0.07; 'implicit': 0.07; 'python': 0.07; '(there': 0.09; 'caller': 0.09; 'exception.': 0.09; 'null;': 0.09; 'obey': 0.09; 'question:': 0.09; '"from': 0.16; '*args)': 0.16; '*self,': 0.16; '>>be': 0.16; '>so,': 0.16; 'allocate': 0.16; 'definition,': 0.16; 'ever...': 0.16; 'pyobject': 0.16; 'pyobject*': 0.16; 'return.': 0.16; 'sizeof(char)': 0.16; 'subject:() ': 0.16; 'argument': 0.16; 'holds': 0.16; 'static': 0.16; 'thanks,': 0.17; 'input': 0.18; 'header:In-Reply-To:1': 0.22; '(but': 0.22; 'right,': 0.22; '(we': 0.24; "didn't": 0.25; 'wrote': 0.25; 'object': 0.27; 'function': 0.27; 'thanks': 0.29; 'error': 0.29; "python's": 0.29; 'probably': 0.30; 'least': 0.30; 'skip:( 20': 0.31; 'all:': 0.31; 'clear,': 0.31; 'typeerror:': 0.31; 'yes.': 0.31; 'does': 0.31; 'to:addr :python-list': 0.32; 'another': 0.32; 'thank': 0.32; "isn't": 0.34; 'using': 0.34; 'got': 0.34; 'there': 0.35; 'but,': 0.35; 'header:User-Agent:1': 0.35; 'ownership': 0.35; 'none': 0.36; 'exactly': 0.37; 'be,': 0.38; 'but': 0.38; 'code:': 0.38; 'current': 0.38; 'ok,': 0.39; 'realize': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'how': 0.39; 'takes': 0.40; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'free': 0.62; 'our': 0.63; 'dear': 0.64; 'here': 0.65; 'us,': 0.66; 'here.': 0.68; 'transfer': 0.71; 'faster...': 0.84; "its'": 0.84; 'knows,': 0.84; 'now...': 0.84; 'ours,': 0.84; 'received:hu': 0.84; 'reference?': 0.84 |
| X-Spam-Score | -1.308 |
| X-Spam-Level | |
| X-Spam-Status | No, score=-1.308 tagged_above=-20 required=4 tests=[AWL=0.061, BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, RDNS_DYNAMIC=0.1] |
| Date | Tue, 26 Apr 2011 19:28:00 +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> <mailman.839.1303826380.9059.python-list@python.org> <ip6qmr$50j$1@r03.glglgl.eu> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Disposition | inline |
| In-Reply-To | <ip6qmr$50j$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.851.1303838890.9059.python-list@python.org> (permalink) |
| Lines | 76 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1303838890 news.xs4all.nl 32470 [::ffff:82.94.164.166]:40512 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4055 |
Show key headers only | View raw
Dear Thomas,
thank you again,
> The ownership rules say that the input parameter belongs to the
> caller who holds it at least until we return. (We just "borrow" it.)
> So no action needed.
ok, its' clear, I understand,
> >>* Py_BuildValue()
>
> This function "transfers ownership", as it is none of
> (PyTuple_GetItem(), PyList_GetItem(), PyDict_GetItem(),
> PyDict_GetItemString()).
>
> So the value it returns belongs to us, for now.
>
> We do transfer ownership to our caller (implicitly), so no action is
> required as well here.
also,
> >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?
>
> In a way, yes. But you have to obey ownership: whom belongs the
> current reference? If it is not ours, and we need it, we do
> Py_(X)INCREF(). If we got it, but don't need it, we do
> Py_(X)DECREF().
right, it's clear again,
> >>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... :)
>
> Ok. (But as sizeof(char) is, by C standard definition, always 1, you
> can write it shorter.)
oh' well, thanks, I just wrote "from a wrist" :), I just realize
it now... :)
Another question: here is an another part ot my code:
static PyObject*
mycrypt_decrypt(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, "ss", &data, &path)) {
return NULL;
}
...
}
When I call this function from Python without argument or more
than it expects, I get an exception, eg.:
TypeError: function takes exactly 2 arguments (0 given)
But, when I don't read input arguments (there isn't
PyArg_ParseTuple), there isn't exception.
How Python handle the number of arguments? I just ask this,
because I don't set errstring with PyErr_SetString, but I get
TypeError - how does Python knows, this error raised?
Hope you understand my question... :)
thanks for all:
a.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
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