]> granicus.if.org Git - python/commitdiff
Added an attribute string_id_to_buffer, which gives the offset you
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 3 Apr 1997 14:51:03 +0000 (14:51 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 3 Apr 1997 14:51:03 +0000 (14:51 +0000)
have to add to the id() of a string to get the address of the
data. This is a horrible and error-prone hack, but unfortunately it is
one that is needed for playing audio and crearing pixmaps. Having the
constant here is at least marginally better than the previous practice
of having the constant 16 all over the place...

Mac/Modules/macosmodule.c

index 89f986b848da192a9e9d107cad2dfec3330f49ab..90be55d1bbe97e8025d9fbf4d0ba1ff8a4b7af0e 100644 (file)
@@ -637,5 +637,17 @@ MacOS_Init()
        MacOS_Error = PyMac_GetOSErrException();
        if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
                Py_FatalError("can't define MacOS.Error");
+       /*
+       ** This is a hack: the following constant added to the id() of a string
+       ** object gives you the address of the data. Unfortunately, it is needed for
+       ** some of the image and sound processing interfaces on the mac:-(
+       */
+       {
+               PyStringObject *p = 0;
+               long off = (long)&(p->ob_sval[0]);
+               
+               if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0)
+                       Py_FatalError("Can't define MacOS.string_id_to_buffer");
+       }
 }