Remove support for BeOS

This commit is contained in:
Skip Montanaro 2007-08-17 12:57:41 +00:00
parent e9af284e99
commit eb33e5ae79
24 changed files with 8150 additions and 10214 deletions

View file

@ -1,254 +0,0 @@
/* Support for dynamic loading of extension modules */
#include <kernel/image.h>
#include <kernel/OS.h>
#include <stdlib.h>
#include "Python.h"
#include "importdl.h"
const struct filedescr _PyImport_DynLoadFiletab[] = {
{".so", "rb", C_EXTENSION},
{"module.so", "rb", C_EXTENSION},
{0, 0}
};
#if defined(MAXPATHLEN) && !defined(_SYS_PARAM_H)
#undef MAXPATHLEN
#endif
#ifdef WITH_THREAD
#include "pythread.h"
static PyThread_type_lock beos_dyn_lock;
#endif
static PyObject *beos_dyn_images = NULL;
/* ----------------------------------------------------------------------
* 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;
#ifdef WITH_THREAD
PyThread_acquire_lock( beos_dyn_lock, 1 );
#endif
id_list = PyDict_Values( beos_dyn_images );
list_size = PyList_Size( id_list );
for( idx = 0; idx < list_size; idx++ ) {
PyObject *the_item;
the_item = PyList_GetItem( id_list, idx );
beos_nuke_dyn( the_item );
}
PyDict_Clear( beos_dyn_images );
#ifdef WITH_THREAD
PyThread_free_lock( beos_dyn_lock );
#endif
}
}
/*
* Initialize our dictionary, and the dictionary mutex.
*/
static void beos_init_dyn( void )
{
/* We're protected from a race condition here by the atomic init_count
* variable.
*/
static int32 init_count = 0;
int32 val;
val = atomic_add( &init_count, 1 );
if( beos_dyn_images == NULL && val == 0 ) {
beos_dyn_images = PyDict_New();
#ifdef WITH_THREAD
beos_dyn_lock = PyThread_allocate_lock();
#endif
atexit( beos_cleanup_dyn );
}
}
/*
* 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( beos_dyn_images == NULL ) {
beos_init_dyn();
}
#ifdef WITH_THREAD
retval = PyThread_acquire_lock( beos_dyn_lock, 1 );
#endif
/* 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 );
}
py_id = PyInt_FromLong( (long)id );
if( py_id ) {
retval = PyDict_SetItemString( beos_dyn_images, name, py_id );
}
#ifdef WITH_THREAD
PyThread_release_lock( beos_dyn_lock );
#endif
}
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
image_id the_id;
status_t retval;
char fullpath[PATH_MAX];
char funcname[258];
if( Py_VerboseFlag ) {
printf( "load_add_on( %s )\n", pathname );
}
/* 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 );
if( Py_VerboseFlag ) {
printf( "load_add_on( %s )\n", fullpath );
}
} else {
(void)strcpy( fullpath, pathname );
}
the_id = load_add_on( fullpath );
if( the_id < B_NO_ERROR ) {
/* It's too bad load_add_on() doesn't set errno or something...
*/
char buff[256]; /* hate hard-coded string sizes... */
if( Py_VerboseFlag ) {
printf( "load_add_on( %s ) failed", fullpath );
}
if( the_id == B_ERROR )
PyOS_snprintf( buff, sizeof(buff),
"BeOS: Failed to load %.200s",
fullpath );
else
PyOS_snprintf( buff, sizeof(buff),
"Unknown error loading %.200s",
fullpath );
PyErr_SetString( PyExc_ImportError, buff );
return NULL;
}
PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
if( Py_VerboseFlag ) {
printf( "get_image_symbol( %s )\n", funcname );
}
retval = get_image_symbol( the_id, funcname, B_SYMBOL_TYPE_TEXT, &p );
if( retval != B_NO_ERROR || p == NULL ) {
/* That's bad, we can't find that symbol in the module...
*/
char buff[256]; /* hate hard-coded string sizes... */
if( Py_VerboseFlag ) {
printf( "get_image_symbol( %s ) failed", funcname );
}
switch( retval ) {
case B_BAD_IMAGE_ID:
PyOS_snprintf( buff, sizeof(buff),
"can't load init function for dynamic module: "
"Invalid image ID for %.180s", fullpath );
break;
case B_BAD_INDEX:
PyOS_snprintf( buff, sizeof(buff),
"can't load init function for dynamic module: "
"Bad index for %.180s", funcname );
break;
default:
PyOS_snprintf( buff, sizeof(buff),
"can't load init function for dynamic module: "
"Unknown error looking up %.180s", funcname );
break;
}
retval = unload_add_on( the_id );
PyErr_SetString( PyExc_ImportError, buff );
return NULL;
}
/* Save the module name and image ID for later so we can clean up
* gracefully.
*/
beos_add_dyn( fqname, the_id );
return p;
}

