[Python-checkins] python/dist/src/Mac/Modules/file _Filemodule.c,1.7,1.8 filesupport.py,1.6,1.7
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Thu, 19 Dec 2002 15:27:00 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules/file
In directory sc8-pr-cvs1:/tmp/cvs-serv4780
Modified Files:
_Filemodule.c filesupport.py
Log Message:
Added the last missing bits of functionality, and fixed a nasty bug where we
could overwrite memory.
Index: _Filemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/_Filemodule.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** _Filemodule.c 19 Dec 2002 21:24:32 -0000 1.7
--- _Filemodule.c 19 Dec 2002 23:26:58 -0000 1.8
***************
*** 27,39 ****
#endif
/* Forward declarations */
! extern PyObject *FSRef_New(FSRef *itself);
! extern PyObject *FSSpec_New(FSSpec *itself);
! extern PyObject *Alias_New(AliasHandle itself);
! extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
! extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
! extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
! static int myPyMac_GetFSSpec(PyObject *v, FSSpec *spec);
! static int myPyMac_GetFSRef(PyObject *v, FSRef *fsr);
/*
--- 27,56 ----
#endif
+ #ifdef USE_TOOLBOX_OBJECT_GLUE
+ extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+ extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
+ extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
+ extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
+
+ #define PyMac_GetFSSpec _PyMac_GetFSSpec
+ #define PyMac_GetFSRef _PyMac_GetFSRef
+ #define PyMac_BuildFSSpec _PyMac_BuildFSSpec
+ #define PyMac_BuildFSRef _PyMac_BuildFSRef
+ #else
+ extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+ extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
+ extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
+ extern PyObject *PyMac_BuildFSRef(FSRef *spec);
+ #endif
+
/* Forward declarations */
! static PyObject *FInfo_New(FInfo *itself);
! static PyObject *FSRef_New(FSRef *itself);
! static PyObject *FSSpec_New(FSSpec *itself);
! static PyObject *Alias_New(AliasHandle itself);
! static int FInfo_Convert(PyObject *v, FInfo *p_itself);
! #define FSRef_Convert PyMac_GetFSRef
! #define FSSpec_Convert PyMac_GetFSSpec
! static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
/*
***************
*** 47,51 ****
return 1;
}
! return myPyMac_GetFSSpec(v, *spec);
}
--- 64,68 ----
return 1;
}
! return PyMac_GetFSSpec(v, *spec);
}
***************
*** 57,61 ****
return 1;
}
! return myPyMac_GetFSRef(v, *ref);
}
--- 74,78 ----
return 1;
}
! return PyMac_GetFSRef(v, *ref);
}
***************
*** 70,104 ****
}
! /*
! ** Parse/generate objsect
! */
! static PyObject *
! PyMac_BuildFInfo(FInfo *itself)
{
! return Py_BuildValue("O&O&HO&h",
! PyMac_BuildOSType, itself->fdType,
! PyMac_BuildOSType, itself->fdCreator,
! itself->fdFlags,
! PyMac_BuildPoint, &itself->fdLocation,
! itself->fdFldr);
}
! static int
! PyMac_GetFInfo(PyObject *v, FInfo *itself)
{
! return PyArg_ParseTuple(v, "O&O&HO&h",
! PyMac_GetOSType, &itself->fdType,
! PyMac_GetOSType, &itself->fdCreator,
! &itself->fdFlags,
! PyMac_GetPoint, &itself->fdLocation,
! &itself->fdFldr);
}
! static PyObject *File_Error;
/* ----------------------- Object type Alias ------------------------ */
! PyTypeObject Alias_Type;
#define Alias_Check(x) ((x)->ob_type == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
--- 87,281 ----
}
!
! static PyObject *File_Error;
!
! /* ----------------------- Object type FInfo ------------------------ */
!
! static PyTypeObject FInfo_Type;
!
! #define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
!
! typedef struct FInfoObject {
! PyObject_HEAD
! FInfo ob_itself;
! } FInfoObject;
!
! static PyObject *FInfo_New(FInfo *itself)
{
+ FInfoObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(FInfoObject, &FInfo_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = *itself;
+ return (PyObject *)it;
+ }
+ static int FInfo_Convert(PyObject *v, FInfo *p_itself)
+ {
+ if (!FInfo_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "FInfo required");
+ return 0;
+ }
+ *p_itself = ((FInfoObject *)v)->ob_itself;
+ return 1;
+ }
! static void FInfo_dealloc(FInfoObject *self)
! {
! /* Cleanup of self->ob_itself goes here */
! self->ob_type->tp_free((PyObject *)self);
}
! static PyMethodDef FInfo_methods[] = {
! {NULL, NULL, 0}
! };
!
! static PyObject *FInfo_get_Type(FInfoObject *self, void *closure)
{
! return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdType);
}
! static int FInfo_set_Type(FInfoObject *self, PyObject *v, void *closure)
! {
! return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdType)-1;
! return 0;
! }
!
! static PyObject *FInfo_get_Creator(FInfoObject *self, void *closure)
! {
! return Py_BuildValue("O&", PyMac_BuildOSType, self->ob_itself.fdCreator);
! }
!
! static int FInfo_set_Creator(FInfoObject *self, PyObject *v, void *closure)
! {
! return PyArg_Parse(v, "O&", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;
! return 0;
! }
!
! static PyObject *FInfo_get_Flags(FInfoObject *self, void *closure)
! {
! return Py_BuildValue("H", self->ob_itself.fdFlags);
! }
!
! static int FInfo_set_Flags(FInfoObject *self, PyObject *v, void *closure)
! {
! return PyArg_Parse(v, "H", &self->ob_itself.fdFlags)-1;
! return 0;
! }
!
! static PyObject *FInfo_get_Location(FInfoObject *self, void *closure)
! {
! return Py_BuildValue("O&", PyMac_BuildPoint, self->ob_itself.fdLocation);
! }
!
! static int FInfo_set_Location(FInfoObject *self, PyObject *v, void *closure)
! {
! return PyArg_Parse(v, "O&", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;
! return 0;
! }
!
! static PyObject *FInfo_get_Fldr(FInfoObject *self, void *closure)
! {
! return Py_BuildValue("h", self->ob_itself.fdFldr);
! }
!
! static int FInfo_set_Fldr(FInfoObject *self, PyObject *v, void *closure)
! {
! return PyArg_Parse(v, "h", &self->ob_itself.fdFldr)-1;
! return 0;
! }
!
! static PyGetSetDef FInfo_getsetlist[] = {
! {"Type", (getter)FInfo_get_Type, (setter)FInfo_set_Type, "4-char file type"},
! {"Creator", (getter)FInfo_get_Creator, (setter)FInfo_set_Creator, "4-char file creator"},
! {"Flags", (getter)FInfo_get_Flags, (setter)FInfo_set_Flags, "Finder flag bits"},
! {"Location", (getter)FInfo_get_Location, (setter)FInfo_set_Location, "(x, y) location of the file's icon in its parent finder window"},
! {"Fldr", (getter)FInfo_get_Fldr, (setter)FInfo_set_Fldr, "Original folder, for 'put away'"},
! {NULL, NULL, NULL, NULL},
! };
!
!
! #define FInfo_compare NULL
!
! #define FInfo_repr NULL
!
! #define FInfo_hash NULL
! static int FInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
! {
! FInfo *itself = NULL;
! char *kw[] = {"itself", 0};
!
! if (PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kw, FInfo_Convert, &itself))
! {
! if (itself) memcpy(&((FInfoObject *)self)->ob_itself, itself, sizeof(FInfo));
! return 0;
! }
! return -1;
! }
!
! #define FInfo_tp_alloc PyType_GenericAlloc
!
! static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
! {
! PyObject *self;
!
! if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
! memset(&((FInfoObject *)self)->ob_itself, 0, sizeof(FInfo));
! return self;
! }
!
! #define FInfo_tp_free PyObject_Del
!
!
! static PyTypeObject FInfo_Type = {
! PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "Carbon.File.FInfo", /*tp_name*/
! sizeof(FInfoObject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
! /* methods */
! (destructor) FInfo_dealloc, /*tp_dealloc*/
! 0, /*tp_print*/
! (getattrfunc)0, /*tp_getattr*/
! (setattrfunc)0, /*tp_setattr*/
! (cmpfunc) FInfo_compare, /*tp_compare*/
! (reprfunc) FInfo_repr, /*tp_repr*/
! (PyNumberMethods *)0, /* tp_as_number */
! (PySequenceMethods *)0, /* tp_as_sequence */
! (PyMappingMethods *)0, /* tp_as_mapping */
! (hashfunc) FInfo_hash, /*tp_hash*/
! 0, /*tp_call*/
! 0, /*tp_str*/
! PyObject_GenericGetAttr, /*tp_getattro*/
! PyObject_GenericSetAttr, /*tp_setattro */
! 0, /*tp_as_buffer*/
! Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
! 0, /*tp_doc*/
! 0, /*tp_traverse*/
! 0, /*tp_clear*/
! 0, /*tp_richcompare*/
! 0, /*tp_weaklistoffset*/
! 0, /*tp_iter*/
! 0, /*tp_iternext*/
! FInfo_methods, /* tp_methods */
! 0, /*tp_members*/
! FInfo_getsetlist, /*tp_getset*/
! 0, /*tp_base*/
! 0, /*tp_dict*/
! 0, /*tp_descr_get*/
! 0, /*tp_descr_set*/
! 0, /*tp_dictoffset*/
! FInfo_tp_init, /* tp_init */
! FInfo_tp_alloc, /* tp_alloc */
! FInfo_tp_new, /* tp_new */
! FInfo_tp_free, /* tp_free */
! };
!
! /* --------------------- End object type FInfo ---------------------- */
!
/* ----------------------- Object type Alias ------------------------ */
! static PyTypeObject Alias_Type;
#define Alias_Check(x) ((x)->ob_type == &Alias_Type || PyObject_TypeCheck((x), &Alias_Type))
***************
*** 110,114 ****
} AliasObject;
! PyObject *Alias_New(AliasHandle itself)
{
AliasObject *it;
--- 287,291 ----
} AliasObject;
! static PyObject *Alias_New(AliasHandle itself)
{
AliasObject *it;
***************
*** 120,124 ****
return (PyObject *)it;
}
! int Alias_Convert(PyObject *v, AliasHandle *p_itself)
{
if (!Alias_Check(v))
--- 297,301 ----
return (PyObject *)it;
}
! static int Alias_Convert(PyObject *v, AliasHandle *p_itself)
{
if (!Alias_Check(v))
***************
*** 138,142 ****
}
self->ob_itself = NULL;
! PyObject_Del(self);
}
--- 315,319 ----
}
self->ob_itself = NULL;
! self->ob_type->tp_free((PyObject *)self);
}
***************
*** 397,401 ****
! PyTypeObject Alias_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
--- 574,578 ----
! static PyTypeObject Alias_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
***************
*** 446,450 ****
/* ----------------------- Object type FSSpec ----------------------- */
! PyTypeObject FSSpec_Type;
#define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type || PyObject_TypeCheck((x), &FSSpec_Type))
--- 623,627 ----
/* ----------------------- Object type FSSpec ----------------------- */
! static PyTypeObject FSSpec_Type;
#define FSSpec_Check(x) ((x)->ob_type == &FSSpec_Type || PyObject_TypeCheck((x), &FSSpec_Type))
***************
*** 455,459 ****
} FSSpecObject;
! PyObject *FSSpec_New(FSSpec *itself)
{
FSSpecObject *it;
--- 632,636 ----
} FSSpecObject;
! static PyObject *FSSpec_New(FSSpec *itself)
{
FSSpecObject *it;
***************
*** 464,482 ****
return (PyObject *)it;
}
- int FSSpec_Convert(PyObject *v, FSSpec *p_itself)
- {
- if (!FSSpec_Check(v))
- {
- PyErr_SetString(PyExc_TypeError, "FSSpec required");
- return 0;
- }
- *p_itself = ((FSSpecObject *)v)->ob_itself;
- return 1;
- }
static void FSSpec_dealloc(FSSpecObject *self)
{
/* Cleanup of self->ob_itself goes here */
! PyObject_Del(self);
}
--- 641,649 ----
return (PyObject *)it;
}
static void FSSpec_dealloc(FSSpecObject *self)
{
/* Cleanup of self->ob_itself goes here */
! self->ob_type->tp_free((PyObject *)self);
}
***************
*** 581,585 ****
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
! PyMac_BuildFInfo, &fndrInfo);
return _res;
}
--- 748,752 ----
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
! FInfo_New, &fndrInfo);
return _res;
}
***************
*** 591,595 ****
FInfo fndrInfo;
if (!PyArg_ParseTuple(_args, "O&",
! PyMac_GetFInfo, &fndrInfo))
return NULL;
_err = FSpSetFInfo(&_self->ob_itself,
--- 758,762 ----
FInfo fndrInfo;
if (!PyArg_ParseTuple(_args, "O&",
! FInfo_Convert, &fndrInfo))
return NULL;
_err = FSpSetFInfo(&_self->ob_itself,
***************
*** 848,852 ****
return 0;
}
! if (myPyMac_GetFSSpec(v, &((FSSpecObject *)self)->ob_itself)) return 0;
return -1;
}
--- 1015,1019 ----
return 0;
}
! if (PyMac_GetFSSpec(v, &((FSSpecObject *)self)->ob_itself)) return 0;
return -1;
}
***************
*** 859,863 ****
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
! memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpecObject));
return self;
}
--- 1026,1030 ----
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
! memset(&((FSSpecObject *)self)->ob_itself, 0, sizeof(FSSpec));
return self;
}
***************
*** 866,870 ****
! PyTypeObject FSSpec_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
--- 1033,1037 ----
! static PyTypeObject FSSpec_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
***************
*** 915,919 ****
/* ----------------------- Object type FSRef ------------------------ */
! PyTypeObject FSRef_Type;
#define FSRef_Check(x) ((x)->ob_type == &FSRef_Type || PyObject_TypeCheck((x), &FSRef_Type))
--- 1082,1086 ----
/* ----------------------- Object type FSRef ------------------------ */
! static PyTypeObject FSRef_Type;
#define FSRef_Check(x) ((x)->ob_type == &FSRef_Type || PyObject_TypeCheck((x), &FSRef_Type))
***************
*** 924,928 ****
} FSRefObject;
! PyObject *FSRef_New(FSRef *itself)
{
FSRefObject *it;
--- 1091,1095 ----
} FSRefObject;
! static PyObject *FSRef_New(FSRef *itself)
{
FSRefObject *it;
***************
*** 933,951 ****
return (PyObject *)it;
}
- int FSRef_Convert(PyObject *v, FSRef *p_itself)
- {
- if (!FSRef_Check(v))
- {
- PyErr_SetString(PyExc_TypeError, "FSRef required");
- return 0;
- }
- *p_itself = ((FSRefObject *)v)->ob_itself;
- return 1;
- }
static void FSRef_dealloc(FSRefObject *self)
{
/* Cleanup of self->ob_itself goes here */
! PyObject_Del(self);
}
--- 1100,1108 ----
return (PyObject *)it;
}
static void FSRef_dealloc(FSRefObject *self)
{
/* Cleanup of self->ob_itself goes here */
! self->ob_type->tp_free((PyObject *)self);
}
***************
*** 1289,1293 ****
return 0;
}
! if (myPyMac_GetFSRef(v, &((FSRefObject *)self)->ob_itself)) return 0;
return -1;
}
--- 1446,1450 ----
return 0;
}
! if (PyMac_GetFSRef(v, &((FSRefObject *)self)->ob_itself)) return 0;
return -1;
}
***************
*** 1300,1304 ****
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
! memset(&((FSRefObject *)self)->ob_itself, 0, sizeof(FSRefObject));
return self;
}
--- 1457,1461 ----
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
! memset(&((FSRefObject *)self)->ob_itself, 0, sizeof(FSRef));
return self;
}
***************
*** 1307,1311 ****
! PyTypeObject FSRef_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
--- 1464,1468 ----
! static PyTypeObject FSRef_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
***************
*** 1738,1742 ****
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
! PyMac_BuildFInfo, &fndrInfo);
return _res;
}
--- 1895,1899 ----
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
! FInfo_New, &fndrInfo);
return _res;
}
***************
*** 1754,1758 ****
&dirID,
PyMac_GetStr255, fileName,
! PyMac_GetFInfo, &fndrInfo))
return NULL;
_err = HSetFInfo(vRefNum,
--- 1911,1915 ----
&dirID,
PyMac_GetStr255, fileName,
! FInfo_Convert, &fndrInfo))
return NULL;
_err = HSetFInfo(vRefNum,
***************
*** 2459,2464 ****
! static int
! myPyMac_GetFSSpec(PyObject *v, FSSpec *spec)
{
Str255 path;
--- 2616,2621 ----
! int
! PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
{
Str255 path;
***************
*** 2504,2508 ****
*/
#if TARGET_API_MAC_OSX
! if ( myPyMac_GetFSRef(v, &fsr) ) {
#else
if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
--- 2661,2665 ----
*/
#if TARGET_API_MAC_OSX
! if ( PyMac_GetFSRef(v, &fsr) ) {
#else
if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
***************
*** 2519,2524 ****
}
! static int
! myPyMac_GetFSRef(PyObject *v, FSRef *fsr)
{
OSStatus err;
--- 2676,2681 ----
}
! int
! PyMac_GetFSRef(PyObject *v, FSRef *fsr)
{
OSStatus err;
***************
*** 2551,2554 ****
--- 2708,2722 ----
}
+ extern PyObject *
+ PyMac_BuildFSSpec(FSSpec *spec)
+ {
+ return FSSpec_New(spec);
+ }
+
+ extern PyObject *
+ PyMac_BuildFSRef(FSRef *spec)
+ {
+ return FSRef_New(spec);
+ }
***************
*** 2560,2563 ****
--- 2728,2736 ----
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
+
m = Py_InitModule("_File", File_methods);
***************
*** 2567,2570 ****
--- 2740,2749 ----
PyDict_SetItemString(d, "Error", File_Error) != 0)
return;
+ FInfo_Type.ob_type = &PyType_Type;
+ Py_INCREF(&FInfo_Type);
+ PyModule_AddObject(m, "FInfo", (PyObject *)&FInfo_Type);
+ /* Backward-compatible name */
+ Py_INCREF(&FInfo_Type);
+ PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
Alias_Type.ob_type = &PyType_Type;
Py_INCREF(&Alias_Type);
Index: filesupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/filesupport.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** filesupport.py 18 Dec 2002 23:17:26 -0000 1.6
--- filesupport.py 19 Dec 2002 23:26:58 -0000 1.7
***************
*** 52,57 ****
Output("%s *%s = &%s__buf__;", self.typeName, name, name)
! FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
! FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
AliasHandle = OpaqueByValueType("AliasHandle", "Alias")
FSSpec = OpaqueType("FSSpec", "FSSpec")
--- 52,57 ----
Output("%s *%s = &%s__buf__;", self.typeName, name, name)
! FInfo = OpaqueType("FInfo", "FInfo")
! FInfo_ptr = OpaqueType("FInfo", "FInfo")
AliasHandle = OpaqueByValueType("AliasHandle", "Alias")
FSSpec = OpaqueType("FSSpec", "FSSpec")
***************
*** 77,89 ****
#endif
/* Forward declarations */
! extern PyObject *FSRef_New(FSRef *itself);
! extern PyObject *FSSpec_New(FSSpec *itself);
! extern PyObject *Alias_New(AliasHandle itself);
! extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
! extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
! extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
! static int myPyMac_GetFSSpec(PyObject *v, FSSpec *spec);
! static int myPyMac_GetFSRef(PyObject *v, FSRef *fsr);
/*
--- 77,106 ----
#endif
+ #ifdef USE_TOOLBOX_OBJECT_GLUE
+ extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+ extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
+ extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
+ extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
+
+ #define PyMac_GetFSSpec _PyMac_GetFSSpec
+ #define PyMac_GetFSRef _PyMac_GetFSRef
+ #define PyMac_BuildFSSpec _PyMac_BuildFSSpec
+ #define PyMac_BuildFSRef _PyMac_BuildFSRef
+ #else
+ extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+ extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
+ extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
+ extern PyObject *PyMac_BuildFSRef(FSRef *spec);
+ #endif
+
/* Forward declarations */
! static PyObject *FInfo_New(FInfo *itself);
! static PyObject *FSRef_New(FSRef *itself);
! static PyObject *FSSpec_New(FSSpec *itself);
! static PyObject *Alias_New(AliasHandle itself);
! static int FInfo_Convert(PyObject *v, FInfo *p_itself);
! #define FSRef_Convert PyMac_GetFSRef
! #define FSSpec_Convert PyMac_GetFSSpec
! static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
/*
***************
*** 97,101 ****
return 1;
}
! return myPyMac_GetFSSpec(v, *spec);
}
--- 114,118 ----
return 1;
}
! return PyMac_GetFSSpec(v, *spec);
}
***************
*** 107,111 ****
return 1;
}
! return myPyMac_GetFSRef(v, *ref);
}
--- 124,128 ----
return 1;
}
! return PyMac_GetFSRef(v, *ref);
}
***************
*** 120,153 ****
}
- /*
- ** Parse/generate objsect
- */
- static PyObject *
- PyMac_BuildFInfo(FInfo *itself)
- {
-
- return Py_BuildValue("O&O&HO&h",
- PyMac_BuildOSType, itself->fdType,
- PyMac_BuildOSType, itself->fdCreator,
- itself->fdFlags,
- PyMac_BuildPoint, &itself->fdLocation,
- itself->fdFldr);
- }
-
- static int
- PyMac_GetFInfo(PyObject *v, FInfo *itself)
- {
- return PyArg_ParseTuple(v, "O&O&HO&h",
- PyMac_GetOSType, &itself->fdType,
- PyMac_GetOSType, &itself->fdCreator,
- &itself->fdFlags,
- PyMac_GetPoint, &itself->fdLocation,
- &itself->fdFldr);
- }
"""
finalstuff = finalstuff + """
! static int
! myPyMac_GetFSSpec(PyObject *v, FSSpec *spec)
{
Str255 path;
--- 137,145 ----
}
"""
finalstuff = finalstuff + """
! int
! PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
{
Str255 path;
***************
*** 193,197 ****
*/
#if TARGET_API_MAC_OSX
! if ( myPyMac_GetFSRef(v, &fsr) ) {
#else
if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
--- 185,189 ----
*/
#if TARGET_API_MAC_OSX
! if ( PyMac_GetFSRef(v, &fsr) ) {
#else
if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
***************
*** 208,213 ****
}
! static int
! myPyMac_GetFSRef(PyObject *v, FSRef *fsr)
{
OSStatus err;
--- 200,205 ----
}
! int
! PyMac_GetFSRef(PyObject *v, FSRef *fsr)
{
OSStatus err;
***************
*** 240,243 ****
--- 232,253 ----
}
+ extern PyObject *
+ PyMac_BuildFSSpec(FSSpec *spec)
+ {
+ return FSSpec_New(spec);
+ }
+
+ extern PyObject *
+ PyMac_BuildFSRef(FSRef *spec)
+ {
+ return FSRef_New(spec);
+ }
+ """
+
+ initstuff = initstuff + """
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
"""
***************
*** 245,249 ****
# Our object types:
! class FSSpecDefinition(PEP253Mixin, GlobalObjectDefinition):
getsetlist = [
("data",
--- 255,316 ----
# Our object types:
! class FInfoDefinition(PEP253Mixin, ObjectDefinition):
! getsetlist = [
! ("Type",
! "return Py_BuildValue(\"O&\", PyMac_BuildOSType, self->ob_itself.fdType);",
! "return PyArg_Parse(v, \"O&\", PyMac_GetOSType, &self->ob_itself.fdType)-1;",
! "4-char file type"
! ),
! ("Creator",
! "return Py_BuildValue(\"O&\", PyMac_BuildOSType, self->ob_itself.fdCreator);",
! "return PyArg_Parse(v, \"O&\", PyMac_GetOSType, &self->ob_itself.fdCreator)-1;",
! "4-char file creator"
! ),
! ("Flags",
! "return Py_BuildValue(\"H\", self->ob_itself.fdFlags);",
! "return PyArg_Parse(v, \"H\", &self->ob_itself.fdFlags)-1;",
! "Finder flag bits"
! ),
! ("Location",
! "return Py_BuildValue(\"O&\", PyMac_BuildPoint, self->ob_itself.fdLocation);",
! "return PyArg_Parse(v, \"O&\", PyMac_GetPoint, &self->ob_itself.fdLocation)-1;",
! "(x, y) location of the file's icon in its parent finder window"
! ),
! ("Fldr",
! "return Py_BuildValue(\"h\", self->ob_itself.fdFldr);",
! "return PyArg_Parse(v, \"h\", &self->ob_itself.fdFldr)-1;",
! "Original folder, for 'put away'"
! ),
!
! ]
!
! def __init__(self, name, prefix, itselftype):
! ObjectDefinition.__init__(self, name, prefix, itselftype)
! self.argref = "*" # Store FSSpecs, but pass them by address
!
! def outputCheckNewArg(self):
! Output("if (itself == NULL) return PyMac_Error(resNotFound);")
!
! def output_tp_newBody(self):
! Output("PyObject *self;");
! Output()
! Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
! Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
! self.objecttype, self.itselftype)
! Output("return self;")
!
! def output_tp_initBody(self):
! Output("%s *itself = NULL;", self.itselftype)
! Output("char *kw[] = {\"itself\", 0};")
! Output()
! Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"|O&\", kw, FInfo_Convert, &itself))")
! OutLbrace()
! Output("if (itself) memcpy(&((%s *)self)->ob_itself, itself, sizeof(%s));",
! self.objecttype, self.itselftype)
! Output("return 0;")
! OutRbrace()
! Output("return -1;")
!
! class FSSpecDefinition(PEP253Mixin, ObjectDefinition):
getsetlist = [
("data",
***************
*** 255,263 ****
def __init__(self, name, prefix, itselftype):
! GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
self.argref = "*" # Store FSSpecs, but pass them by address
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def output_tp_newBody(self):
--- 322,334 ----
def __init__(self, name, prefix, itselftype):
! ObjectDefinition.__init__(self, name, prefix, itselftype)
self.argref = "*" # Store FSSpecs, but pass them by address
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ # We do Convert ourselves (with PyMac_GetFSxxx)
+ def outputConvert(self):
+ pass
def output_tp_newBody(self):
***************
*** 266,270 ****
Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
! self.objecttype, self.objecttype)
Output("return self;")
--- 337,341 ----
Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
! self.objecttype, self.itselftype)
Output("return self;")
***************
*** 298,302 ****
Output("return 0;")
OutRbrace()
! Output("if (myPyMac_GetFSSpec(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
--- 369,373 ----
Output("return 0;")
OutRbrace()
! Output("if (PyMac_GetFSSpec(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
***************
*** 314,318 ****
OutRbrace()
! class FSRefDefinition(PEP253Mixin, GlobalObjectDefinition):
getsetlist = [
("data",
--- 385,389 ----
OutRbrace()
! class FSRefDefinition(PEP253Mixin, ObjectDefinition):
getsetlist = [
("data",
***************
*** 324,332 ****
def __init__(self, name, prefix, itselftype):
! GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
self.argref = "*" # Store FSRefs, but pass them by address
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def output_tp_newBody(self):
--- 395,407 ----
def __init__(self, name, prefix, itselftype):
! ObjectDefinition.__init__(self, name, prefix, itselftype)
self.argref = "*" # Store FSRefs, but pass them by address
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ # We do Convert ourselves (with PyMac_GetFSxxx)
+ def outputConvert(self):
+ pass
def output_tp_newBody(self):
***************
*** 335,339 ****
Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
! self.objecttype, self.objecttype)
Output("return self;")
--- 410,414 ----
Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));",
! self.objecttype, self.itselftype)
Output("return self;")
***************
*** 367,374 ****
Output("return 0;")
OutRbrace()
! Output("if (myPyMac_GetFSRef(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
! class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
# XXXX Should inherit from resource?
getsetlist = [
--- 442,449 ----
Output("return 0;")
OutRbrace()
! Output("if (PyMac_GetFSRef(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
! class AliasDefinition(PEP253Mixin, ObjectDefinition):
# XXXX Should inherit from resource?
getsetlist = [
***************
*** 392,400 ****
def outputStructMembers(self):
! GlobalObjectDefinition.outputStructMembers(self)
Output("void (*ob_freeit)(%s ptr);", self.itselftype)
def outputInitStructMembers(self):
! GlobalObjectDefinition.outputInitStructMembers(self)
Output("it->ob_freeit = NULL;")
--- 467,475 ----
def outputStructMembers(self):
! ObjectDefinition.outputStructMembers(self)
Output("void (*ob_freeit)(%s ptr);", self.itselftype)
def outputInitStructMembers(self):
! ObjectDefinition.outputInitStructMembers(self)
Output("it->ob_freeit = NULL;")
***************
*** 470,477 ****
--- 545,554 ----
longname=LONGMODNAME)
+ finfoobject = FInfoDefinition('FInfo', 'FInfo', 'FInfo')
aliasobject = AliasDefinition('Alias', 'Alias', 'AliasHandle')
fsspecobject = FSSpecDefinition('FSSpec', 'FSSpec', 'FSSpec')
fsrefobject = FSRefDefinition('FSRef', 'FSRef', 'FSRef')
+ module.addobject(finfoobject)
module.addobject(aliasobject)
module.addobject(fsspecobject)