/* ----------------------------------------------------------------------
* BeOS dynamic loading support
*
* This uses shared libraries, but BeOS has its own way of doing things
* (much easier than dlfnc.h, from the look of things). We'll use a
* Python Dictionary object to store the images_ids so we can be very
* nice and unload them when we exit.
*
* Note that this is thread-safe. Probably irrelevent, because of losing
* systems... Python probably disables threads while loading modules.
* Note the use of "probably"! Better to be safe than sorry. [chrish]
*
* As of 1.5.1 this should also work properly when you've configured
* Python without thread support; the 1.5 version required it, which wasn't
* very friendly. Note that I haven't tested it without threading... why
* would you want to avoid threads on BeOS? [chrish]
*
* As of 1.5.2, the PyImport_BeImageID() function has been removed; Donn
* tells me it's not necessary anymore because of PyCObject_Import().
* [chrish]
*/
/* Whack an item; the item is an image_id in disguise, so we'll call
* unload_add_on() for it.
*/
static void beos_nuke_dyn( PyObject *item )
{
status_t retval;
if( item ) {
image_id id = (image_id)PyInt_AsLong( item );
retval = unload_add_on( id );
}
}
/* atexit() handler that'll call unload_add_on() for every item in the
* dictionary.
*/
static void beos_cleanup_dyn( void )
{
if( beos_dyn_images ) {
int idx;
int list_size;
PyObject *id_list;
/*
* Add an image_id to the dictionary; the module name of the loaded image
* is the key. Note that if the key is already in the dict, we unload
* that image; this should allow reload() to work on dynamically loaded
* modules (super-keen!).
*/
static void beos_add_dyn( char *name, image_id id )
{
int retval;
PyObject *py_id;
/* If there's already an object with this key in the dictionary,
* we're doing a reload(), so let's nuke it.
*/
py_id = PyDict_GetItemString( beos_dyn_images, name );
if( py_id ) {
beos_nuke_dyn( py_id );
retval = PyDict_DelItemString( beos_dyn_images, name );
}
/* Hmm, this old bug appears to have regenerated itself; if the
* path isn't absolute, load_add_on() will fail. Reported to Be
* April 21, 1998.
*/
if( pathname[0] != '/' ) {
(void)getcwd( fullpath, PATH_MAX );
(void)strncat( fullpath, "/", PATH_MAX );
(void)strncat( fullpath, pathname, PATH_MAX );