[Python-checkins] python/dist/src/Mac/Modules/res _Resmodule.c,1.15,1.16 resedit.py,1.6,1.7 ressupport.py,1.23,1.24
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Thu, 05 Dec 2002 15:26:41 -0800
Update of /cvsroot/python/python/dist/src/Mac/Modules/res
In directory sc8-pr-cvs1:/tmp/cvs-serv26728
Modified Files:
_Resmodule.c resedit.py ressupport.py
Log Message:
Fixed so the Res.Resource() accepts either another resource, a string
or no argument (giving an empty resource).
Index: _Resmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/res/_Resmodule.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** _Resmodule.c 29 Nov 2002 23:40:47 -0000 1.15
--- _Resmodule.c 5 Dec 2002 23:26:38 -0000 1.16
***************
*** 613,616 ****
--- 613,658 ----
#define ResObj_hash NULL
+ static int ResObj_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
+ {
+ char *srcdata = NULL;
+ int srclen = 0;
+ Handle itself;
+ char *kw[] = {"itself", 0};
+
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, ResObj_Convert, &itself))
+ {
+ ((ResourceObject *)self)->ob_itself = itself;
+ return 0;
+ }
+ PyErr_Clear();
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s#", kw, &srcdata, &srclen)) return -1;
+ if ((itself = NewHandle(srclen)) == NULL)
+ {
+ PyErr_NoMemory();
+ return 0;
+ }
+ ((ResourceObject *)self)->ob_itself = itself;
+ if (srclen && srcdata)
+ {
+ HLock(itself);
+ memcpy(*itself, srcdata, srclen);
+ HUnlock(itself);
+ }
+ return 0;
+ }
+
+ #define ResObj_tp_alloc PyType_GenericAlloc
+
+ static PyObject *ResObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ PyObject *self;
+ if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
+ ((ResourceObject *)self)->ob_itself = NULL;
+ ((ResourceObject *)self)->ob_freeit = NULL;
+ return self;
+ }
+
+ #define ResObj_tp_free PyObject_Del
+
PyTypeObject Resource_Type = {
***************
*** 635,651 ****
PyObject_GenericGetAttr, /*tp_getattro*/
PyObject_GenericSetAttr, /*tp_setattro */
! 0, /*outputHook_tp_as_buffer*/
! 0, /*outputHook_tp_flags*/
! 0, /*outputHook_tp_doc*/
! 0, /*outputHook_tp_traverse*/
! 0, /*outputHook_tp_clear*/
! 0, /*outputHook_tp_richcompare*/
! 0, /*outputHook_tp_weaklistoffset*/
! 0, /*outputHook_tp_iter*/
! 0, /*outputHook_tp_iternext*/
ResObj_methods, /* tp_methods */
! 0, /*outputHook_tp_members*/
ResObj_getsetlist, /*tp_getset*/
! 0, /*outputHook_tp_base*/
};
--- 677,701 ----
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*/
ResObj_methods, /* tp_methods */
! 0, /*tp_members*/
ResObj_getsetlist, /*tp_getset*/
! 0, /*tp_base*/
! 0, /*tp_dict*/
! 0, /*tp_descr_get*/
! 0, /*tp_descr_set*/
! 0, /*tp_dictoffset*/
! ResObj_tp_init, /* tp_init */
! ResObj_tp_alloc, /* tp_alloc */
! ResObj_tp_new, /* tp_new */
! ResObj_tp_free, /* tp_free */
};
***************
*** 1695,1721 ****
#endif
- static PyObject *Res_Resource(PyObject *_self, PyObject *_args)
- {
- PyObject *_res = NULL;
-
- char *buf;
- int len;
- Handle h;
-
- if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
- return NULL;
- h = NewHandle(len);
- if ( h == NULL ) {
- PyErr_NoMemory();
- return NULL;
- }
- HLock(h);
- memcpy(*h, buf, len);
- HUnlock(h);
- _res = ResObj_New(h);
- return _res;
-
- }
-
static PyObject *Res_Handle(PyObject *_self, PyObject *_args)
{
--- 1745,1748 ----
***************
*** 1872,1877 ****
PyDoc_STR("(FSRef ref, Buffer forkNameLength, SignedByte permissions) -> (SInt16 refNum)")},
#endif
- {"Resource", (PyCFunction)Res_Resource, 1,
- PyDoc_STR("Convert a string to a resource object.\n\nThe created resource object is actually just a handle,\napply AddResource() to write it to a resource file.\nSee also the Handle() docstring.\n")},
{"Handle", (PyCFunction)Res_Handle, 1,
PyDoc_STR("Convert a string to a Handle object.\n\nResource() and Handle() are very similar, but objects created with Handle() are\nby default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()\nto change this.\n")},
--- 1899,1902 ----
***************
*** 1938,1943 ****
Resource_Type.ob_type = &PyType_Type;
Py_INCREF(&Resource_Type);
! if (PyDict_SetItemString(d, "ResourceType", (PyObject *)&Resource_Type) != 0)
! Py_FatalError("can't initialize ResourceType");
}
--- 1963,1970 ----
Resource_Type.ob_type = &PyType_Type;
Py_INCREF(&Resource_Type);
! PyModule_AddObject(m, "Resource", (PyObject *)&Resource_Type);
! /* Backward-compatible name */
! Py_INCREF(&Resource_Type);
! PyModule_AddObject(m, "ResourceType", (PyObject *)&Resource_Type);
}
Index: resedit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/res/resedit.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** resedit.py 5 Sep 2001 15:44:37 -0000 1.6
--- resedit.py 5 Dec 2002 23:26:38 -0000 1.7
***************
*** 1,29 ****
! resource_body = """
! char *buf;
! int len;
! Handle h;
!
! if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
! return NULL;
! h = NewHandle(len);
! if ( h == NULL ) {
! PyErr_NoMemory();
! return NULL;
! }
! HLock(h);
! memcpy(*h, buf, len);
! HUnlock(h);
! _res = ResObj_New(h);
! return _res;
! """
!
! f = ManualGenerator("Resource", resource_body)
! f.docstring = lambda: """Convert a string to a resource object.
!
! The created resource object is actually just a handle,
! apply AddResource() to write it to a resource file.
! See also the Handle() docstring.
! """
! functions.append(f)
handle_body = """
--- 1,29 ----
! ##resource_body = """
! ##char *buf;
! ##int len;
! ##Handle h;
! ##
! ##if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
! ## return NULL;
! ##h = NewHandle(len);
! ##if ( h == NULL ) {
! ## PyErr_NoMemory();
! ## return NULL;
! ##}
! ##HLock(h);
! ##memcpy(*h, buf, len);
! ##HUnlock(h);
! ##_res = ResObj_New(h);
! ##return _res;
! ##"""
! ##
! ##f = ManualGenerator("Resource", resource_body)
! ##f.docstring = lambda: """Convert a string to a resource object.
! ##
! ##The created resource object is actually just a handle,
! ##apply AddResource() to write it to a resource file.
! ##See also the Handle() docstring.
! ##"""
! ##functions.append(f)
handle_body = """
Index: ressupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/res/ressupport.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** ressupport.py 29 Nov 2002 23:40:47 -0000 1.23
--- ressupport.py 5 Dec 2002 23:26:38 -0000 1.24
***************
*** 101,105 ****
module = MacModule('_Res', 'Res', includestuff, finalstuff, initstuff)
! class ResDefinition(PEP252Mixin, GlobalObjectDefinition):
getsetlist = [
('data',
--- 101,105 ----
module = MacModule('_Res', 'Res', includestuff, finalstuff, initstuff)
! class ResDefinition(PEP253Mixin, GlobalObjectDefinition):
getsetlist = [
('data',
***************
*** 177,180 ****
--- 177,216 ----
Output("self->ob_itself = NULL;")
+ def output_tp_newBody(self):
+ Output("PyObject *self;")
+ Output
+ Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
+ Output("((%s *)self)->ob_freeit = NULL;", self.objecttype)
+ Output("return self;")
+
+ def output_tp_initBody(self):
+ Output("char *srcdata = NULL;")
+ Output("int srclen = 0;")
+ Output("%s itself;", self.itselftype);
+ Output("char *kw[] = {\"itself\", 0};")
+ Output()
+ Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
+ self.prefix);
+ OutLbrace()
+ Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+ Output("return 0;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|s#\", kw, &srcdata, &srclen)) return -1;")
+ Output("if ((itself = NewHandle(srclen)) == NULL)")
+ OutLbrace()
+ Output("PyErr_NoMemory();")
+ Output("return 0;")
+ OutRbrace()
+ Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+ # XXXX Output("((%s *)self)->ob_freeit = PyMac_AutoDisposeHandle;")
+ Output("if (srclen && srcdata)")
+ OutLbrace()
+ Output("HLock(itself);")
+ Output("memcpy(*itself, srcdata, srclen);")
+ Output("HUnlock(itself);")
+ OutRbrace()
+ Output("return 0;")
resobject = ResDefinition('Resource', 'ResObj', 'Handle')