Objective-C experts?

Ronald Oussoren <[email protected]>
Newsgroups gmane.comp.python.pyobjc.devel,gmane.comp.python.apple
Message-ID <[email protected]>
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

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
smime.p7s (application/pkcs7-signature, 4.7 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.