summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/res/resedit.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2000-03-08 16:58:15 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2000-03-08 16:58:15 (GMT)
commitadd03b62fd6ec982785432b64b783441f9fcb879 (patch)
treecd2e0b8647b061fb6bf1bb48eea088987989f383 /Mac/Modules/res/resedit.py
parenta17e0f1b61add9a49f2f611c7baf42257a3979da (diff)
downloadcpython-add03b62fd6ec982785432b64b783441f9fcb879.zip
cpython-add03b62fd6ec982785432b64b783441f9fcb879.tar.gz
cpython-add03b62fd6ec982785432b64b783441f9fcb879.tar.bz2
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Also added a Handle() function which is like Resource() but has auto-dispose on by default.
Diffstat (limited to 'Mac/Modules/res/resedit.py')
-rw-r--r--Mac/Modules/res/resedit.py56
1 files changed, 53 insertions, 3 deletions
diff --git a/Mac/Modules/res/resedit.py b/Mac/Modules/res/resedit.py
index 42966e4..1684870 100644
--- a/Mac/Modules/res/resedit.py
+++ b/Mac/Modules/res/resedit.py
@@ -13,14 +13,45 @@ if ( h == NULL ) {
HLock(h);
memcpy(*h, buf, len);
HUnlock(h);
-return (PyObject *)ResObj_New(h);
+return ResObj_New(h);
"""
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.
+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 = """
+char *buf;
+int len;
+Handle h;
+ResourceObject *rv;
+
+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);
+rv = (ResourceObject *)ResObj_New(h);
+rv->ob_freeit = PyMac_AutoDisposeHandle;
+return (PyObject *)rv;
+"""
+
+f = ManualGenerator("Handle", handle_body)
+f.docstring = lambda: """Convert a string to a Handle object.
+
+Resource() and Handle() are very similar, but objects created with Handle() are
+by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()
+to change this.
"""
functions.append(f)
@@ -46,3 +77,22 @@ f = ResMethod(void, 'LoadResource',
(Handle, 'theResource', InMode),
)
resmethods.append(f)
+
+#
+# A method to set the auto-dispose flag
+#
+AutoDispose_body = """
+int onoff, old = 0;
+if (!PyArg_ParseTuple(_args, "i", &onoff))
+ return NULL;
+if ( _self->ob_freeit )
+ old = 1;
+if ( onoff )
+ _self->ob_freeit = PyMac_AutoDisposeHandle;
+else
+ _self->ob_freeit = NULL;
+return Py_BuildValue("i", old);
+"""
+f = ManualGenerator("AutoDispose", AutoDispose_body)
+f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"
+resmethods.append(f)