Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4122
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Py_INCREF() incomprehension |
| Date | Wed, 27 Apr 2011 11:58:18 +0200 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <ip8pc1$qb8$1@r03.glglgl.eu> (permalink) |
| 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> <mailman.851.1303838890.9059.python-list@python.org> <ip70b8$3lv$1@r03.glglgl.eu> <mailman.858.1303843478.9059.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 Hamster/2.1.0.11 |
| In-Reply-To | <mailman.858.1303843478.9059.python-list@python.org> |
| Lines | 54 |
| NNTP-Posting-Date | 27 Apr 2011 12:00:02 CEST |
| NNTP-Posting-Host | 1c65d337.newsspool2.arcor-online.net |
| X-Trace | DXC=a?InW65_@E[5TOT9_N5i<VA9EHlD;3YcR4Fo<]lROoRQ8kF<OcfhCO[5j_`QamNf4QK8FCa6^2FWROLF_]FfFg8_HZCb[fACfoT |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4122 |
Show key headers only | View raw
Am 26.04.2011 20:44, schrieb Hegedüs Ervin:
> and (maybe) final question: :)
>
> I defined many exceptions:
>
> static PyObject *cibcrypt_error_nokey;
> static PyObject *cibcrypt_error_nofile;
> static PyObject *cibcrypt_error_badpad;
> ...
>
> void handle_err(int errcode) {
> switch(errcode) {
> case -1: PyErr_SetString(cibcrypt_error_nokey, "Can't find key.");
> break;
> ...
> }
> ...
> cibcrypt_error_nokey = PyErr_NewException("cibcrypt.error_nokey", NULL, NULL);
> ...
> PyModule_AddObject(o, "error", cibcrypt_error_nokey);
Then I would not use the name "error" here, but maybe "error_nokey" or
even better "NoKeyException".
Oops: there is an inconsistency in the docu: on the one hand, it says
There are exactly two important exceptions to this rule:
PyTuple_SetItem() and PyList_SetItem().
stating these are the only ones who take over ownership.
But PyModule_AddObject() claims to "steal" a reference as well...
> I am right, here also no need any Py_INCREF()/Py_DECREF() action,
> based on this doc:
> http://docs.python.org/c-api/arg.html
I'm not sure: On one hand, you pass ownership of the error objects to
the module. There - one could think - they are until the module is unloaded.
But what if someone does "del module.NoKeyException"? In this case, the
object could have been destroyed, and you are using it -> BANG.
On the other hand, if you keep one instance internally, it is not
possible any longer to unload the module without a memory leak...
As already stated - you might want to have a look at some other C
modules and mimic their behaviour... (and hope they are doing it right...)
Thomas
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