[Python-Dev] Deallocation of a pointer not malloced, any tips?

2007-04-20 Thread Kumar McMillan
I get this warning from my test suite when I introduced a segment of code:

python(18603,0xa000d000) malloc: *** Deallocation of a pointer not
malloced: 0x310caa3; This could be a double free(), or free() called
with the middle of an allocated block; Try setting environment
variable MallocHelp to see tools to help debug

Always the same warning; sometimes it even segfaults python, but
rarely. I only see it on Mac OS X (two separate machines), python
2.4.3 both built from source via Darwin Ports. The same suite gives no
such warning on a 2.4.3 production machine running Free BSD.

I know what segment of code causes it but can't for the life of me
think of writing it a different way in this specific application. In a
nutshell, it's two sets of two nested try blocks (try, try, except,
except * 2) where the inner except can re-raise a new exception if a
rescue function wants to. it sounds convoluted because it is! :( I
tried really hard recreating it in a test case outside of my
application but of course there is something too deeply buried that I
can't catch.

I turned on MallocHelp but just stared blankly at heaps and stack
options. Is there anything I can switch on that would be helpful to
anyone who might be interested in this problem? :) I also wanted to
put out some feelers in case it sounds like something that is fixed
elsewhere (I'm having trouble running my existing suite in 2.5 due to
setuptools not working and me not having enough time to fiddle with
it).

Sorry if this is all very vague, I'm just a bit stumped and wanted to
see if anyone had some suggestions.

-Kumar
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Deallocation of a pointer not malloced, any tips?

2007-04-24 Thread Kumar McMillan
On 4/20/07, Josiah Carlson <[EMAIL PROTECTED]> wrote:
> You may want the python-list mailing list or the equivalent
> comp.lang.python newsgroup, unless this is a bug with Python itself (you
> may try running Python 2.4.4, which is the next bugfix of the Python 2.4
> series).

yes, seems like it's either a bug in python or the mac os x malloc library.

>
> Regardless, you can help those who want to help you by providing the
> code that you have written that causes the error.  A doubly nested
> try/except isn't all that exciting, so I would guess many would be
> surprised that you are getting double free errors.

again, sorry for being vague.  i tried my best at reproducing it in a
test case but couldn't.  However, I finally experimented with trying
to force deallocation within the block of code and got something that
worked!

Here is a very small portion of it, with the fix, which was putting a
ref to the exc_info vars outside the tries and specifically del'ing
them in the finally block:

def load_or_rescue(self, load):
etype, val, tb = None, None, None
try:
try:
try:
load()
except Exception, exc:
etype, val, tb = sys.exc_info()
if not self.rescue_load((etype, val, tb), exc):
log.critical("EXCEPTION %s while processing %s",
etype, self.ext_event)
raise exc, None, tb
except NonFatalError, e:
self.handle_non_fatal_error(e)
finally:
del etype, val, tb

to put this in perspective a little more, the warning/crash happens
when the code is getting called more or less like this...

def load():
self.start_file(fileobj)
for row in self.file_reader(fileobj):
self.load_or_rescue(lambda: self.load_row(row))
self.load_or_rescue(load)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] sys.setdefaultencoding() vs. csv module + unicode

2007-06-13 Thread Kumar McMillan
I'm seeing conflicting opinions on whether to put
sys.setdefaultencoding('utf-8') in sitecustomize.py or not ([1] vs.
[2]) and frankly I'm confused.

The csv module says it's not unicode safe but the 2.5 docs [3] have a
workaround for this.  While the workaround says nothing about
sys.setdefaultencoding() it simply does not work with the default
encoding, "ascii."  Is this _the_ problem with the csv module?  Should
I give up and use XML?  Below is code that works vs. code that
doesn't.  Am I interpretting the workaround from the docs wrong?  If
so, can someone please give me a hint ;)  I should also point out that
I've tried this with the StringIO queued approach (from the
workaround) but that doesn't solve anything.

1) with the default encoding :

kumar$ python2.5
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
>>> import sys, csv, codecs
>>> f = codecs.open('unicsv.csv','wb','utf-8')
>>> w = csv.writer(f)
>>> w.writerow([u'lang', u'espa\xa4ol'])
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa4' in
position 4: ordinal not in range(128)
>>>

2) with custom encoding :

kumar$ python2.5 -S
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
>>> import sys, csv, codecs
>>> sys.setdefaultencoding('utf-8')
>>> f = codecs.open('unicsv.csv','wb','utf-8')
>>> w = csv.writer(f)
>>> w.writerow([u'lang', u'espa\xa4ol'])
>>> f.close()

thanks, Kumar

[1] http://mail.python.org/pipermail/python-dev/2007-June/073593.html
[2] http://diveintopython.org/xml_processing/unicode.html
[3] http://docs.python.org/lib/csv-examples.html#csv-examples
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com