Re: [Pyobjc-dev] Python 3 + pyobjc_unicode + strptime = crash
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2010-09-08 15:13:04
|
On 8 Sep, 2010, at 14:39, Virgil Dupras wrote: > On Wed, Sep 8, 2010 at 2:19 PM, Ronald Oussoren <ron...@ma...> wrote: >> >> On 8 Sep, 2010, at 11:38, Virgil Dupras wrote: >> >>> Hi, >>> >>> (Sorry for not submitting it to the tracker, I don't remember my old >>> SF login, I dislike SF and I want to avoid dealing with it.) >> >>> >>> I uncovered a bug today. Under Python 3, when using a pyobjc_unicode >>> with strptime, I get a this crash: >>> >>> Traceback (most recent call last): >>> File "pyobjc_strptime_bug.py", line 6, in <module> >>> print(datetime.strptime(s, '%Y-%m-%d')) >>> File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/_strptime.py", >>> line 335, in _strptime >>> data_string[found.end():]) >>> ValueError: unconverted data remains: o >>> >>> I created a script that reproduces the bug: >>> >>> from Foundation import NSString >>> s = NSString.alloc().initWithString_('2010-09-08') >>> print(type(s)) >>> # Very interesting, the bug only shows up if datetime is imported here >>> instead of at the top >>> from datetime import datetime >>> print(datetime.strptime(s, '%Y-%m-%d')) >> >> This works for me, with python 3.1 and 3.2. Both of them 32-bit builds. IIRC both python versions don't run the tip of the tree, but that shouldn't matter. >> >> What version of Python and PyObjC do you use? Which architecture are you using (32-bit, intel, 3-way, ...)? >> >> The most likely reason for the odd behaviour is that the constructor for pyobjc_unicode fails to initalize one of the fields in the unicode structs, or at least not exactly the same as the initializer for the real unicode type. >> >> Ronald. >> > > I use PyObjC's trunk at r2558 and Python 3.1.2, build in 32bit and > 64bit intel arches (when I run it, it runs in 64bit). I fiddled around > to figure out how to run python under 32bit mode, to no avail. The > "arch" command doesn't seem to work for me... Could you test r2592 of pyobjc-core (the current HEAD). I could reproduce the issue with a 64-bit of python 3.2 and r2592 fixes the problem by ensuring that the internal buffer of pyobjc_unicode is NUL terminated. Ronald |