- Added rawdata initializers

- Added support for optional FSSpecs and FSRefs to the Alias routines.
  NewAlias and friends are still functions, though, not methods.
This commit is contained in:
Jack Jansen 2002-12-18 23:17:26 +00:00
parent ba873472d2
commit 543c9253cd
3 changed files with 339 additions and 124 deletions

View File

@ -36,6 +36,29 @@ 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);
/*
** Optional fsspec and fsref pointers. None will pass NULL
*/
static int
myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
{
if (v == Py_None) {
*spec = NULL;
return 1;
}
return myPyMac_GetFSSpec(v, *spec);
}
static int
myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
{
if (v == Py_None) {
*ref = NULL;
return 1;
}
return myPyMac_GetFSRef(v, *ref);
}
/*
** Parse/generate objsect
*/
@ -121,13 +144,14 @@ static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _rv;
FSSpec fromFile;
FSSpec fromFile__buf__;
FSSpec *fromFile = &fromFile__buf__;
FSSpec target;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&",
FSSpec_Convert, &fromFile))
myPyMac_GetOptFSSpecPtr, &fromFile))
return NULL;
_rv = ResolveAlias(&fromFile,
_rv = ResolveAlias(fromFile,
_self->ob_itself,
&target,
&wasChanged);
@ -160,15 +184,16 @@ static PyObject *Alias_ResolveAliasWithMountFlags(AliasObject *_self, PyObject *
{
PyObject *_res = NULL;
OSErr _rv;
FSSpec fromFile;
FSSpec fromFile__buf__;
FSSpec *fromFile = &fromFile__buf__;
FSSpec target;
Boolean wasChanged;
unsigned long mountFlags;
if (!PyArg_ParseTuple(_args, "O&l",
FSSpec_Convert, &fromFile,
myPyMac_GetOptFSSpecPtr, &fromFile,
&mountFlags))
return NULL;
_rv = ResolveAliasWithMountFlags(&fromFile,
_rv = ResolveAliasWithMountFlags(fromFile,
_self->ob_itself,
&target,
&wasChanged,
@ -184,15 +209,16 @@ static PyObject *Alias_FollowFinderAlias(AliasObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _rv;
FSSpec fromFile;
FSSpec fromFile__buf__;
FSSpec *fromFile = &fromFile__buf__;
Boolean logon;
FSSpec target;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&b",
FSSpec_Convert, &fromFile,
myPyMac_GetOptFSSpecPtr, &fromFile,
&logon))
return NULL;
_rv = FollowFinderAlias(&fromFile,
_rv = FollowFinderAlias(fromFile,
_self->ob_itself,
logon,
&target,
@ -208,15 +234,16 @@ static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject
{
PyObject *_res = NULL;
OSErr _rv;
FSRef fromFile;
FSRef fromFile__buf__;
FSRef *fromFile = &fromFile__buf__;
FSRef target;
Boolean wasChanged;
unsigned long mountFlags;
if (!PyArg_ParseTuple(_args, "O&l",
FSRef_Convert, &fromFile,
myPyMac_GetOptFSRefPtr, &fromFile,
&mountFlags))
return NULL;
_rv = FSResolveAliasWithMountFlags(&fromFile,
_rv = FSResolveAliasWithMountFlags(fromFile,
_self->ob_itself,
&target,
&wasChanged,
@ -232,13 +259,14 @@ static PyObject *Alias_FSResolveAlias(AliasObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _rv;
FSRef fromFile;
FSRef fromFile__buf__;
FSRef *fromFile = &fromFile__buf__;
FSRef target;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&",
FSRef_Convert, &fromFile))
myPyMac_GetOptFSRefPtr, &fromFile))
return NULL;
_rv = FSResolveAlias(&fromFile,
_rv = FSResolveAlias(fromFile,
_self->ob_itself,
&target,
&wasChanged);
@ -319,15 +347,39 @@ static PyGetSetDef Alias_getsetlist[] = {
#define Alias_hash NULL
static int Alias_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
{
AliasHandle itself;
char *kw[] = {"itself", 0};
AliasHandle itself = NULL;
char *rawdata = NULL;
int rawdatalen = 0;
Handle h;
char *kw[] = {"itself", "rawdata", 0};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, Alias_Convert, &itself))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen))
return -1;
if (itself && rawdata)
{
((AliasObject *)self)->ob_itself = itself;
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
return -1;
}
if (!itself && !rawdata)
{
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
return -1;
}
if (rawdata)
{
if ((h = NewHandle(rawdatalen)) == NULL)
{
PyErr_NoMemory();
return -1;
}
HLock(h);
memcpy((char *)*h, rawdata, rawdatalen);
HUnlock(h);
((AliasObject *)self)->ob_itself = (AliasHandle)h;
return 0;
}
return -1;
((AliasObject *)self)->ob_itself = itself;
return 0;
}
#define Alias_tp_alloc PyType_GenericAlloc
@ -637,24 +689,6 @@ static PyObject *FSSpec_FSpMakeFSRef(FSSpecObject *_self, PyObject *_args)
return _res;
}
static PyObject *FSSpec_NewAlias(FSSpecObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSSpec target;
AliasHandle alias;
if (!PyArg_ParseTuple(_args, "O&",
FSSpec_Convert, &target))
return NULL;
_err = NewAlias(&_self->ob_itself,
&target,
&alias);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
Alias_New, alias);
return _res;
}
static PyObject *FSSpec_NewAliasMinimal(FSSpecObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -688,27 +722,6 @@ static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args)
return _res;
}
static PyObject *FSSpec_UpdateAlias(FSSpecObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSSpec target;
AliasHandle alias;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&O&",
FSSpec_Convert, &target,
Alias_Convert, &alias))
return NULL;
_err = UpdateAlias(&_self->ob_itself,
&target,
alias,
&wasChanged);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("b",
wasChanged);
return _res;
}
static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -767,14 +780,10 @@ static PyMethodDef FSSpec_methods[] = {
PyDoc_STR("(FSSpec dest) -> None")},
{"FSpMakeFSRef", (PyCFunction)FSSpec_FSpMakeFSRef, 1,
PyDoc_STR("() -> (FSRef newRef)")},
{"NewAlias", (PyCFunction)FSSpec_NewAlias, 1,
PyDoc_STR("(FSSpec target) -> (AliasHandle alias)")},
{"NewAliasMinimal", (PyCFunction)FSSpec_NewAliasMinimal, 1,
PyDoc_STR("() -> (AliasHandle alias)")},
{"IsAliasFile", (PyCFunction)FSSpec_IsAliasFile, 1,
PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
{"UpdateAlias", (PyCFunction)FSSpec_UpdateAlias, 1,
PyDoc_STR("(FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
{"as_pathname", (PyCFunction)FSSpec_as_pathname, 1,
PyDoc_STR("() -> string")},
{"as_tuple", (PyCFunction)FSSpec_as_tuple, 1,
@ -811,11 +820,33 @@ static PyObject * FSSpec_repr(FSSpecObject *self)
#define FSSpec_hash NULL
static int FSSpec_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *v;
char *kw[] = {"itself", 0};
PyObject *v = NULL;
char *rawdata = NULL;
int rawdatalen = 0;
char *kw[] = {"itself", "rawdata", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kw, &v))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
return -1;
if (v && rawdata)
{
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
return -1;
}
if (!v && !rawdata)
{
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
return -1;
}
if (rawdata)
{
if (rawdatalen != sizeof(FSSpec))
{
PyErr_SetString(PyExc_TypeError, "FSSpec rawdata incorrect size");
return -1;
}
memcpy(&((FSSpecObject *)self)->ob_itself, rawdata, rawdatalen);
return 0;
}
if (myPyMac_GetFSSpec(v, &((FSSpecObject *)self)->ob_itself)) return 0;
return -1;
}
@ -1113,24 +1144,6 @@ static PyObject *FSRef_FNNotify(FSRefObject *_self, PyObject *_args)
}
#endif
static PyObject *FSRef_FSNewAlias(FSRefObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSRef target;
AliasHandle inAlias;
if (!PyArg_ParseTuple(_args, "O&",
FSRef_Convert, &target))
return NULL;
_err = FSNewAlias(&_self->ob_itself,
&target,
&inAlias);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
Alias_New, inAlias);
return _res;
}
static PyObject *FSRef_FSNewAliasMinimal(FSRefObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -1164,27 +1177,6 @@ static PyObject *FSRef_FSIsAliasFile(FSRefObject *_self, PyObject *_args)
return _res;
}
static PyObject *FSRef_FSUpdateAlias(FSRefObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSRef target;
AliasHandle alias;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&O&",
FSRef_Convert, &target,
Alias_Convert, &alias))
return NULL;
_err = FSUpdateAlias(&_self->ob_itself,
&target,
alias,
&wasChanged);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("b",
wasChanged);
return _res;
}
static PyObject *FSRef_FSRefMakePath(FSRefObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -1238,14 +1230,10 @@ static PyMethodDef FSRef_methods[] = {
{"FNNotify", (PyCFunction)FSRef_FNNotify, 1,
PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
#endif
{"FSNewAlias", (PyCFunction)FSRef_FSNewAlias, 1,
PyDoc_STR("(FSRef target) -> (AliasHandle inAlias)")},
{"FSNewAliasMinimal", (PyCFunction)FSRef_FSNewAliasMinimal, 1,
PyDoc_STR("() -> (AliasHandle inAlias)")},
{"FSIsAliasFile", (PyCFunction)FSRef_FSIsAliasFile, 1,
PyDoc_STR("() -> (Boolean aliasFileFlag, Boolean folderFlag)")},
{"FSUpdateAlias", (PyCFunction)FSRef_FSUpdateAlias, 1,
PyDoc_STR("(FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
{"FSRefMakePath", (PyCFunction)FSRef_FSRefMakePath, 1,
PyDoc_STR("() -> string")},
{"as_pathname", (PyCFunction)FSRef_as_pathname, 1,
@ -1273,11 +1261,33 @@ static PyGetSetDef FSRef_getsetlist[] = {
#define FSRef_hash NULL
static int FSRef_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *v;
char *kw[] = {"itself", 0};
PyObject *v = NULL;
char *rawdata = NULL;
int rawdatalen = 0;
char *kw[] = {"itself", "rawdata", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kw, &v))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Os#", kw, &v, &rawdata, &rawdatalen))
return -1;
if (v && rawdata)
{
PyErr_SetString(PyExc_TypeError, "Only one of itself or rawdata may be specified");
return -1;
}
if (!v && !rawdata)
{
PyErr_SetString(PyExc_TypeError, "One of itself or rawdata must be specified");
return -1;
}
if (rawdata)
{
if (rawdatalen != sizeof(FSRef))
{
PyErr_SetString(PyExc_TypeError, "FSRef rawdata incorrect size");
return -1;
}
memcpy(&((FSRefObject *)self)->ob_itself, rawdata, rawdatalen);
return 0;
}
if (myPyMac_GetFSRef(v, &((FSRefObject *)self)->ob_itself)) return 0;
return -1;
}
@ -2099,6 +2109,27 @@ static PyObject *File_FNNotifyAll(PyObject *_self, PyObject *_args)
}
#endif
static PyObject *File_NewAlias(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSSpec fromFile__buf__;
FSSpec *fromFile = &fromFile__buf__;
FSSpec target;
AliasHandle alias;
if (!PyArg_ParseTuple(_args, "O&O&",
myPyMac_GetOptFSSpecPtr, &fromFile,
FSSpec_Convert, &target))
return NULL;
_err = NewAlias(fromFile,
&target,
&alias);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
Alias_New, alias);
return _res;
}
static PyObject *File_NewAliasMinimalFromFullPath(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -2176,6 +2207,30 @@ static PyObject *File_ResolveAliasFileWithMountFlags(PyObject *_self, PyObject *
return _res;
}
static PyObject *File_UpdateAlias(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSSpec fromFile__buf__;
FSSpec *fromFile = &fromFile__buf__;
FSSpec target;
AliasHandle alias;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&O&O&",
myPyMac_GetOptFSSpecPtr, &fromFile,
FSSpec_Convert, &target,
Alias_Convert, &alias))
return NULL;
_err = UpdateAlias(fromFile,
&target,
alias,
&wasChanged);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("b",
wasChanged);
return _res;
}
static PyObject *File_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -2203,6 +2258,27 @@ static PyObject *File_ResolveAliasFileWithMountFlagsNoUI(PyObject *_self, PyObje
return _res;
}
static PyObject *File_FSNewAlias(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSRef fromFile__buf__;
FSRef *fromFile = &fromFile__buf__;
FSRef target;
AliasHandle inAlias;
if (!PyArg_ParseTuple(_args, "O&O&",
myPyMac_GetOptFSRefPtr, &fromFile,
FSRef_Convert, &target))
return NULL;
_err = FSNewAlias(fromFile,
&target,
&inAlias);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("O&",
Alias_New, inAlias);
return _res;
}
static PyObject *File_FSResolveAliasFileWithMountFlags(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
@ -2252,6 +2328,30 @@ static PyObject *File_FSResolveAliasFile(PyObject *_self, PyObject *_args)
return _res;
}
static PyObject *File_FSUpdateAlias(PyObject *_self, PyObject *_args)
{
PyObject *_res = NULL;
OSErr _err;
FSRef fromFile__buf__;
FSRef *fromFile = &fromFile__buf__;
FSRef target;
AliasHandle alias;
Boolean wasChanged;
if (!PyArg_ParseTuple(_args, "O&O&O&",
myPyMac_GetOptFSRefPtr, &fromFile,
FSRef_Convert, &target,
Alias_Convert, &alias))
return NULL;
_err = FSUpdateAlias(fromFile,
&target,
alias,
&wasChanged);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("b",
wasChanged);
return _res;
}
static PyMethodDef File_methods[] = {
{"UnmountVol", (PyCFunction)File_UnmountVol, 1,
PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
@ -2333,18 +2433,26 @@ static PyMethodDef File_methods[] = {
{"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
#endif
{"NewAlias", (PyCFunction)File_NewAlias, 1,
PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
{"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
PyDoc_STR("(Buffer fullPath, Str32 zoneName, Str31 serverName) -> (AliasHandle alias)")},
{"ResolveAliasFile", (PyCFunction)File_ResolveAliasFile, 1,
PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
{"ResolveAliasFileWithMountFlags", (PyCFunction)File_ResolveAliasFileWithMountFlags, 1,
PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
{"UpdateAlias", (PyCFunction)File_UpdateAlias, 1,
PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
{"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
{"FSNewAlias", (PyCFunction)File_FSNewAlias, 1,
PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
{"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
PyDoc_STR("(Boolean resolveAliasChains, unsigned long mountFlags) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
{"FSResolveAliasFile", (PyCFunction)File_FSResolveAliasFile, 1,
PyDoc_STR("(Boolean resolveAliasChains) -> (FSRef theRef, Boolean targetIsFolder, Boolean wasAliased)")},
{"FSUpdateAlias", (PyCFunction)File_FSUpdateAlias, 1,
PyDoc_STR("(FSRef fromFile, FSRef target, AliasHandle alias) -> (Boolean wasChanged)")},
{NULL, NULL, 0}
};

View File

@ -173,6 +173,14 @@ class MyScanner(Scanner_OSX):
# Various ResolveAliasFileXXXX functions
([('FSSpec', 'theSpec', 'OutMode')],
[('FSSpec_ptr', 'theSpec', 'InOutMode')]),
# The optional FSSpec to all ResolveAlias and NewAlias methods
([('FSSpec_ptr', 'fromFile', 'InMode')],
[('OptFSSpecPtr', 'fromFile', 'InMode')]),
([('FSRef_ptr', 'fromFile', 'InMode')],
[('OptFSRefPtr', 'fromFile', 'InMode')]),
]

View File

@ -4,7 +4,6 @@
# using the "scantools" package (customized for this particular manager).
#
# XXXX TO DO:
# - implement rawdata initializers
# - Implement correct missing FSSpec handling for Alias methods
# - Implement FInfo
@ -47,13 +46,20 @@ HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetH
UInt8_ptr = InputOnlyType("UInt8 *", "s")
# Other types:
class OptionalFSxxxType(OpaqueByValueType):
def declare(self, name):
Output("%s %s__buf__;", self.typeName, name)
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")
FSSpec_ptr = OpaqueType("FSSpec", "FSSpec")
OptFSSpecPtr = OptionalFSxxxType("FSSpec", "BUG", "myPyMac_GetOptFSSpecPtr")
FSRef = OpaqueType("FSRef", "FSRef")
FSRef_ptr = OpaqueType("FSRef", "FSRef")
OptFSRefPtr = OptionalFSxxxType("FSRef", "BUG", "myPyMac_GetOptFSRefPtr")
# To be done:
#CatPositionRec
@ -80,6 +86,29 @@ 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);
/*
** Optional fsspec and fsref pointers. None will pass NULL
*/
static int
myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
{
if (v == Py_None) {
*spec = NULL;
return 1;
}
return myPyMac_GetFSSpec(v, *spec);
}
static int
myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
{
if (v == Py_None) {
*ref = NULL;
return 1;
}
return myPyMac_GetFSRef(v, *ref);
}
/*
** Parse/generate objsect
*/
@ -240,11 +269,34 @@ class FSSpecDefinition(PEP253Mixin, GlobalObjectDefinition):
Output("return self;")
def output_tp_initBody(self):
Output("PyObject *v;")
Output("char *kw[] = {\"itself\", 0};")
Output("PyObject *v = NULL;")
Output("char *rawdata = NULL;")
Output("int rawdatalen = 0;")
Output("char *kw[] = {\"itself\", \"rawdata\", 0};")
Output()
Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|Os#\", kw, &v, &rawdata, &rawdatalen))")
Output("return -1;")
Output("if (v && rawdata)")
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");")
Output("return -1;")
OutRbrace()
Output("if (!v && !rawdata)")
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");")
Output("return -1;")
OutRbrace()
Output("if (rawdata)")
OutLbrace()
Output("if (rawdatalen != sizeof(%s))", self.itselftype)
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"%s rawdata incorrect size\");",
self.itselftype)
Output("return -1;")
OutRbrace()
Output("memcpy(&((%s *)self)->ob_itself, rawdata, rawdatalen);", self.objecttype)
Output("return 0;")
OutRbrace()
Output("if (myPyMac_GetFSSpec(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
@ -286,11 +338,34 @@ class FSRefDefinition(PEP253Mixin, GlobalObjectDefinition):
Output("return self;")
def output_tp_initBody(self):
Output("PyObject *v;")
Output("char *kw[] = {\"itself\", 0};")
Output("PyObject *v = NULL;")
Output("char *rawdata = NULL;")
Output("int rawdatalen = 0;")
Output("char *kw[] = {\"itself\", \"rawdata\", 0};")
Output()
Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|Os#\", kw, &v, &rawdata, &rawdatalen))")
Output("return -1;")
Output("if (v && rawdata)")
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");")
Output("return -1;")
OutRbrace()
Output("if (!v && !rawdata)")
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");")
Output("return -1;")
OutRbrace()
Output("if (rawdata)")
OutLbrace()
Output("if (rawdatalen != sizeof(%s))", self.itselftype)
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"%s rawdata incorrect size\");",
self.itselftype)
Output("return -1;")
OutRbrace()
Output("memcpy(&((%s *)self)->ob_itself, rawdata, rawdatalen);", self.objecttype)
Output("return 0;")
OutRbrace()
Output("if (myPyMac_GetFSRef(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
Output("return -1;")
@ -338,16 +413,40 @@ class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
Output("return self;")
def output_tp_initBody(self):
Output("%s itself;", self.itselftype);
Output("char *kw[] = {\"itself\", 0};")
Output("%s itself = NULL;", self.itselftype)
Output("char *rawdata = NULL;")
Output("int rawdatalen = 0;")
Output("Handle h;")
Output("char *kw[] = {\"itself\", \"rawdata\", 0};")
Output()
Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|O&s#\", kw, %s_Convert, &itself, &rawdata, &rawdatalen))",
self.prefix)
Output("return -1;")
Output("if (itself && rawdata)")
OutLbrace()
Output("((%s *)self)->ob_itself = itself;", self.objecttype)
Output("PyErr_SetString(PyExc_TypeError, \"Only one of itself or rawdata may be specified\");")
Output("return -1;")
OutRbrace()
Output("if (!itself && !rawdata)")
OutLbrace()
Output("PyErr_SetString(PyExc_TypeError, \"One of itself or rawdata must be specified\");")
Output("return -1;")
OutRbrace()
Output("if (rawdata)")
OutLbrace()
Output("if ((h = NewHandle(rawdatalen)) == NULL)")
OutLbrace()
Output("PyErr_NoMemory();")
Output("return -1;")
OutRbrace()
Output("HLock(h);")
Output("memcpy((char *)*h, rawdata, rawdatalen);")
Output("HUnlock(h);")
Output("((%s *)self)->ob_itself = (%s)h;", self.objecttype, self.itselftype)
Output("return 0;")
OutRbrace()
Output("return -1;")
Output("((%s *)self)->ob_itself = itself;", self.objecttype)
Output("return 0;")
# Alias methods come in two flavors: those with the alias as arg1 and
# those with the alias as arg 2.