mirror of https://github.com/python/cpython
Changes for BeOS, QNX and long long, by Chris Herborth.
This commit is contained in:
parent
7d896ab1bb
commit
1a8791e0b8
|
@ -54,6 +54,11 @@ int PyImport_ImportFrozenModule Py_PROTO((char *));
|
||||||
extern PyObject *_PyImport_FindExtension Py_PROTO((char *, char *));
|
extern PyObject *_PyImport_FindExtension Py_PROTO((char *, char *));
|
||||||
extern PyObject *_PyImport_FixupExtension Py_PROTO((char *, char *));
|
extern PyObject *_PyImport_FixupExtension Py_PROTO((char *, char *));
|
||||||
|
|
||||||
|
#ifdef __BEOS__
|
||||||
|
#include <kernel/image.h>
|
||||||
|
extern image_id PyImport_BeImageID( char *name );
|
||||||
|
#endif
|
||||||
|
|
||||||
struct _inittab {
|
struct _inittab {
|
||||||
char *name;
|
char *name;
|
||||||
void (*initfunc)();
|
void (*initfunc)();
|
||||||
|
|
|
@ -50,6 +50,13 @@ extern long PyLong_AsLong Py_PROTO((PyObject *));
|
||||||
extern unsigned long PyLong_AsUnsignedLong Py_PROTO((PyObject *));
|
extern unsigned long PyLong_AsUnsignedLong Py_PROTO((PyObject *));
|
||||||
extern double PyLong_AsDouble Py_PROTO((PyObject *));
|
extern double PyLong_AsDouble Py_PROTO((PyObject *));
|
||||||
|
|
||||||
|
#ifdef HAVE_LONG_LONG
|
||||||
|
extern PyObject *PyLong_FromLongLong Py_PROTO((long long ));
|
||||||
|
extern PyObject *PyLong_FromUnsignedLongLong Py_PROTO((unsigned long long));
|
||||||
|
extern long long PyLong_AsLongLong Py_PROTO((PyObject *));
|
||||||
|
extern unsigned long long PyLong_AsUnsignedLongLong Py_PROTO((PyObject *));
|
||||||
|
#endif
|
||||||
|
|
||||||
PyObject *PyLong_FromString Py_PROTO((char *, char **, int));
|
PyObject *PyLong_FromString Py_PROTO((char *, char **, int));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -20,10 +20,17 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Macros defining new names for all these symbols */
|
/* Macros defining new names for all these symbols */
|
||||||
|
/* BeOS note: We have exit_thread(), and no legacy code to
|
||||||
|
* support, so we won't allow exit_thread and _exit_thread
|
||||||
|
* in here. Actually, I think these #defines should vanish;
|
||||||
|
* aren't they cheesy in the face of the Great Renaming? [cjh]
|
||||||
|
*/
|
||||||
#define init_thread PyThread_init_thread
|
#define init_thread PyThread_init_thread
|
||||||
#define start_new_thread PyThread_start_new_thread
|
#define start_new_thread PyThread_start_new_thread
|
||||||
|
#ifndef __BEOS__
|
||||||
#define exit_thread PyThread_exit_thread
|
#define exit_thread PyThread_exit_thread
|
||||||
#define _exit_thread PyThread__exit_thread
|
#define _exit_thread PyThread__exit_thread
|
||||||
|
#endif
|
||||||
#define get_thread_ident PyThread_get_thread_ident
|
#define get_thread_ident PyThread_get_thread_ident
|
||||||
#define allocate_lock PyThread_allocate_lock
|
#define allocate_lock PyThread_allocate_lock
|
||||||
#define free_lock PyThread_free_lock
|
#define free_lock PyThread_free_lock
|
||||||
|
@ -43,8 +50,13 @@ extern "C" {
|
||||||
|
|
||||||
void init_thread Py_PROTO((void));
|
void init_thread Py_PROTO((void));
|
||||||
int start_new_thread Py_PROTO((void (*)(void *), void *));
|
int start_new_thread Py_PROTO((void (*)(void *), void *));
|
||||||
|
#ifndef __BEOS__
|
||||||
void exit_thread Py_PROTO((void));
|
void exit_thread Py_PROTO((void));
|
||||||
void _exit_thread Py_PROTO((void));
|
void _exit_thread Py_PROTO((void));
|
||||||
|
#else
|
||||||
|
void PyThread_exit_thread Py_PROTO((void));
|
||||||
|
void PyThread__exit_thread Py_PROTO((void));
|
||||||
|
#endif
|
||||||
long get_thread_ident Py_PROTO((void));
|
long get_thread_ident Py_PROTO((void));
|
||||||
|
|
||||||
type_lock allocate_lock Py_PROTO((void));
|
type_lock allocate_lock Py_PROTO((void));
|
||||||
|
|
|
@ -20,10 +20,17 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Macros defining new names for all these symbols */
|
/* Macros defining new names for all these symbols */
|
||||||
|
/* BeOS note: We have exit_thread(), and no legacy code to
|
||||||
|
* support, so we won't allow exit_thread and _exit_thread
|
||||||
|
* in here. Actually, I think these #defines should vanish;
|
||||||
|
* aren't they cheesy in the face of the Great Renaming? [cjh]
|
||||||
|
*/
|
||||||
#define init_thread PyThread_init_thread
|
#define init_thread PyThread_init_thread
|
||||||
#define start_new_thread PyThread_start_new_thread
|
#define start_new_thread PyThread_start_new_thread
|
||||||
|
#ifndef __BEOS__
|
||||||
#define exit_thread PyThread_exit_thread
|
#define exit_thread PyThread_exit_thread
|
||||||
#define _exit_thread PyThread__exit_thread
|
#define _exit_thread PyThread__exit_thread
|
||||||
|
#endif
|
||||||
#define get_thread_ident PyThread_get_thread_ident
|
#define get_thread_ident PyThread_get_thread_ident
|
||||||
#define allocate_lock PyThread_allocate_lock
|
#define allocate_lock PyThread_allocate_lock
|
||||||
#define free_lock PyThread_free_lock
|
#define free_lock PyThread_free_lock
|
||||||
|
@ -43,8 +50,13 @@ extern "C" {
|
||||||
|
|
||||||
void init_thread Py_PROTO((void));
|
void init_thread Py_PROTO((void));
|
||||||
int start_new_thread Py_PROTO((void (*)(void *), void *));
|
int start_new_thread Py_PROTO((void (*)(void *), void *));
|
||||||
|
#ifndef __BEOS__
|
||||||
void exit_thread Py_PROTO((void));
|
void exit_thread Py_PROTO((void));
|
||||||
void _exit_thread Py_PROTO((void));
|
void _exit_thread Py_PROTO((void));
|
||||||
|
#else
|
||||||
|
void PyThread_exit_thread Py_PROTO((void));
|
||||||
|
void PyThread__exit_thread Py_PROTO((void));
|
||||||
|
#endif
|
||||||
long get_thread_ident Py_PROTO((void));
|
long get_thread_ident Py_PROTO((void));
|
||||||
|
|
||||||
type_lock allocate_lock Py_PROTO((void));
|
type_lock allocate_lock Py_PROTO((void));
|
||||||
|
|
|
@ -277,6 +277,198 @@ PyLong_AsDouble(vv)
|
||||||
return x * sign;
|
return x * sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LONG_LONG
|
||||||
|
/*
|
||||||
|
* long long support by Chris Herborth (chrish@qnx.com)
|
||||||
|
*
|
||||||
|
* For better or worse :-), I tried to follow the coding style already
|
||||||
|
* here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_LIMITS_H
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Hopefully this is portable... */
|
||||||
|
#ifndef LONG_MAX
|
||||||
|
#define LONG_MAX 2147483647L
|
||||||
|
#endif
|
||||||
|
#ifndef ULONG_MAX
|
||||||
|
#define ULONG_MAX 4294967295U
|
||||||
|
#endif
|
||||||
|
#ifndef LONGLONG_MAX
|
||||||
|
#define LONGLONG_MAX 9223372036854775807LL
|
||||||
|
#endif
|
||||||
|
#ifndef ULONGLONG_MAX
|
||||||
|
#define ULONGLONG_MAX 0xffffffffffffffffULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Create a new long int object from a C long long int */
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
PyLong_FromLongLong(ival)
|
||||||
|
long long ival;
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||||
|
/* In case the compiler is faking it. */
|
||||||
|
return PyLong_FromLong( (long)ival );
|
||||||
|
#else
|
||||||
|
if( ival <= (long long)LONG_MAX ) {
|
||||||
|
return PyLong_FromLong( (long)ival );
|
||||||
|
} else if( ival <= (unsigned long long)ULONG_MAX ) {
|
||||||
|
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||||
|
} else {
|
||||||
|
/* Assume a C long long fits in at most 10 'digits'.
|
||||||
|
* Should be OK if we're assuming long fits in 5.
|
||||||
|
*/
|
||||||
|
PyLongObject *v = _PyLong_New(10);
|
||||||
|
|
||||||
|
if (v != NULL) {
|
||||||
|
unsigned long long t = ival;
|
||||||
|
int i;
|
||||||
|
if (ival < 0) {
|
||||||
|
t = -ival;
|
||||||
|
v->ob_size = -(v->ob_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
v->ob_digit[i] = (digit) (t & MASK);
|
||||||
|
t >>= SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = long_normalize(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (PyObject *)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we got here, we're confused... */
|
||||||
|
PyErr_SetString( PyExc_ArithmeticError, "invalid long integer" );
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create a new long int object from a C unsigned long long int */
|
||||||
|
PyObject *
|
||||||
|
PyLong_FromUnsignedLongLong(ival)
|
||||||
|
unsigned long long ival;
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||||
|
/* In case the compiler is faking it. */
|
||||||
|
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||||
|
#else
|
||||||
|
if( ival <= (unsigned long long)ULONG_MAX ) {
|
||||||
|
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||||
|
} else {
|
||||||
|
/* Assume a C long fits in at most 10 'digits'. */
|
||||||
|
PyLongObject *v = _PyLong_New(10);
|
||||||
|
|
||||||
|
if (v != NULL) {
|
||||||
|
unsigned long long t = ival;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
v->ob_digit[i] = (digit) (t & MASK);
|
||||||
|
t >>= SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = long_normalize(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (PyObject *)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we got here, we're confused... */
|
||||||
|
PyErr_SetString( PyExc_ArithmeticError, "invalid unsigned long integer" );
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a C long long int from a long int object.
|
||||||
|
Returns -1 and sets an error condition if overflow occurs. */
|
||||||
|
|
||||||
|
long long
|
||||||
|
PyLong_AsLongLong(vv)
|
||||||
|
PyObject *vv;
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||||
|
/* In case the compiler is faking it. */
|
||||||
|
return (long long)PyLong_AsLong( vv );
|
||||||
|
#else
|
||||||
|
register PyLongObject *v;
|
||||||
|
long long x, prev;
|
||||||
|
int i, sign;
|
||||||
|
|
||||||
|
if (vv == NULL || !PyLong_Check(vv)) {
|
||||||
|
PyErr_BadInternalCall();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = (PyLongObject *)vv;
|
||||||
|
i = v->ob_size;
|
||||||
|
sign = 1;
|
||||||
|
x = 0;
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
sign = -1;
|
||||||
|
i = -(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (--i >= 0) {
|
||||||
|
prev = x;
|
||||||
|
x = (x << SHIFT) + v->ob_digit[i];
|
||||||
|
if ((x >> SHIFT) != prev) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"long int too long to convert");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return x * sign;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long
|
||||||
|
PyLong_AsUnsignedLongLong(vv)
|
||||||
|
PyObject *vv;
|
||||||
|
{
|
||||||
|
#if SIZEOF_LONG_LONG == 4
|
||||||
|
/* In case the compiler is faking it. */
|
||||||
|
return (unsigned long long)PyLong_AsUnsignedLong( vv );
|
||||||
|
#else
|
||||||
|
register PyLongObject *v;
|
||||||
|
unsigned long long x, prev;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (vv == NULL || !PyLong_Check(vv)) {
|
||||||
|
PyErr_BadInternalCall();
|
||||||
|
return (unsigned long long) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = (PyLongObject *)vv;
|
||||||
|
i = v->ob_size;
|
||||||
|
x = 0;
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"can't convert negative value to unsigned long");
|
||||||
|
return (unsigned long long) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (--i >= 0) {
|
||||||
|
prev = x;
|
||||||
|
x = (x << SHIFT) + v->ob_digit[i];
|
||||||
|
if ((x >> SHIFT) != prev) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"long int too long to convert");
|
||||||
|
return (unsigned long long) -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif /* HAVE_LONG_LONG */
|
||||||
|
|
||||||
/* Multiply by a single digit, ignoring the sign. */
|
/* Multiply by a single digit, ignoring the sign. */
|
||||||
|
|
||||||
static PyLongObject *
|
static PyLongObject *
|
||||||
|
|
|
@ -42,6 +42,11 @@ extern void PyWinFreeze_ExeTerm();
|
||||||
#include <unistd.h> /* For isatty() */
|
#include <unistd.h> /* For isatty() */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* For isatty()'s proto. - [cjh] */
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Main program */
|
/* Main program */
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -499,6 +499,20 @@ convertsimple1(arg, p_format, p_va)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_LONG_LONG
|
||||||
|
case 'L': /* long long */
|
||||||
|
{
|
||||||
|
long long *p = va_arg( *p_va, long long * );
|
||||||
|
long long ival = PyLong_AsLongLong( arg );
|
||||||
|
if( ival == (long long)-1 && PyErr_Occurred() ) {
|
||||||
|
return "long<L>";
|
||||||
|
} else {
|
||||||
|
*p = ival;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case 'f': /* float */
|
case 'f': /* float */
|
||||||
{
|
{
|
||||||
float *p = va_arg(*p_va, float *);
|
float *p = va_arg(*p_va, float *);
|
||||||
|
@ -988,6 +1002,14 @@ skipitem(p_format, p_va)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_LONG_LONG
|
||||||
|
case 'L': /* long long int */
|
||||||
|
{
|
||||||
|
(void) va_arg(*p_va, long long *);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case 'f': /* float */
|
case 'f': /* float */
|
||||||
{
|
{
|
||||||
(void) va_arg(*p_va, float *);
|
(void) va_arg(*p_va, float *);
|
||||||
|
|
|
@ -2274,7 +2274,7 @@ static PyMethodDef imp_methods[] = {
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
static int
|
||||||
setint(d, name, value)
|
setint(d, name, value)
|
||||||
PyObject *d;
|
PyObject *d;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
|
@ -61,6 +61,7 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
__NetBSD__ -- NetBSD shared libraries
|
__NetBSD__ -- NetBSD shared libraries
|
||||||
(assuming dlerror() was introduced between 1.2 and 1.3)
|
(assuming dlerror() was introduced between 1.2 and 1.3)
|
||||||
__FreeBSD__ -- FreeBSD shared libraries
|
__FreeBSD__ -- FreeBSD shared libraries
|
||||||
|
__BEOS__ -- BeOS shared libraries - defined by the compiler
|
||||||
|
|
||||||
(The other WITH_* symbols are used only once, to set the
|
(The other WITH_* symbols are used only once, to set the
|
||||||
appropriate symbols.)
|
appropriate symbols.)
|
||||||
|
@ -164,6 +165,44 @@ static int aix_bindnewmodule(void *, void *);
|
||||||
static void aix_loaderror(char *);
|
static void aix_loaderror(char *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __BEOS__
|
||||||
|
# undef USE_SHLIB /* probably not defined anyway */
|
||||||
|
# define DYNAMIC_LINK
|
||||||
|
# define SHORT_EXT ".so"
|
||||||
|
# define LONG_EXT "module.so"
|
||||||
|
typedef void (*dl_funcptr)(void);
|
||||||
|
# define _DL_FUNCPTR_DEFINED
|
||||||
|
|
||||||
|
# if defined(MAXPATHLEN) && !defined(_SYS_PARAM_H)
|
||||||
|
# undef MAXPATHLEN
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# include <kernel/image.h>
|
||||||
|
# include <kernel/OS.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
# ifdef WITH_THREAD
|
||||||
|
# include "thread.h"
|
||||||
|
static type_lock beos_dyn_lock;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
static PyObject *beos_dyn_images = NULL;
|
||||||
|
|
||||||
|
static void beos_init_dyn( void );
|
||||||
|
static void beos_cleanup_dyn( void );
|
||||||
|
static void beos_nuke_dyn( PyObject *item );
|
||||||
|
static void beos_add_dyn( char *pathname, image_id id );
|
||||||
|
|
||||||
|
/* External interface for finding image IDs; useful if you need to
|
||||||
|
* do your own symbol lookup in dynamically loaded modules. [Donn Cave]
|
||||||
|
*
|
||||||
|
* Hmm, could we hack up the Sun dlmodule instead for this sort of thing?
|
||||||
|
* That might be more generally useful. [chrish]
|
||||||
|
*/
|
||||||
|
image_id PyImport_BeImageID( char *name );
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DYNAMIC_LINK
|
#ifdef DYNAMIC_LINK
|
||||||
|
|
||||||
#ifdef USE_SHLIB
|
#ifdef USE_SHLIB
|
||||||
|
@ -597,6 +636,96 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
|
||||||
perror(funcname);
|
perror(funcname);
|
||||||
}
|
}
|
||||||
#endif /* hpux */
|
#endif /* hpux */
|
||||||
|
#ifdef __BEOS__
|
||||||
|
{
|
||||||
|
image_id the_id;
|
||||||
|
status_t retval;
|
||||||
|
char fullpath[PATH_MAX];
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( the_id ) {
|
||||||
|
case B_ERROR:
|
||||||
|
sprintf( buff, "BeOS: Failed to load %.200s", fullpath );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sprintf( buff, "Unknown error loading %.200s", fullpath );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_SetString( PyExc_ImportError, buff );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
sprintf( buff, "can't load init function for dynamic module: "
|
||||||
|
"Invalid image ID for %.180s", fullpath );
|
||||||
|
break;
|
||||||
|
case B_BAD_INDEX:
|
||||||
|
sprintf( buff, "can't load init function for dynamic module: "
|
||||||
|
"Bad index for %.180s", funcname );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sprintf( 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( name, the_id );
|
||||||
|
}
|
||||||
|
#endif /* __BEOS__ */
|
||||||
#ifdef USE_SHLIB
|
#ifdef USE_SHLIB
|
||||||
got_it:
|
got_it:
|
||||||
#endif
|
#endif
|
||||||
|
@ -785,3 +914,159 @@ aix_loaderror(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _AIX */
|
#endif /* _AIX */
|
||||||
|
|
||||||
|
#ifdef __BEOS__
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
* 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]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Given a module name, return the image_id (if it's a dynamically loaded
|
||||||
|
* module). [Donn Cave]
|
||||||
|
*/
|
||||||
|
image_id PyImport_BeImageID( char *name )
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
PyObject *py_id;
|
||||||
|
long id;
|
||||||
|
|
||||||
|
if( !beos_dyn_images ) {
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
|
retval = PyThread_acquire_lock( beos_dyn_lock, 1 );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
py_id = PyDict_GetItemString( beos_dyn_images, name );
|
||||||
|
if( py_id ) {
|
||||||
|
id = PyInt_AsLong( py_id );
|
||||||
|
} else {
|
||||||
|
id = B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_THREAD
|
||||||
|
PyThread_release_lock( beos_dyn_lock );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (image_id)id;
|
||||||
|
}
|
||||||
|
#endif /* __BEOS__ */
|
||||||
|
|
|
@ -291,6 +291,11 @@ do_mkvalue(p_format, p_va)
|
||||||
case 'l':
|
case 'l':
|
||||||
return PyInt_FromLong((long)va_arg(*p_va, long));
|
return PyInt_FromLong((long)va_arg(*p_va, long));
|
||||||
|
|
||||||
|
#if HAVE_LONG_LONG
|
||||||
|
case 'L':
|
||||||
|
return PyLong_FromLongLong((long long)va_arg(*p_va, long long));
|
||||||
|
#endif
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'd':
|
case 'd':
|
||||||
return PyFloat_FromDouble(
|
return PyFloat_FromDouble(
|
||||||
|
|
|
@ -12,4 +12,13 @@
|
||||||
jmp_buf PyFPE_jbuf;
|
jmp_buf PyFPE_jbuf;
|
||||||
int PyFPE_counter = 0;
|
int PyFPE_counter = 0;
|
||||||
double PyFPE_dummy(void *dummy){ return 1.0; }
|
double PyFPE_dummy(void *dummy){ return 1.0; }
|
||||||
|
#else
|
||||||
|
#ifdef __MWERKS__
|
||||||
|
/*
|
||||||
|
* Metrowerks fails when compiling an empty file, at least in strict ANSI
|
||||||
|
* mode. - [cjh]
|
||||||
|
*/
|
||||||
|
static double PyFPE_dummy( void * );
|
||||||
|
static double PyFPE_dummy( void *dummy ) { return 1.0; }
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -153,6 +153,10 @@ void init_thread _P0()
|
||||||
#include "thread_os2.h"
|
#include "thread_os2.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BEOS_THREADS
|
||||||
|
#include "thread_beos.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef FOOBAR_THREADS
|
#ifdef FOOBAR_THREADS
|
||||||
#include "thread_foobar.h"
|
#include "thread_foobar.h"
|
||||||
|
|
Loading…
Reference in New Issue