Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5bca57

Browse files
committed
PyMac_GetFSSpec must be called via the dylib glue code on OSX.
1 parent 3988358 commit a5bca57

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

Mac/Include/pymactoolbox.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn)
4343
#endif /* USE_TOOLBOX_OBJECT_GLUE */
4444

45+
/* macfs exports */
46+
extern int PyMac_GetFSSpec(PyObject *, FSSpec *);
47+
4548
/* AE exports */
4649
extern PyObject *AEDesc_New(AppleEvent *); /* XXXX Why passed by address?? */
4750
extern int AEDesc_Convert(PyObject *, AppleEvent *);

Mac/Modules/macfsmodule.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2424

2525
#include "Python.h"
2626
#include "macglue.h"
27+
#include "pymactoolbox.h"
2728

2829
#ifdef WITHOUT_FRAMEWORKS
2930
#include <Memory.h>
@@ -38,7 +39,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3839

3940
#include "getapplbycreator.h"
4041

41-
42+
#ifdef USE_TOOLBOX_OBJECT_GLUE
43+
extern int _PyMac_GetFSSpec(PyObject *, FSSpec *);
44+
#define PyMac_GetFSSpec _PyMac_GetFSSpec
45+
#endif
4246
static PyObject *ErrorObject;
4347

4448
/* ----------------------------------------------------- */
@@ -1201,8 +1205,17 @@ PyMac_GetFSRef(PyObject *v, FSRef *fsr)
12011205
if ( _mfs_GetFSRefFromFSSpec(v, fsr) )
12021206
return 1;
12031207
if ( PyString_Check(v) ) {
1208+
#if TARGET_API_MAC_OSX
1209+
OSStatus err;
1210+
if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
1211+
PyErr_Mac(ErrorObject, err);
1212+
return 0;
1213+
}
1214+
return 1;
1215+
#else
12041216
PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform");
12051217
return 0;
1218+
#endif
12061219
}
12071220
PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname");
12081221
return 0;
@@ -1270,6 +1283,8 @@ initmacfs()
12701283
{
12711284
PyObject *m, *d;
12721285

1286+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, PyMac_GetFSSpec);
1287+
12731288
/* Create the module and add the functions */
12741289
m = Py_InitModule("macfs", mfs_methods);
12751290

Mac/Python/macglue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ int routinename(PyObject *pyobj, object *cobj) { \
11941194
} \
11951195
return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
11961196
}
1197+
GLUE_CONVERT(FSSpec, PyMac_GetFSSpec, "macfs")
11971198

11981199
GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */
11991200
GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE")

0 commit comments

Comments
 (0)