Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f73bab7

Browse files
committed
Added an attribute string_id_to_buffer, which gives the offset you
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...
1 parent 377df98 commit f73bab7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Mac/Modules/macosmodule.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,5 +637,17 @@ MacOS_Init()
637637
MacOS_Error = PyMac_GetOSErrException();
638638
if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
639639
Py_FatalError("can't define MacOS.Error");
640+
/*
641+
** This is a hack: the following constant added to the id() of a string
642+
** object gives you the address of the data. Unfortunately, it is needed for
643+
** some of the image and sound processing interfaces on the mac:-(
644+
*/
645+
{
646+
PyStringObject *p = 0;
647+
long off = (long)&(p->ob_sval[0]);
648+
649+
if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0)
650+
Py_FatalError("Can't define MacOS.string_id_to_buffer");
651+
}
640652
}
641653

0 commit comments

Comments
 (0)