rich comparison fscks up reference count?

G

Gerhard Häring

Maybe somebody can enlighten me here. I can't figure out why doing a
rich comparison on my object decreases the total reference count by 1.
Linked is the minimal test case with a C exension that compiles under
both Python 2.6 and 3.1. No external dependencies, except a DEBUG
build of Python to see the effect (Py_REF_DEBUG defined).

http://cdn.ghaering.de/foo.c
http://cdn.ghaering.de/setup.py

Builtin types like list, dict, etc. don't seem to have the same
effect.

I've also run the test a few thousand times; then the total refcount
is like -50000, but Python does not crash. Also if I print all objects
and their respective refcounts using the gc module, none of them seems
to have a negative refcount, but the total refcount is still way
negative. How could that be?

-- Gerhard
 
G

Gerhard Häring

Can be run like this:

ghaering@ws124~/src/gh/test$ python3 setup.py build_ext --inplace
running build_ext
building 'foo' extension
gcc -fno-strict-aliasing -g -fwrapv -O0 -Wall -Wstrict-prototypes -
arch i386 -m32 -I/opt/jetstream/include/python3.1 -c foo.c -o build/
temp.macosx-10.4-i386-3.1-pydebug/foo.o
foo.c: In function ‘PyInit_foo’:
foo.c:109: warning: return makes pointer from integer without a cast
gcc -bundle -undefined dynamic_lookup -arch i386 -m32 build/
temp.macosx-10.4-i386-3.1-pydebug/foo.o -o /Users/ghaering/src/gh/test/
foo.so
[50367 refs]
ghaering@ws124~/src/gh/test$ python3 setup.py test
running test
total refcount 65304
total refcount 65305
total refcount 65304
total refcount 65303
total refcount 65302
total refcount 65301
total refcount 65300
total refcount 65299
total refcount 65298
total refcount 65297
[45322 refs]
ghaering@ws124~/src/gh/test$
 
G

Gerhard Häring

Maybe somebody can enlighten me here. I can't figure out why doing a
rich comparison on my object decreases the total reference count by 1. [....]

Doh! It turned out the strange effect was due to my particular build
process.
My Python 2.6/3.1 are built using our own SCons-based build and the
corresponding Makefile that distutils then uses didn't have the same
DEFINEs.

So, the Python was built with Py_REF_DEBUG, but Py_REF_DEBUG was not
defined
when I built my extension module. Which fscked up the *total*
reference
counting (sys.gettotalrefcount()).

-- Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top