[Pythonmac-SIG] CFURL Pain

Nicholas Riley njriley at uiuc.edu
Mon Feb 28 22:40:42 CET 2005


On Mon, Feb 28, 2005 at 06:41:47PM +0000, has wrote:
> import Carbon.CF as CF
> f = 
> CF.CFURLCreateFromFileSystemRepresentation('file://localhost/Users/has/', 
> True)

That's not a filesystem representation (code for "UTF-8 encoded path").

> u'./file://localhost/Users/has' (Where did './' come from?)
> print f.toPython() # MacOS.Error: (-192, 'Resource not found')
> print f.CFURLGetFSRef() # crashes
> print f.CFURLGetFSRef()[1].as_pathname() # MacOS.Error: (-35, 'no such 
> volume')

When CF stuff crashes, you can often get more information by using the
debug version of frameworks:

% DYLD_IMAGE_SUFFIX="_debug" ipython
2005-02-28 15:34:18.928 python[16198] CFLog (0): Assertions enabled 
In [1]: import Carbon.CF as CF

In [2]: f = CF.CFURLCreateFromFileSystemRepresentation('/Users/nicholas', True)

In [3]: f.CFURLGetString().toPython()
2005-02-28 15:34:29.168 python[16198] CFLog (15): CFStringGetCharacters(): string range 0,32 out of bounds (length 31)
Out[3]: u'file://localhost/Users/nicholas'

In [4]: f.CFURLGetFSRef()
zsh: 16198 bus error  DYLD_IMAGE_SUFFIX="_debug" ipython
[...]

In [3]: f.CFURLGetFSRef()[1].as_pathname() 
DebugAssert: Third Party Client: err == 0  [-43] FSPathMakeRef_GetObjectInfoFailed [line 1670, file Files/HighLevelCalls.c]
DebugAssert: Third Party Client: volume != NULL FSMakePath_VolNotFound [line 848, file Files/FilePathUtils.c]
DebugAssert: Third Party Client: (tempMapOffset <= (fileLength - kNullMapLength)) exit CheckMapHeaderCommon(), Resource Manager: EOF truncates resource map.[line 195, file Resources/Source/ResourceUtils.c]
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)

/Users/nicholas/<console> 

Error: (-35, 'no such volume')

In [4]: f.CFURLGetFSRef()[1]              
DebugAssert: Third Party Client: err == 0  [-43] FSPathMakeRef_GetObjectInfoFailed [line 1670, file Files/HighLevelCalls.c]
Out[4]: <Carbon.File.FSRef object at 0x5756a8>

In [5]: f = CF.CFURLCreateFromFileSystemRepresentation('/Users/nicholas/', True)
In [6]: f.CFURLGetFSRef()[1].as_pathname()
Out[6]: '/Users/nicholas'

It's hard to say if the crash is Python's fault or CF's fault, but
there's definitely a wrapper bug in there.  And it looks like you need
the trailing slash; didn't bother to check if that is by design or
not.

-- 
Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>


More information about the Pythonmac-SIG mailing list