Author: ronaldoussoren
Date: Thu Apr 30 07:14:53 2009
New Revision: 2180
Log:
Implement better support for FSRef and FSSpec
structures (the latter is probably too minimal,
but should be good enough).
This adds two new types: ``objc.FSRef`` and
``objc.FSSpec`` and implements automatic conversion
to/from the corresponding C structures.
``Carbon.File.FSRef`` and ``Carbon.File.FSSpec``
will also be converted to the right C structure
by the bridge when those types have been enabled
in the Python build.
Added:
trunk/pyobjc/pyobjc-core/Doc/fsref-fsspec.txt
trunk/pyobjc/pyobjc-core/Lib/objc/test/test_fsref.py (contents, props changed)
trunk/pyobjc/pyobjc-core/Lib/objc/test/test_keyvalue_prop.py (contents, props changed)
trunk/pyobjc/pyobjc-core/Modules/objc/fsref.h (contents, props changed)
trunk/pyobjc/pyobjc-core/Modules/objc/fsref.m
trunk/pyobjc/pyobjc-core/Modules/objc/fsspec.h (contents, props changed)
trunk/pyobjc/pyobjc-core/Modules/objc/fsspec.m
trunk/pyobjc/pyobjc-core/Modules/objc/test/fsref.m
Modified:
trunk/pyobjc/pyobjc-core/Lib/objc/_bridges.py
trunk/pyobjc/pyobjc-core/Modules/objc/module.m
trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m
trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
trunk/pyobjc/pyobjc-core/NEWS.txt
trunk/pyobjc/pyobjc-core/setup.py
Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_bridges.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_bridges.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_bridges.py Thu Apr 30 07:14:53 2009
@@ -25,28 +25,6 @@
OC_PythonDictionary.depythonifyTable().append(type)
-try:
- from array import array
- from Carbon.File import FSRef, FSSpec
-except ImportError:
- pass
-else:
- def struct_to_FSRef(s):
- return FSRef(rawdata=array('B', s[0]).tostring())
- BRIDGED_STRUCTURES['{FSRef=[80C]}'] = struct_to_FSRef
-
- def FSRef_to_struct(fsRef):
- return (tuple(array('B').fromstring(fsRef.data)),)
- BRIDGED_TYPES.append((FSRef, FSRef_to_struct))
-
- def struct_to_FSRef(s):
- return FSRef(rawdata=array('B', s[0]).tostring())
- BRIDGED_STRUCTURES['{FSRef=[80C]}'] = struct_to_FSRef
-
- def FSSpec_to_struct(fsSpec):
- return (tuple(array('B').fromstring(fsSpec.data)),)
- BRIDGED_TYPES.append((FSSpec, FSSpec_to_struct))
-
def _bridgePythonTypes():
# Python to Obj-C
OC_PythonObject = lookUpClass('OC_PythonObject')
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/module.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/module.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/module.m Thu Apr 30 07:14:53 2009
@@ -1853,6 +1853,8 @@
PyType_Ready(&PyObjCMethodAccessor_Type);
PyType_Ready(&PyObjCMethodSignature_Type);
PyType_Ready(&PyObjC_VarList_Type);
+ PyType_Ready(&PyObjC_FSRefType);
+ PyType_Ready(&PyObjC_FSSpecType);
PyObjCSuper_Type.tp_doc = PySuper_Type.tp_doc;
PyObjCSuper_Type.tp_init = PySuper_Type.tp_init;
@@ -1880,6 +1882,8 @@
PyDict_SetItemString(d, "objc_object", (PyObject*)&PyObjCObject_Type);
PyDict_SetItemString(d, "pyobjc_unicode", (PyObject*)&PyObjCUnicode_Type);
PyDict_SetItemString(d, "selector", (PyObject*)&PyObjCSelector_Type);
+ PyDict_SetItemString(d, "FSRef", (PyObject*)&PyObjC_FSRefType);
+ PyDict_SetItemString(d, "FSSpec", (PyObject*)&PyObjC_FSSpecType);
PyDict_SetItemString(d, "ivar", (PyObject*)&PyObjCInstanceVariable_Type);
PyDict_SetItemString(d, "informal_protocol", (PyObject*)&PyObjCInformalProtocol_Type);
PyDict_SetItemString(d, "formal_protocol", (PyObject*)&PyObjCFormalProtocol_Type);
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m Thu Apr 30 07:14:53 2009
@@ -1089,6 +1089,14 @@
return PyObjC_SockAddrToPython(datum);
}
+ if (IS_FSREF(type)) {
+ return PyObjC_decode_fsref(datum);
+ }
+
+ if (IS_FSSPEC(type)) {
+ return PyObjC_decode_fsspec(datum);
+ }
+
/* Skip back over digits at end of type in function prototypes */
while (type_real_length > 0 && isdigit(type_start[type_real_length-1])) {
type_real_length --;
@@ -1449,6 +1457,19 @@
return PyObjC_SockAddrFromPython(arg, datum);
}
+ if (IS_FSREF(types)) {
+ if (PyObjC_encode_fsref(arg, datum) == 0) {
+ return 0;
+ }
+ PyErr_Clear();
+ }
+ if (IS_FSSPEC(types)) {
+ if (PyObjC_encode_fsspec(arg, datum) == 0) {
+ return 0;
+ }
+ PyErr_Clear();
+ }
+
while (*types != _C_STRUCT_E && *types++ != '='); /* skip "<name>=" */
type=types;
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h Thu Apr 30 07:14:53 2009
@@ -62,6 +62,8 @@
#include "varlist.h"
#include "parsexml.h"
#include "objc_super.h"
+#include "fsref.h"
+#include "fsspec.h"
/*
Modified: trunk/pyobjc/pyobjc-core/NEWS.txt
==============================================================================
--- trunk/pyobjc/pyobjc-core/NEWS.txt (original)
+++ trunk/pyobjc/pyobjc-core/NEWS.txt Thu Apr 30 07:14:53 2009
@@ -7,6 +7,14 @@
Version 2.2 (...)
-----------------
+- Fixed support for ``FSRef`` and ``FSSpec`` structures.
+
+ * Transparently convert ``Carbon.File.FSRef`` and ``Carbon.File.FSSpec``
+ instances to C.
+
+ * The types ``objc.FSRef`` and ``objc.FSSpec`` are the native
+ PyObjC representation for ``FSRef`` and ``FSSpec`` structures.
+
- Added more magic signature heuristics: the delegate selector for
sheets is now automaticly recognized, removing the need for
the decorator ``AppHelper.didEndSelector`` (which will stay present
Modified: trunk/pyobjc/pyobjc-core/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/setup.py (original)
+++ trunk/pyobjc/pyobjc-core/setup.py Thu Apr 30 07:14:53 2009
@@ -88,10 +88,14 @@
# Enable 'PyObjC_STRICT_DEBUGGING' to enable some costly internal
# assertions.
CFLAGS=[
- "-nostdinc",
- "-isystem/usr/include",
- "-isystem/usr/lib/gcc/i686-apple-darwin9/4.0.1/include",
- "-iframework/System/Library/Frameworks",
+
+# The following flags are an attempt at getting rid of /usr/local
+# in the compiler search path.
+# "-nostdinc",
+# "-isystem/usr/include",
+# "-isystem/usr/lib/gcc/i686-apple-darwin9/4.0.1/include",
+# "-iframework/System/Library/Frameworks",
+
"-DPyObjC_STRICT_DEBUGGING",
"-DMACOSX",
"-no-cpp-precomp",
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
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.