Re: [Pyobjc-dev] Python 3 + pyobjc_unicode + strptime = crash
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2010-09-08 12:19:54
|
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. |