View file

@ -133,10 +133,6 @@ static size_t _pythread_stacksize = 0;
#include "thread_os2.h"
#endif
#ifdef BEOS_THREADS
#include "thread_beos.h"
#endif
#ifdef WINCE_THREADS
#include "thread_wince.h"
#endif

View file

@ -1,287 +0,0 @@
#include <kernel/OS.h>
#include <support/SupportDefs.h>
#include <errno.h>
/* ----------------------------------------------------------------------
* Fast locking mechanism described by Benoit Schillings (benoit@be.com)
* in the Be Developer's Newsletter, Issue #26 (http://www.be.com/).
*/
typedef struct benaphore {
sem_id _sem;
int32 _atom;
} benaphore_t;
static status_t benaphore_create( const char *name, benaphore_t *ben );
static status_t benaphore_destroy( benaphore_t *ben );
static status_t benaphore_lock( benaphore_t *ben );
static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros );
static status_t benaphore_unlock( benaphore_t *ben );
static status_t benaphore_create( const char *name, benaphore_t *ben )
{
if( ben != NULL ) {
ben->_atom = 0;
ben->_sem = create_sem( 0, name );
if( ben->_sem < B_NO_ERROR ) {
return B_BAD_SEM_ID;
}
} else {
return EFAULT;
}
return EOK;
}
static status_t benaphore_destroy( benaphore_t *ben )
{
if( ben->_sem >= B_NO_ERROR ) {
status_t retval = benaphore_timedlock( ben, 0 );
if( retval == EOK || retval == EWOULDBLOCK ) {
status_t del_retval = delete_sem( ben->_sem );
return del_retval;
}
}
return B_BAD_SEM_ID;
}
static status_t benaphore_lock( benaphore_t *ben )
{
int32 prev = atomic_add( &(ben->_atom), 1 );
if( prev > 0 ) {
return acquire_sem( ben->_sem );
}
return EOK;
}
static status_t benaphore_timedlock( benaphore_t *ben, bigtime_t micros )
{
int32 prev = atomic_add( &(ben->_atom), 1 );
if( prev > 0 ) {
status_t retval = acquire_sem_etc( ben->_sem, 1, B_TIMEOUT, micros );
switch( retval ) {
case B_WOULD_BLOCK: /* Fall through... */
case B_TIMED_OUT:
return EWOULDBLOCK;
break;
case B_OK:
return EOK;
break;
default:
return retval;
break;
}
}
return EOK;
}
static status_t benaphore_unlock( benaphore_t *ben )
{
int32 prev = atomic_add( &(ben->_atom), -1 );
if( prev > 1 ) {
return release_sem( ben->_sem );
}
return EOK;
}
/* ----------------------------------------------------------------------
* Initialization.
*/
static void PyThread__init_thread( void )
{
/* Do nothing. */
return;
}
/* ----------------------------------------------------------------------
* Thread support.
*
* Only ANSI C, renamed functions here; you can't use K&R on BeOS,
* and there's no legacy thread module to support.
*/
static int32 thread_count = 0;
long PyThread_start_new_thread( void (*func)(void *), void *arg )
{
status_t success = 0;
thread_id tid;
char name[B_OS_NAME_LENGTH];
int32 this_thread;
dprintf(("PyThread_start_new_thread called\n"));
/* We are so very thread-safe... */
this_thread = atomic_add( &thread_count, 1 );
PyOS_snprintf(name, sizeof(name),
"python thread (%d)", this_thread );
tid = spawn_thread( (thread_func)func, name,
B_NORMAL_PRIORITY, arg );
if( tid > B_NO_ERROR ) {
success = resume_thread( tid );
}
return ( success == B_NO_ERROR ? tid : -1 );
}
long PyThread_get_thread_ident( void )
{
/* Presumed to return the current thread's ID... */
thread_id tid;
tid = find_thread( NULL );
return ( tid != B_NAME_NOT_FOUND ? tid : -1 );
}
static void do_PyThread_exit_thread( int no_cleanup )
{
int32 threads;
dprintf(("PyThread_exit_thread called\n"));
/* Thread-safe way to read a variable without a mutex: */
threads = atomic_add( &thread_count, 0 );
if( threads == 0 ) {
/* No threads around, so exit main(). */
if( no_cleanup ) {
_exit(0);
} else {
exit(0);
}
} else {
/* Oh, we're a thread, let's try to exit gracefully... */
exit_thread( B_NO_ERROR );
}
}
void PyThread_exit_thread( void )
{
do_PyThread_exit_thread(0);
}
void PyThread__exit_thread( void )
{
do_PyThread_exit_thread(1);
}
#ifndef NO_EXIT_PROG
static void do_PyThread_exit_prog( int status, int no_cleanup )
{
dprintf(("PyThread_exit_prog(%d) called\n", status));
/* No need to do anything, the threads get torn down if main() exits. */
if (no_cleanup) {
_exit(status);
} else {
exit(status);
}
}
void PyThread_exit_prog( int status )
{
do_PyThread_exit_prog(status, 0);
}
void PyThread__exit_prog( int status )
{
do_PyThread_exit_prog(status, 1);
}
#endif /* NO_EXIT_PROG */
/* ----------------------------------------------------------------------
* Lock support.
*/
static int32 lock_count = 0;
PyThread_type_lock PyThread_allocate_lock( void )
{
benaphore_t *lock;
status_t retval;
char name[B_OS_NAME_LENGTH];
int32 this_lock;
dprintf(("PyThread_allocate_lock called\n"));
lock = (benaphore_t *)malloc( sizeof( benaphore_t ) );
if( lock == NULL ) {
/* TODO: that's bad, raise MemoryError */
return (PyThread_type_lock)NULL;
}
this_lock = atomic_add( &lock_count, 1 );
PyOS_snprintf(name, sizeof(name), "python lock (%d)", this_lock);
retval = benaphore_create( name, lock );
if( retval != EOK ) {
/* TODO: that's bad, raise an exception */
return (PyThread_type_lock)NULL;
}
dprintf(("PyThread_allocate_lock() -> %p\n", lock));
return (PyThread_type_lock) lock;
}
void PyThread_free_lock( PyThread_type_lock lock )
{
status_t retval;
dprintf(("PyThread_free_lock(%p) called\n", lock));
retval = benaphore_destroy( (benaphore_t *)lock );
if( retval != EOK ) {
/* TODO: that's bad, raise an exception */
return;
}
}
int PyThread_acquire_lock( PyThread_type_lock lock, int waitflag )
{
int success;
status_t retval;
dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
if( waitflag ) {
retval = benaphore_lock( (benaphore_t *)lock );
} else {
retval = benaphore_timedlock( (benaphore_t *)lock, 0 );
}
if( retval == EOK ) {
success = 1;
} else {
success = 0;
/* TODO: that's bad, raise an exception */
}
dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
return success;
}
void PyThread_release_lock( PyThread_type_lock lock )
{
status_t retval;
dprintf(("PyThread_release_lock(%p) called\n", lock));
retval = benaphore_unlock( (benaphore_t *)lock );
if( retval != EOK ) {
/* TODO: that's bad, raise an exception */
return;
}
}