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


Groups > comp.lang.python > #4427

Re: Py_INCREF() incomprehension

From Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Newsgroups comp.lang.python
Subject Re: Py_INCREF() incomprehension
Date 2011-05-02 02:59 +0200
Organization A newly installed InterNetNews server
Message-ID <ipkvmd$cu5$1@r03.glglgl.eu> (permalink)
References (4 earlier) <mailman.851.1303838890.9059.python-list@python.org> <ip70b8$3lv$1@r03.glglgl.eu> <mailman.858.1303843478.9059.python-list@python.org> <ip8pc1$qb8$1@r03.glglgl.eu> <mailman.1044.1304280052.9059.python-list@python.org>

Show all headers | View raw


Am 01.05.2011 22:00, schrieb Hegedüs Ervin:

> My module contains just 4 functions (in C), which translate 3rd
> party lib to Python. The name would be _mycrypt.so example.
>
> I wrapped it a pure Python module, its name is mycrypt.py.
>
> Then, I've import pure Python module in a main program, like
> this:
>
> =%=
> mycrypt.py:
>
> import _mycrypt
> ...
> =%=
>
> =%=
> userapp.py:
>
> import mycrypt
> ...
> =%=

AFAICS, it looks ok.


> I've missed out something, and then I didn't get exception,
> instead there were a segfault. :(

I guess this is the point where yo should start printf programing.

* What happens during module initialization?
* What happens n the functions?
* Where does the stuff fail?
* What are the reference counts of the involved objects?

etc.


> I've put it a Py_INCREF() after every PyModule_AddObject(), eg.:
>
>      PyModule_AddObject(o, "error", cibcrypt_error_nokey);
>      Py_INCREF(cibcrypt_error_nokey);
>
> and now if there is some expected exception, I get it.

> Any explanation?

I don't have one - I would think that if the module object exists for 
all the time, it would be enough to have one reference there.

But obviously it is not enough - did you at any time del something 
related to here? The module or one of its attributes?

Anyway, it seems safer to do INCREF here - so do it. (As Gregory already 
stated - it looks cleaner if you do INCREF before AddObject.)


> ps: this is just for my passion, but I would like to understand
> it very-very much :)

Understandable. That's that the printf debugging of the refcounts can be 
good for - even if you don't really have a problem.


Thomas

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