[Pythonmac-SIG] Objective-C experts?

Ronald Oussoren ronaldoussoren at mac.com
Tue Jun 12 17:13:25 CEST 2012


Hi,

I'm running into an odd failure in the PyObjC test suite that is probably caused by a bug in OC_PythonUnicode in the pyobjc-core project. The relevant code looks fine though, and I have no idea what's going on here and would really appriciate if someone that knows Objective-C (and the Python C API) could have a look at the code.

In particular, with the following script:

<quote>
import Cocoa

# Create Cocoa string:
s = Cocoa.CFStringCreateMutableCopy(None, 0, b"****foobar****".decode('ascii'))

# Use this as a Cocoa object, instead of using the unicode subclass that's by default used for wrapping
s = s.nsstring()


trim_chars = u"*"
#trim_chars = Cocoa.CFStringCreateWithCString(None, trim_chars, Cocoa.kCFStringEncodingASCII)

Cocoa.CFStringTrim(s, trim_chars)

print (s)
</quote>

This script prints an unexpected value (the "*" characters are not stripped on both sides), but works fine when the line that translates trim_chars in a Cocoa string is activated.

For me te problem only occurs when I run this code with a 64-bit build of python ("arch -x86_64 python2.7 ...") and works fine in a 32-bit build ("arch -i386 python2.7 ..."). I have only tested on OSX 10.7, I'm currently traveling and cannot easily test on other releases.  To make life even more interesting, the problem only occurs when "PyObjC_UNICODE_FAST_PATH" is active.

It is best to use the version of PyObjC that is in my bitbucket repository to reproduce the problem (http://bitbucket.org/ronaldoussoren/pyobjc).  You will have to change Modules/objc/pyobjc.h, I have for now disabled PyObjC_UNICODE_FAST_PATH unconditionally to avoid this problem.

The relevant, failing, code is in Modules/objc/OC_PythonUnicode.m. This is a subclass of NSString that is used to proxy Python unicode strings into the Objective-C world. I've already tried disabling the implementation of "-getCharacters:range" and that didn't help.

Ronald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4788 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20120612/f5e8b40c/attachment.bin>


More information about the Pythonmac-SIG mailing list