Re: Refcount problem in ceval.c

2008-09-11 Thread Berthold Höllmann
Christian Heimes [EMAIL PROTECTED] writes:

 Berthold Höllmann wrote:
 Is there any common reason to for such a strange object on the command
 stack, or is it more likely that any of my extension modules is causing
 havoc?

 It's very likely that your extension has a reference counting bug. It
 looks like you are either missing a Py_INCREF or you have a Py_DECREF
 too much. Newly freed memory is filled with 0xDB (see
 Objects/obmalloc.c DEADBYTE).

I was suspecting this, that's why I build the debugging version of
Python. I hoped I would get the error message somewhere near the code
causing the error, but I seems i have to continue the search.

 Wild guess: Are you using PyModule_AddObject with a PyTypeObject w/o
 Py_INCREF()ing the type object first?

That would have been easy :-) I have only one occurrence of
PyModule_AddObject, and its PyTypeObject is Py_INCREF()ed

Thanks
Berthold
-- 
__   Address:
 G /  \ L Germanischer Lloyd
phone: +49-40-36149-7374 -++- Vorsetzen 35   P.O.Box 111606
fax  : +49-40-36149-7320   \__/   D-20459 HamburgD-20416 Hamburg


pgpRObfd5AOUq.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: Refcount problem in ceval.c

2008-09-10 Thread Christian Heimes

Berthold Höllmann wrote:

Is there any common reason to for such a strange object on the command
stack, or is it more likely that any of my extension modules is causing
havoc?


It's very likely that your extension has a reference counting bug. It 
looks like you are either missing a Py_INCREF or you have a Py_DECREF 
too much. Newly freed memory is filled with 0xDB (see Objects/obmalloc.c 
DEADBYTE).


Wild guess: Are you using PyModule_AddObject with a PyTypeObject w/o 
Py_INCREF()ing the type object first?


Christian

--
http://mail.python.org/mailman/listinfo/python-list


Re: refcount

2008-01-30 Thread Sion Arrowsmith
Benjamin  [EMAIL PROTECTED] wrote:
 [ help(sys.getrefcount) says: ]
 [ ... ]  The count returned is generally
 one higher than you might expect, because it includes the (temporary)
 reference as an argument to getrefcount().
Are there any cases when it wouldn't?

When the temporary reference which is the argument to getrefcount is
the *only* reference, eg:

 sys.getrefcount (set())
1

The return value for a weakly referenced object may also be not what
you expect:

 s = set()
 sys.getrefcount(s)
2
 r = weakref.ref(s)
 r() is s
True
 sys.getrefcount(r())
2

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   Frankly I have no feelings towards penguins one way or the other
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: refcount

2008-01-29 Thread Duncan Booth
Simon Pickles [EMAIL PROTECTED] wrote:
 Is is possible to access the refcount for an object?

 import sys
 sys.getrefcount(42)
6

 Ideally, I am looking to see if I have a refcount of 1 before calling del

That's a pointless exercise: you probably don't understand what del does.

All that del does is remove one reference from an object, either by 
removing a name from the namespace, or by removing a reference from 
something like a list. 'del x' does NOT destroy the object referenced by x, 
unless it happens that there are no other references to the object.

Also note that the only time you will see a reference count of 1 is on an 
object which you cannot otherwise access (the only reference is being used 
for the call to getrefcount()):

 x = 9
 sys.getrefcount(x)
2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refcount

2008-01-29 Thread Benjamin
On Jan 29, 5:46 am, Christian Heimes [EMAIL PROTECTED] wrote:
 Simon Pickles wrote:
  Hi,

  Is is possible to access the refcount for an object?

  Ideally, I am looking to see if I have a refcount of 1 before calling del

 Help on built-in function getrefcount in module sys:

 getrefcount(...)
 getrefcount(object) - integer

 Return the reference count of object.  The count returned is generally
 one higher than you might expect, because it includes the (temporary)
 reference as an argument to getrefcount().
Are there any cases when it wouldn't?

 Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refcount

2008-01-29 Thread Mel
Benjamin wrote:
 On Jan 29, 5:46 am, Christian Heimes [EMAIL PROTECTED] wrote:
 Simon Pickles wrote:
 Hi,
 Is is possible to access the refcount for an object?
 Ideally, I am looking to see if I have a refcount of 1 before calling del
 Help on built-in function getrefcount in module sys:

 getrefcount(...)
 getrefcount(object) - integer

 Return the reference count of object.  The count returned is generally
 one higher than you might expect, because it includes the (temporary)
 reference as an argument to getrefcount().
 Are there any cases when it wouldn't?

Well, as long as the object is named object in sys.getrefcount's 
namespace, there's at least that one reference to it...

Mel.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: refcount

2008-01-29 Thread Christian Heimes
Simon Pickles wrote:
 Hi,
 
 Is is possible to access the refcount for an object?
 
 Ideally, I am looking to see if I have a refcount of 1 before calling del

Help on built-in function getrefcount in module sys:

getrefcount(...)
getrefcount(object) - integer

Return the reference count of object.  The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list