From 270b7a3b0ea1e5f7485320b502c5b5b91da457ab Mon Sep 17 00:00:00 2001 From: pefavel Date: Mon, 16 Mar 2026 13:37:47 +0300 Subject: add fastapi to piglet config commit_hash:6962a6b28ec3ee5fdc2392a2415810aaa54943c4 --- contrib/tools/python/src/Python/atof.c | 50 +++ contrib/tools/python/src/Python/dup2.c | 31 ++ contrib/tools/python/src/Python/dynload_aix.c | 183 ++++++++ contrib/tools/python/src/Python/dynload_atheos.c | 47 ++ contrib/tools/python/src/Python/dynload_beos.c | 254 +++++++++++ contrib/tools/python/src/Python/dynload_dl.c | 26 ++ contrib/tools/python/src/Python/dynload_hpux.c | 58 +++ contrib/tools/python/src/Python/dynload_next.c | 114 +++++ contrib/tools/python/src/Python/dynload_os2.c | 46 ++ contrib/tools/python/src/Python/dynload_stub.c | 11 + contrib/tools/python/src/Python/frozen.c | 38 ++ contrib/tools/python/src/Python/frozenmain.c | 69 +++ contrib/tools/python/src/Python/getcwd.c | 82 ++++ contrib/tools/python/src/Python/mactoolboxglue.c | 474 +++++++++++++++++++++ .../tools/python/src/Python/makeopcodetargets.py | 45 ++ contrib/tools/python/src/Python/sigcheck.c | 19 + contrib/tools/python/src/Python/strdup.c | 14 + contrib/tools/python/src/Python/strtod.c | 159 +++++++ 18 files changed, 1720 insertions(+) create mode 100644 contrib/tools/python/src/Python/atof.c create mode 100644 contrib/tools/python/src/Python/dup2.c create mode 100644 contrib/tools/python/src/Python/dynload_aix.c create mode 100644 contrib/tools/python/src/Python/dynload_atheos.c create mode 100644 contrib/tools/python/src/Python/dynload_beos.c create mode 100644 contrib/tools/python/src/Python/dynload_dl.c create mode 100644 contrib/tools/python/src/Python/dynload_hpux.c create mode 100644 contrib/tools/python/src/Python/dynload_next.c create mode 100644 contrib/tools/python/src/Python/dynload_os2.c create mode 100644 contrib/tools/python/src/Python/dynload_stub.c create mode 100644 contrib/tools/python/src/Python/frozen.c create mode 100644 contrib/tools/python/src/Python/frozenmain.c create mode 100644 contrib/tools/python/src/Python/getcwd.c create mode 100644 contrib/tools/python/src/Python/mactoolboxglue.c create mode 100755 contrib/tools/python/src/Python/makeopcodetargets.py create mode 100644 contrib/tools/python/src/Python/sigcheck.c create mode 100644 contrib/tools/python/src/Python/strdup.c create mode 100644 contrib/tools/python/src/Python/strtod.c (limited to 'contrib/tools/python/src/Python') diff --git a/contrib/tools/python/src/Python/atof.c b/contrib/tools/python/src/Python/atof.c new file mode 100644 index 00000000000..562fcd688e8 --- /dev/null +++ b/contrib/tools/python/src/Python/atof.c @@ -0,0 +1,50 @@ + +/* Just in case you haven't got an atof() around... + This one doesn't check for bad syntax or overflow, + and is slow and inaccurate. + But it's good enough for the occasional string literal... */ + +#include "pyconfig.h" + +#include + +double atof(char *s) +{ + double a = 0.0; + int e = 0; + int c; + while ((c = *s++) != '\0' && isdigit(c)) { + a = a*10.0 + (c - '0'); + } + if (c == '.') { + while ((c = *s++) != '\0' && isdigit(c)) { + a = a*10.0 + (c - '0'); + e = e-1; + } + } + if (c == 'e' || c == 'E') { + int sign = 1; + int i = 0; + c = *s++; + if (c == '+') + c = *s++; + else if (c == '-') { + c = *s++; + sign = -1; + } + while (isdigit(c)) { + i = i*10 + (c - '0'); + c = *s++; + } + e += i*sign; + } + while (e > 0) { + a *= 10.0; + e--; + } + while (e < 0) { + a *= 0.1; + e++; + } + return a; +} diff --git a/contrib/tools/python/src/Python/dup2.c b/contrib/tools/python/src/Python/dup2.c new file mode 100644 index 00000000000..2579afd443d --- /dev/null +++ b/contrib/tools/python/src/Python/dup2.c @@ -0,0 +1,31 @@ +/* + * Public domain dup2() lookalike + * by Curtis Jackson @ AT&T Technologies, Burlington, NC + * electronic address: burl!rcj + * + * dup2 performs the following functions: + * + * Check to make sure that fd1 is a valid open file descriptor. + * Check to see if fd2 is already open; if so, close it. + * Duplicate fd1 onto fd2; checking to make sure fd2 is a valid fd. + * Return fd2 if all went well; return BADEXIT otherwise. + */ + +#include +#include + +#define BADEXIT -1 + +int +dup2(int fd1, int fd2) +{ + if (fd1 != fd2) { + if (fcntl(fd1, F_GETFL) < 0) + return BADEXIT; + if (fcntl(fd2, F_GETFL) >= 0) + close(fd2); + if (fcntl(fd1, F_DUPFD, fd2) < 0) + return BADEXIT; + } + return fd2; +} diff --git a/contrib/tools/python/src/Python/dynload_aix.c b/contrib/tools/python/src/Python/dynload_aix.c new file mode 100644 index 00000000000..149990d7995 --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_aix.c @@ -0,0 +1,183 @@ + +/* Support for dynamic loading of extension modules */ + +#include "Python.h" +#include "importdl.h" + +#include /* for isdigit() */ +#include /* for global errno */ +#include /* for strerror() */ +#include /* for malloc(), free() */ +#include + + +#ifdef AIX_GENUINE_CPLUSPLUS +#include +#define aix_load loadAndInit +#else +#define aix_load load +#endif + + +extern char *Py_GetProgramName(void); + +typedef struct Module { + struct Module *next; + void *entry; +} Module, *ModulePtr; + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {".so", "rb", C_EXTENSION}, + {"module.so", "rb", C_EXTENSION}, + {0, 0} +}; + +static int +aix_getoldmodules(void **modlistptr) +{ + register ModulePtr modptr, prevmodptr; + register struct ld_info *ldiptr; + register char *ldibuf; + register int errflag, bufsize = 1024; + register unsigned int offset; + char *progname = Py_GetProgramName(); + + /* + -- Get the list of loaded modules into ld_info structures. + */ + if ((ldibuf = malloc(bufsize)) == NULL) { + PyErr_SetString(PyExc_ImportError, strerror(errno)); + return -1; + } + while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1 + && errno == ENOMEM) { + free(ldibuf); + bufsize += 1024; + if ((ldibuf = malloc(bufsize)) == NULL) { + PyErr_SetString(PyExc_ImportError, strerror(errno)); + return -1; + } + } + if (errflag == -1) { + PyErr_SetString(PyExc_ImportError, strerror(errno)); + return -1; + } + /* + -- Make the modules list from the ld_info structures. + */ + ldiptr = (struct ld_info *)ldibuf; + prevmodptr = NULL; + do { + if (strstr(progname, ldiptr->ldinfo_filename) == NULL && + strstr(ldiptr->ldinfo_filename, "python") == NULL) { + /* + -- Extract only the modules belonging to the main + -- executable + those containing "python" as a + -- substring (like the "python[version]" binary or + -- "libpython[version].a" in case it's a shared lib). + */ + offset = (unsigned int)ldiptr->ldinfo_next; + ldiptr = (struct ld_info *)((char*)ldiptr + offset); + continue; + } + if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) { + PyErr_SetString(PyExc_ImportError, strerror(errno)); + while (*modlistptr) { + modptr = (ModulePtr)*modlistptr; + *modlistptr = (void *)modptr->next; + free(modptr); + } + return -1; + } + modptr->entry = ldiptr->ldinfo_dataorg; + modptr->next = NULL; + if (prevmodptr == NULL) + *modlistptr = (void *)modptr; + else + prevmodptr->next = modptr; + prevmodptr = modptr; + offset = (unsigned int)ldiptr->ldinfo_next; + ldiptr = (struct ld_info *)((char*)ldiptr + offset); + } while (offset); + free(ldibuf); + return 0; +} + + +static void +aix_loaderror(const char *pathname) +{ + + char *message[1024], errbuf[1024]; + register int i,j; + + struct errtab { + int errNo; + char *errstr; + } load_errtab[] = { + {L_ERROR_TOOMANY, "too many errors, rest skipped."}, + {L_ERROR_NOLIB, "can't load library:"}, + {L_ERROR_UNDEF, "can't find symbol in library:"}, + {L_ERROR_RLDBAD, + "RLD index out of range or bad relocation type:"}, + {L_ERROR_FORMAT, "not a valid, executable xcoff file:"}, + {L_ERROR_MEMBER, + "file not an archive or does not contain requested member:"}, + {L_ERROR_TYPE, "symbol table mismatch:"}, + {L_ERROR_ALIGN, "text alignment in file is wrong."}, + {L_ERROR_SYSTEM, "System error:"}, + {L_ERROR_ERRNO, NULL} + }; + +#define LOAD_ERRTAB_LEN (sizeof(load_errtab)/sizeof(load_errtab[0])) +#define ERRBUF_APPEND(s) strncat(errbuf, s, sizeof(errbuf)-strlen(errbuf)-1) + + PyOS_snprintf(errbuf, sizeof(errbuf), "from module %.200s ", pathname); + + if (!loadquery(L_GETMESSAGES, &message[0], sizeof(message))) { + ERRBUF_APPEND(strerror(errno)); + ERRBUF_APPEND("\n"); + } + for(i = 0; message[i] && *message[i]; i++) { + int nerr = atoi(message[i]); + for (j=0; j +#include + +#include "Python.h" +#include "importdl.h" + + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {".so", "rb", C_EXTENSION}, + {"module.so", "rb", C_EXTENSION}, + {0, 0} +}; + +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) +{ + void *p; + int lib; + char funcname[258]; + + if (Py_VerboseFlag) + printf("load_library %s\n", pathname); + + lib = load_library(pathname, 0); + if (lib < 0) { + char buf[512]; + if (Py_VerboseFlag) + perror(pathname); + PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s: %.200s", + pathname, strerror(errno)); + PyErr_SetString(PyExc_ImportError, buf); + return NULL; + } + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); + if (Py_VerboseFlag) + printf("get_symbol_address %s\n", funcname); + if (get_symbol_address(lib, funcname, -1, &p) < 0) { + p = NULL; + if (Py_VerboseFlag) + perror(funcname); + } + + return (dl_funcptr) p; +} diff --git a/contrib/tools/python/src/Python/dynload_beos.c b/contrib/tools/python/src/Python/dynload_beos.c new file mode 100644 index 00000000000..f5ca1ec3aa6 --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_beos.c @@ -0,0 +1,254 @@ + +/* Support for dynamic loading of extension modules */ + +#include +#include +#include + +#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; +} diff --git a/contrib/tools/python/src/Python/dynload_dl.c b/contrib/tools/python/src/Python/dynload_dl.c new file mode 100644 index 00000000000..4675a6722ac --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_dl.c @@ -0,0 +1,26 @@ + +/* Support for dynamic loading of extension modules */ + +#include "dl.h" + +#include "Python.h" +#include "importdl.h" + + +extern char *Py_GetProgramName(void); + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {".o", "rb", C_EXTENSION}, + {"module.o", "rb", C_EXTENSION}, + {0, 0} +}; + + +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) +{ + char funcname[258]; + + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); + return dl_loadmod(Py_GetProgramName(), pathname, funcname); +} diff --git a/contrib/tools/python/src/Python/dynload_hpux.c b/contrib/tools/python/src/Python/dynload_hpux.c new file mode 100644 index 00000000000..c6ce16ef7e5 --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_hpux.c @@ -0,0 +1,58 @@ + +/* Support for dynamic loading of extension modules */ + +#include "dl.h" +#include + +#include "Python.h" +#include "importdl.h" + +#if defined(__hp9000s300) +#define FUNCNAME_PATTERN "_init%.200s" +#else +#define FUNCNAME_PATTERN "init%.200s" +#endif + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {SHLIB_EXT, "rb", C_EXTENSION}, + {"module"SHLIB_EXT, "rb", C_EXTENSION}, + {0, 0} +}; + +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) +{ + dl_funcptr p; + shl_t lib; + int flags; + char funcname[258]; + + flags = BIND_FIRST | BIND_DEFERRED; + if (Py_VerboseFlag) { + flags = BIND_FIRST | BIND_IMMEDIATE | + BIND_NONFATAL | BIND_VERBOSE; + printf("shl_load %s\n",pathname); + } + lib = shl_load(pathname, flags, 0); + /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */ + if (lib == NULL) { + char buf[256]; + if (Py_VerboseFlag) + perror(pathname); + PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s", + pathname); + PyErr_SetString(PyExc_ImportError, buf); + return NULL; + } + PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname); + if (Py_VerboseFlag) + printf("shl_findsym %s\n", funcname); + if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) { + shl_unload(lib); + p = NULL; + } + if (p == NULL && Py_VerboseFlag) + perror(funcname); + + return p; +} diff --git a/contrib/tools/python/src/Python/dynload_next.c b/contrib/tools/python/src/Python/dynload_next.c new file mode 100644 index 00000000000..7e61b5d5708 --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_next.c @@ -0,0 +1,114 @@ + +/* Support for dynamic loading of extension modules on Mac OS X +** All references to "NeXT" are for historical reasons. +*/ + +#include "Python.h" +#include "importdl.h" + +#include + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {".so", "rb", C_EXTENSION}, + {"module.so", "rb", C_EXTENSION}, + {0, 0} +}; + +/* +** Python modules are Mach-O MH_BUNDLE files. The best way to load these +** is each in a private namespace, so you can load, say, a module bar and a +** module foo.bar. If we load everything in the global namespace the two +** initbar() symbols will conflict. +** However, it seems some extension packages depend upon being able to access +** each others' global symbols. There seems to be no way to eat our cake and +** have it, so the USE_DYLD_GLOBAL_NAMESPACE define determines which behaviour +** you get. +*/ + +#ifdef USE_DYLD_GLOBAL_NAMESPACE +#define LINKOPTIONS NSLINKMODULE_OPTION_BINDNOW|NSLINKMODULE_OPTION_RETURN_ON_ERROR +#else +#define LINKOPTIONS NSLINKMODULE_OPTION_BINDNOW| \ + NSLINKMODULE_OPTION_RETURN_ON_ERROR|NSLINKMODULE_OPTION_PRIVATE +#endif +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) +{ + dl_funcptr p = NULL; + char funcname[258]; + NSObjectFileImageReturnCode rc; + NSObjectFileImage image; + NSModule newModule; + NSSymbol theSym; + const char *errString; + char errBuf[512]; + + PyOS_snprintf(funcname, sizeof(funcname), "_init%.200s", shortname); + +#ifdef USE_DYLD_GLOBAL_NAMESPACE + if (NSIsSymbolNameDefined(funcname)) { + theSym = NSLookupAndBindSymbol(funcname); + p = (dl_funcptr)NSAddressOfSymbol(theSym); + return p; + } +#endif + rc = NSCreateObjectFileImageFromFile(pathname, &image); + switch(rc) { + default: + case NSObjectFileImageFailure: + case NSObjectFileImageFormat: + /* for these a message is printed on stderr by dyld */ + errString = "Can't create object file image"; + break; + case NSObjectFileImageSuccess: + errString = NULL; + break; + case NSObjectFileImageInappropriateFile: + errString = "Inappropriate file type for dynamic loading"; + break; + case NSObjectFileImageArch: + errString = "Wrong CPU type in object file"; + break; + case NSObjectFileImageAccess: + errString = "Can't read object file (no access)"; + break; + } + if (errString == NULL) { + newModule = NSLinkModule(image, pathname, LINKOPTIONS); + if (newModule == NULL) { + int errNo; + const char *fileName, *moreErrorStr; + NSLinkEditErrors c; + NSLinkEditError( &c, &errNo, &fileName, &moreErrorStr ); + PyOS_snprintf(errBuf, 512, "Failure linking new module: %s: %s", + fileName, moreErrorStr); + errString = errBuf; + } + } + if (errString != NULL) { + PyErr_SetString(PyExc_ImportError, errString); + return NULL; + } +#ifdef USE_DYLD_GLOBAL_NAMESPACE + if (!NSIsSymbolNameDefined(funcname)) { + /* UnlinkModule() isn't implemented in current versions, but calling it does no harm */ + /* NSUnLinkModule(newModule, FALSE); removed: causes problems for ObjC code */ + PyErr_Format(PyExc_ImportError, + "Loaded module does not contain symbol %.200s", + funcname); + return NULL; + } + theSym = NSLookupAndBindSymbol(funcname); +#else + theSym = NSLookupSymbolInModule(newModule, funcname); + if ( theSym == NULL ) { + /* NSUnLinkModule(newModule, FALSE); removed: causes problems for ObjC code */ + PyErr_Format(PyExc_ImportError, + "Loaded module does not contain symbol %.200s", + funcname); + return NULL; + } +#endif + p = (dl_funcptr)NSAddressOfSymbol(theSym); + return p; +} diff --git a/contrib/tools/python/src/Python/dynload_os2.c b/contrib/tools/python/src/Python/dynload_os2.c new file mode 100644 index 00000000000..e3fdb70ab68 --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_os2.c @@ -0,0 +1,46 @@ + +/* Support for dynamic loading of extension modules */ + +#define INCL_DOSERRORS +#define INCL_DOSMODULEMGR +#include + +#include "Python.h" +#include "importdl.h" + + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {".pyd", "rb", C_EXTENSION}, + {".dll", "rb", C_EXTENSION}, + {0, 0} +}; + +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) +{ + dl_funcptr p; + APIRET rc; + HMODULE hDLL; + char failreason[256]; + char funcname[258]; + + rc = DosLoadModule(failreason, + sizeof(failreason), + pathname, + &hDLL); + + if (rc != NO_ERROR) { + char errBuf[256]; + PyOS_snprintf(errBuf, sizeof(errBuf), + "DLL load failed, rc = %d: %.200s", + rc, failreason); + PyErr_SetString(PyExc_ImportError, errBuf); + return NULL; + } + + PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname); + rc = DosQueryProcAddr(hDLL, 0L, funcname, &p); + if (rc != NO_ERROR) + p = NULL; /* Signify Failure to Acquire Entrypoint */ + return p; +} diff --git a/contrib/tools/python/src/Python/dynload_stub.c b/contrib/tools/python/src/Python/dynload_stub.c new file mode 100644 index 00000000000..69f8b450b3a --- /dev/null +++ b/contrib/tools/python/src/Python/dynload_stub.c @@ -0,0 +1,11 @@ + +/* This module provides the necessary stubs for when dynamic loading is + not present. */ + +#include "Python.h" +#include "importdl.h" + + +const struct filedescr _PyImport_DynLoadFiletab[] = { + {0, 0} +}; diff --git a/contrib/tools/python/src/Python/frozen.c b/contrib/tools/python/src/Python/frozen.c new file mode 100644 index 00000000000..ae7e9a4a93d --- /dev/null +++ b/contrib/tools/python/src/Python/frozen.c @@ -0,0 +1,38 @@ + +/* Dummy frozen modules initializer */ + +#include "Python.h" + +/* In order to test the support for frozen modules, by default we + define a single frozen module, __hello__. Loading it will print + some famous words... */ + +/* To regenerate this data after the bytecode or marshal format has changed, + go to ../Tools/freeze/ and freeze the hello.py file; then copy and paste + the appropriate bytes from M___main__.c. */ + +static unsigned char M___hello__[] = { + 99,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, + 0,115,9,0,0,0,100,0,0,71,72,100,1,0,83,40, + 2,0,0,0,115,14,0,0,0,72,101,108,108,111,32,119, + 111,114,108,100,46,46,46,78,40,0,0,0,0,40,0,0, + 0,0,40,0,0,0,0,40,0,0,0,0,115,8,0,0, + 0,104,101,108,108,111,46,112,121,115,1,0,0,0,63,1, + 0,0,0,115,0,0,0,0, +}; + +#define SIZE (int)sizeof(M___hello__) + +static struct _frozen _PyImport_FrozenModules[] = { + /* Test module */ + {"__hello__", M___hello__, SIZE}, + /* Test package (negative size indicates package-ness) */ + {"__phello__", M___hello__, -SIZE}, + {"__phello__.spam", M___hello__, SIZE}, + {0, 0, 0} /* sentinel */ +}; + +/* Embedding apps may change this pointer to point to their favorite + collection of frozen modules: */ + +struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; diff --git a/contrib/tools/python/src/Python/frozenmain.c b/contrib/tools/python/src/Python/frozenmain.c new file mode 100644 index 00000000000..e742172494e --- /dev/null +++ b/contrib/tools/python/src/Python/frozenmain.c @@ -0,0 +1,69 @@ + +/* Python interpreter main program for frozen scripts */ + +#include "Python.h" + +#ifdef MS_WINDOWS +extern void PyWinFreeze_ExeInit(void); +extern void PyWinFreeze_ExeTerm(void); +extern int PyInitFrozenExtensions(void); +#endif + +/* Main program */ + +int +Py_FrozenMain(int argc, char **argv) +{ + char *p; + int n, sts; + int inspect = 0; + int unbuffered = 0; + + Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ + + if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') + inspect = 1; + if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') + unbuffered = 1; + + if (unbuffered) { + setbuf(stdin, (char *)NULL); + setbuf(stdout, (char *)NULL); + setbuf(stderr, (char *)NULL); + } + +#ifdef MS_WINDOWS + PyInitFrozenExtensions(); +#endif /* MS_WINDOWS */ + if (argc >= 1) + Py_SetProgramName(argv[0]); + Py_Initialize(); +#ifdef MS_WINDOWS + PyWinFreeze_ExeInit(); +#endif + + if (Py_VerboseFlag) + fprintf(stderr, "Python %s\n%s\n", + Py_GetVersion(), Py_GetCopyright()); + + PySys_SetArgv(argc, argv); + + n = PyImport_ImportFrozenModule("__main__"); + if (n == 0) + Py_FatalError("__main__ not frozen"); + if (n < 0) { + PyErr_Print(); + sts = 1; + } + else + sts = 0; + + if (inspect && isatty((int)fileno(stdin))) + sts = PyRun_AnyFile(stdin, "") != 0; + +#ifdef MS_WINDOWS + PyWinFreeze_ExeTerm(); +#endif + Py_Finalize(); + return sts; +} diff --git a/contrib/tools/python/src/Python/getcwd.c b/contrib/tools/python/src/Python/getcwd.c new file mode 100644 index 00000000000..44dc9e69ab8 --- /dev/null +++ b/contrib/tools/python/src/Python/getcwd.c @@ -0,0 +1,82 @@ + +/* Two PD getcwd() implementations. + Author: Guido van Rossum, CWI Amsterdam, Jan 1991, . */ + +#include +#include + +#ifdef HAVE_GETWD + +/* Version for BSD systems -- use getwd() */ + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifndef MAXPATHLEN +#if defined(PATH_MAX) && PATH_MAX > 1024 +#define MAXPATHLEN PATH_MAX +#else +#define MAXPATHLEN 1024 +#endif +#endif + +extern char *getwd(char *); + +char * +getcwd(char *buf, int size) +{ + char localbuf[MAXPATHLEN+1]; + char *ret; + + if (size <= 0) { + errno = EINVAL; + return NULL; + } + ret = getwd(localbuf); + if (ret != NULL && strlen(localbuf) >= (size_t)size) { + errno = ERANGE; + return NULL; + } + if (ret == NULL) { + errno = EACCES; /* Most likely error */ + return NULL; + } + strncpy(buf, localbuf, size); + return buf; +} + +#else /* !HAVE_GETWD */ + +/* Version for really old UNIX systems -- use pipe from pwd */ + +#ifndef PWD_CMD +#define PWD_CMD "/bin/pwd" +#endif + +char * +getcwd(char *buf, int size) +{ + FILE *fp; + char *p; + if (size <= 0) { + errno = EINVAL; + return NULL; + } + if ((fp = popen(PWD_CMD, "r")) == NULL) + return NULL; + if (fgets(buf, size, fp) == NULL || pclose(fp) != 0) { + errno = EACCES; /* Most likely error */ + return NULL; + } + for (p = buf; *p != '\n'; p++) { + if (*p == '\0') { + errno = ERANGE; + return NULL; + } + } + *p = '\0'; + return buf; +} + +#endif /* !HAVE_GETWD */ diff --git a/contrib/tools/python/src/Python/mactoolboxglue.c b/contrib/tools/python/src/Python/mactoolboxglue.c new file mode 100644 index 00000000000..b91be3b7aa0 --- /dev/null +++ b/contrib/tools/python/src/Python/mactoolboxglue.c @@ -0,0 +1,474 @@ +/*********************************************************** +Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, +The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + + +#include "Python.h" +#include "pymactoolbox.h" +#include /* for ntohl, htonl */ + + +/* Like strerror() but for Mac OS error numbers */ +char * +PyMac_StrError(int err) +{ + static char buf[256]; + PyObject *m; + PyObject *rv; + + m = PyImport_ImportModuleNoBlock("MacOS"); + if (!m) { + if (Py_VerboseFlag) + PyErr_Print(); + PyErr_Clear(); + rv = NULL; + } + else { + rv = PyObject_CallMethod(m, "GetErrorString", "i", err); + if (!rv) + PyErr_Clear(); + } + if (!rv) { + buf[0] = '\0'; + } + else { + char *input = PyString_AsString(rv); + if (!input) { + PyErr_Clear(); + buf[0] = '\0'; + } else { + strncpy(buf, input, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + } + Py_DECREF(rv); + } + Py_XDECREF(m); + return buf; +} + +/* Exception object shared by all Mac specific modules for Mac OS errors */ +PyObject *PyMac_OSErrException; + +/* Initialize and return PyMac_OSErrException */ +PyObject * +PyMac_GetOSErrException(void) +{ + if (PyMac_OSErrException == NULL) + PyMac_OSErrException = PyErr_NewException("MacOS.Error", NULL, NULL); + return PyMac_OSErrException; +} + +/* Set a MAC-specific error from errno, and return NULL; return None if no error */ +PyObject * +PyErr_Mac(PyObject *eobj, int err) +{ + char *msg; + PyObject *v; + + if (err == 0 && !PyErr_Occurred()) { + Py_INCREF(Py_None); + return Py_None; + } + if (err == -1 && PyErr_Occurred()) + return NULL; + msg = PyMac_StrError(err); + v = Py_BuildValue("(is)", err, msg); + PyErr_SetObject(eobj, v); + Py_DECREF(v); + return NULL; +} + +/* Call PyErr_Mac with PyMac_OSErrException */ +PyObject * +PyMac_Error(OSErr err) +{ + return PyErr_Mac(PyMac_GetOSErrException(), err); +} + + +#if APPLE_SUPPORTS_QUICKTIME +OSErr +PyMac_GetFullPathname(FSSpec *fss, char *path, int len) +{ + PyObject *fs, *exc; + PyObject *rv = NULL; + char *input; + OSErr err = noErr; + + *path = '\0'; + + fs = PyMac_BuildFSSpec(fss); + if (!fs) + goto error; + + rv = PyObject_CallMethod(fs, "as_pathname", ""); + if (!rv) + goto error; + + input = PyString_AsString(rv); + if (!input) + goto error; + + strncpy(path, input, len - 1); + path[len - 1] = '\0'; + + Py_XDECREF(rv); + Py_XDECREF(fs); + return err; + + error: + exc = PyErr_Occurred(); + if (exc && PyErr_GivenExceptionMatches(exc, + PyMac_GetOSErrException())) { + PyObject *args = PyObject_GetAttrString(exc, "args"); + if (args) { + char *ignore; + PyArg_ParseTuple(args, "is", &err, &ignore); + Py_XDECREF(args); + } + } + if (err == noErr) + err = -1; + PyErr_Clear(); + Py_XDECREF(rv); + Py_XDECREF(fs); + return err; +} +#endif /* APPLE_SUPPORTS_QUICKTIME */ + +/* Convert a 4-char string object argument to an OSType value */ +int +PyMac_GetOSType(PyObject *v, OSType *pr) +{ + uint32_t tmp; + if (!PyString_Check(v) || PyString_Size(v) != 4) { + PyErr_SetString(PyExc_TypeError, + "OSType arg must be string of 4 chars"); + return 0; + } + memcpy((char *)&tmp, PyString_AsString(v), 4); + *pr = (OSType)ntohl(tmp); + return 1; +} + +/* Convert an OSType value to a 4-char string object */ +PyObject * +PyMac_BuildOSType(OSType t) +{ + uint32_t tmp = htonl((uint32_t)t); + return PyString_FromStringAndSize((char *)&tmp, 4); +} + +/* Convert an NumVersion value to a 4-element tuple */ +PyObject * +PyMac_BuildNumVersion(NumVersion t) +{ + return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev); +} + + +/* Convert a Python string object to a Str255 */ +int +PyMac_GetStr255(PyObject *v, Str255 pbuf) +{ + int len; + if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { + PyErr_SetString(PyExc_TypeError, + "Str255 arg must be string of at most 255 chars"); + return 0; + } + pbuf[0] = len; + memcpy((char *)(pbuf+1), PyString_AsString(v), len); + return 1; +} + +/* Convert a Str255 to a Python string object */ +PyObject * +PyMac_BuildStr255(Str255 s) +{ + if ( s == NULL ) { + PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL"); + return NULL; + } + return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); +} + +PyObject * +PyMac_BuildOptStr255(Str255 s) +{ + if ( s == NULL ) { + Py_INCREF(Py_None); + return Py_None; + } + return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); +} + + + +/* Convert a Python object to a Rect. + The object must be a (left, top, right, bottom) tuple. + (This differs from the order in the struct but is consistent with + the arguments to SetRect(), and also with STDWIN). */ +int +PyMac_GetRect(PyObject *v, Rect *r) +{ + return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom); +} + +/* Convert a Rect to a Python object */ +PyObject * +PyMac_BuildRect(Rect *r) +{ + return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom); +} + + +/* Convert a Python object to a Point. + The object must be a (h, v) tuple. + (This differs from the order in the struct but is consistent with + the arguments to SetPoint(), and also with STDWIN). */ +int +PyMac_GetPoint(PyObject *v, Point *p) +{ + return PyArg_Parse(v, "(hh)", &p->h, &p->v); +} + +/* Convert a Point to a Python object */ +PyObject * +PyMac_BuildPoint(Point p) +{ + return Py_BuildValue("(hh)", p.h, p.v); +} + + +/* Convert a Python object to an EventRecord. + The object must be a (what, message, when, (v, h), modifiers) tuple. */ +int +PyMac_GetEventRecord(PyObject *v, EventRecord *e) +{ + return PyArg_Parse(v, "(Hkk(hh)H)", + &e->what, + &e->message, + &e->when, + &e->where.h, + &e->where.v, + &e->modifiers); +} + +/* Convert a Rect to an EventRecord object */ +PyObject * +PyMac_BuildEventRecord(EventRecord *e) +{ + return Py_BuildValue("(hll(hh)h)", + e->what, + e->message, + e->when, + e->where.h, + e->where.v, + e->modifiers); +} + +/* Convert Python object to Fixed */ +int +PyMac_GetFixed(PyObject *v, Fixed *f) +{ + double d; + + if( !PyArg_Parse(v, "d", &d)) + return 0; + *f = (Fixed)(d * 0x10000); + return 1; +} + +/* Convert a Fixed to a Python object */ +PyObject * +PyMac_BuildFixed(Fixed f) +{ + double d; + + d = f; + d = d / 0x10000; + return Py_BuildValue("d", d); +} + +/* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */ +int +PyMac_Getwide(PyObject *v, wide *rv) +{ + if (PyInt_Check(v)) { + rv->hi = 0; + rv->lo = PyInt_AsLong(v); + if( rv->lo & 0x80000000 ) + rv->hi = -1; + return 1; + } + return PyArg_Parse(v, "(kk)", &rv->hi, &rv->lo); +} + + +PyObject * +PyMac_Buildwide(wide *w) +{ + if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) || + (w->hi == -1 && (w->lo & 0x80000000) ) ) + return PyInt_FromLong(w->lo); + return Py_BuildValue("(ll)", w->hi, w->lo); +} + +#ifdef USE_TOOLBOX_OBJECT_GLUE +/* +** Glue together the toolbox objects. +** +** Because toolbox modules interdepend on each other, they use each others +** object types, on MacOSX/MachO this leads to the situation that they +** cannot be dynamically loaded (or they would all have to be lumped into +** a single .so, but this would be bad for extensibility). +** +** This file defines wrappers for all the _New and _Convert functions, +** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers +** check an indirection function pointer, and if it isn't filled in yet +** they import the appropriate module, whose init routine should fill in +** the pointer. +*/ + +#define GLUE_NEW(object, routinename, module) \ +PyObject *(*PyMacGluePtr_##routinename)(object); \ +\ +PyObject *routinename(object cobj) { \ + if (!PyMacGluePtr_##routinename) { \ + if (!PyImport_ImportModule(module)) return NULL; \ + if (!PyMacGluePtr_##routinename) { \ + PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ + return NULL; \ + } \ + } \ + return (*PyMacGluePtr_##routinename)(cobj); \ +} + +#define GLUE_CONVERT(object, routinename, module) \ +int (*PyMacGluePtr_##routinename)(PyObject *, object *); \ +\ +int routinename(PyObject *pyobj, object *cobj) { \ + if (!PyMacGluePtr_##routinename) { \ + if (!PyImport_ImportModule(module)) return 0; \ + if (!PyMacGluePtr_##routinename) { \ + PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ + return 0; \ + } \ + } \ + return (*PyMacGluePtr_##routinename)(pyobj, cobj); \ +} + +GLUE_NEW(FSSpec *, PyMac_BuildFSSpec, "Carbon.File") +GLUE_CONVERT(FSSpec, PyMac_GetFSSpec, "Carbon.File") +GLUE_NEW(FSRef *, PyMac_BuildFSRef, "Carbon.File") +GLUE_CONVERT(FSRef, PyMac_GetFSRef, "Carbon.File") + +GLUE_NEW(AppleEvent *, AEDesc_New, "Carbon.AE") /* XXXX Why by address? */ +GLUE_NEW(AppleEvent *, AEDesc_NewBorrowed, "Carbon.AE") +GLUE_CONVERT(AppleEvent, AEDesc_Convert, "Carbon.AE") + +GLUE_NEW(Component, CmpObj_New, "Carbon.Cm") +GLUE_CONVERT(Component, CmpObj_Convert, "Carbon.Cm") +GLUE_NEW(ComponentInstance, CmpInstObj_New, "Carbon.Cm") +GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Carbon.Cm") + +GLUE_NEW(ControlHandle, CtlObj_New, "Carbon.Ctl") +GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Carbon.Ctl") + +GLUE_NEW(DialogPtr, DlgObj_New, "Carbon.Dlg") +GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Carbon.Dlg") +GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Carbon.Dlg") + +GLUE_NEW(DragReference, DragObj_New, "Carbon.Drag") +GLUE_CONVERT(DragReference, DragObj_Convert, "Carbon.Drag") + +GLUE_NEW(ListHandle, ListObj_New, "Carbon.List") +GLUE_CONVERT(ListHandle, ListObj_Convert, "Carbon.List") + +GLUE_NEW(MenuHandle, MenuObj_New, "Carbon.Menu") +GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Carbon.Menu") + +GLUE_NEW(GrafPtr, GrafObj_New, "Carbon.Qd") +GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Carbon.Qd") +GLUE_NEW(BitMapPtr, BMObj_New, "Carbon.Qd") +GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Carbon.Qd") +GLUE_NEW(RGBColor *, QdRGB_New, "Carbon.Qd") /* XXXX Why? */ +GLUE_CONVERT(RGBColor, QdRGB_Convert, "Carbon.Qd") + +GLUE_NEW(GWorldPtr, GWorldObj_New, "Carbon.Qdoffs") +GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Carbon.Qdoffs") + +#if APPLE_SUPPORTS_QUICKTIME +GLUE_NEW(Track, TrackObj_New, "Carbon.Qt") +GLUE_CONVERT(Track, TrackObj_Convert, "Carbon.Qt") +GLUE_NEW(Movie, MovieObj_New, "Carbon.Qt") +GLUE_CONVERT(Movie, MovieObj_Convert, "Carbon.Qt") +GLUE_NEW(MovieController, MovieCtlObj_New, "Carbon.Qt") +GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Carbon.Qt") +GLUE_NEW(TimeBase, TimeBaseObj_New, "Carbon.Qt") +GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Carbon.Qt") +GLUE_NEW(UserData, UserDataObj_New, "Carbon.Qt") +GLUE_CONVERT(UserData, UserDataObj_Convert, "Carbon.Qt") +GLUE_NEW(Media, MediaObj_New, "Carbon.Qt") +GLUE_CONVERT(Media, MediaObj_Convert, "Carbon.Qt") +#endif /* APPLE_SUPPORTS_QUICKTIME */ + +GLUE_NEW(Handle, ResObj_New, "Carbon.Res") +GLUE_CONVERT(Handle, ResObj_Convert, "Carbon.Res") +GLUE_NEW(Handle, OptResObj_New, "Carbon.Res") +GLUE_CONVERT(Handle, OptResObj_Convert, "Carbon.Res") + +GLUE_NEW(TEHandle, TEObj_New, "Carbon.TE") +GLUE_CONVERT(TEHandle, TEObj_Convert, "Carbon.TE") + +GLUE_NEW(WindowPtr, WinObj_New, "Carbon.Win") +GLUE_CONVERT(WindowPtr, WinObj_Convert, "Carbon.Win") +GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Carbon.Win") + +GLUE_CONVERT(CFTypeRef, CFObj_Convert, "Carbon.CF") +GLUE_NEW(CFTypeRef, CFObj_New, "Carbon.CF") + +GLUE_CONVERT(CFTypeRef, CFTypeRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFTypeRef, CFTypeRefObj_New, "Carbon.CF") + +GLUE_CONVERT(CFStringRef, CFStringRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFStringRef, CFStringRefObj_New, "Carbon.CF") +GLUE_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFMutableStringRef, CFMutableStringRefObj_New, "Carbon.CF") + +GLUE_CONVERT(CFArrayRef, CFArrayRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFArrayRef, CFArrayRefObj_New, "Carbon.CF") +GLUE_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New, "Carbon.CF") + +GLUE_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFDictionaryRef, CFDictionaryRefObj_New, "Carbon.CF") +GLUE_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New, "Carbon.CF") + +GLUE_CONVERT(CFURLRef, CFURLRefObj_Convert, "Carbon.CF") +GLUE_CONVERT(CFURLRef, OptionalCFURLRefObj_Convert, "Carbon.CF") +GLUE_NEW(CFURLRef, CFURLRefObj_New, "Carbon.CF") + +#endif /* USE_TOOLBOX_OBJECT_GLUE */ diff --git a/contrib/tools/python/src/Python/makeopcodetargets.py b/contrib/tools/python/src/Python/makeopcodetargets.py new file mode 100755 index 00000000000..fcbf5ef7918 --- /dev/null +++ b/contrib/tools/python/src/Python/makeopcodetargets.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python +"""Generate C code for the jump table of the threaded code interpreter +(for compilers supporting computed gotos or "labels-as-values", such as gcc). +""" + +# This code should stay compatible with Python 2.3, at least while +# some of the buildbots have Python 2.3 as their system Python. + +import imp +import os + + +def find_module(modname): + """Finds and returns a module in the local dist/checkout. + """ + modpath = os.path.join( + os.path.dirname(os.path.dirname(__file__)), "Lib") + return imp.load_module(modname, *imp.find_module(modname, [modpath])) + +def write_contents(f): + """Write C code contents to the target file object. + """ + opcode = find_module("opcode") + targets = ['_unknown_opcode'] * 256 + for opname, op in opcode.opmap.items(): + if opname == "STOP_CODE": + continue + targets[op] = "TARGET_%s" % opname.replace("+0", " ").replace("+", "_") + f.write("static void *opcode_targets[256] = {\n") + f.write(",\n".join([" &&%s" % s for s in targets])) + f.write("\n};\n") + + +if __name__ == "__main__": + import sys + assert len(sys.argv) < 3, "Too many arguments" + if len(sys.argv) == 2: + target = sys.argv[1] + else: + target = "Python/opcode_targets.h" + f = open(target, "w") + try: + write_contents(f) + finally: + f.close() diff --git a/contrib/tools/python/src/Python/sigcheck.c b/contrib/tools/python/src/Python/sigcheck.c new file mode 100644 index 00000000000..022d0e8ac39 --- /dev/null +++ b/contrib/tools/python/src/Python/sigcheck.c @@ -0,0 +1,19 @@ + +/* Sigcheck is similar to intrcheck() but sets an exception when an + interrupt occurs. It can't be in the intrcheck.c file since that + file (and the whole directory it is in) doesn't know about objects + or exceptions. It can't be in errors.c because it can be + overridden (at link time) by a more powerful version implemented in + signalmodule.c. */ + +#include "Python.h" + +/* ARGSUSED */ +int +PyErr_CheckSignals(void) +{ + if (!PyOS_InterruptOccurred()) + return 0; + PyErr_SetNone(PyExc_KeyboardInterrupt); + return -1; +} diff --git a/contrib/tools/python/src/Python/strdup.c b/contrib/tools/python/src/Python/strdup.c new file mode 100644 index 00000000000..20187e0f0a7 --- /dev/null +++ b/contrib/tools/python/src/Python/strdup.c @@ -0,0 +1,14 @@ +/* strdup() replacement (from stdwin, if you must know) */ + +#include "pgenheaders.h" + +char * +strdup(const char *str) +{ + if (str != NULL) { + register char *copy = malloc(strlen(str) + 1); + if (copy != NULL) + return strcpy(copy, str); + } + return NULL; +} diff --git a/contrib/tools/python/src/Python/strtod.c b/contrib/tools/python/src/Python/strtod.c new file mode 100644 index 00000000000..ee558982d53 --- /dev/null +++ b/contrib/tools/python/src/Python/strtod.c @@ -0,0 +1,159 @@ +#include +#include + +#include "pyconfig.h" + +/* comp.sources.misc strtod(), as posted in comp.lang.tcl, + with bugfix for "123000.0" and acceptance of space after 'e' sign nuked. + + ************************************************************ + * YOU MUST EDIT THE MACHINE-DEPENDENT DEFINITIONS BELOW!!! * + ************************************************************ +*/ + +/* File : stdtod.c (Modified version of str2dbl.c) + Author : Richard A. O'Keefe @ Quintus Computer Systems, Inc. + Updated: Tuesday August 2nd, 1988 + Defines: double strtod (char *str, char**ptr) +*/ + +/* This is an implementation of the strtod() function described in the + System V manuals, with a different name to avoid linker problems. + All that str2dbl() does itself is check that the argument is well-formed + and is in range. It leaves the work of conversion to atof(), which is + assumed to exist and deliver correct results (if they can be represented). + + There are two reasons why this should be provided to the net: + (a) some UNIX systems do not yet have strtod(), or do not have it + available in the BSD "universe" (but they do have atof()). + (b) some of the UNIX systems that *do* have it get it wrong. + (some crash with large arguments, some assign the wrong *ptr value). + There is a reason why *we* are providing it: we need a correct version + of strtod(), and if we give this one away maybe someone will look for + mistakes in it and fix them for us (:-). +*/ + +/* The following constants are machine-specific. MD{MIN,MAX}EXPT are + integers and MD{MIN,MAX}FRAC are strings such that + 0.${MDMAXFRAC}e${MDMAXEXPT} is the largest representable double, + 0.${MDMINFRAC}e${MDMINEXPT} is the smallest representable +ve double + MD{MIN,MAX}FRAC must not have any trailing zeros. + The values here are for IEEE-754 64-bit floats. + It is not perfectly clear to me whether an IEEE infinity should be + returned for overflow, nor what a portable way of writing one is, + so HUGE is just 0.MAXFRAC*10**MAXEXPT (this seems still to be the + UNIX convention). + + I do know about , but the whole point of this file is that + we can't always trust that stuff to be there or to be correct. +*/ +static int MDMINEXPT = -323; +static char MDMINFRAC[] = "494065645841246544"; +static double ZERO = 0.0; + +static int MDMAXEXPT = 309; +static char MDMAXFRAC[] = "17976931348623157"; +static double HUGE = 1.7976931348623157e308; + +extern double atof(const char *); /* Only called when result known to be ok */ + +#ifdef HAVE_ERRNO_H +#include +#endif +extern int errno; + +double strtod(char *str, char **ptr) +{ + int sign, scale, dotseen; + int esign, expt; + char *save; + register char *sp, *dp; + register int c; + char *buforg, *buflim; + char buffer[64]; /* 45-digit significant + */ + /* 13-digit exponent */ + sp = str; + while (*sp == ' ') sp++; + sign = 1; + if (*sp == '-') sign -= 2, sp++; + dotseen = 0, scale = 0; + dp = buffer; + *dp++ = '0'; *dp++ = '.'; + buforg = dp, buflim = buffer+48; + for (save = sp; (c = *sp); sp++) + if (c == '.') { + if (dotseen) break; + dotseen++; + } else + if ((unsigned)(c-'0') > (unsigned)('9'-'0')) { + break; + } else + if (c == '0') { + if (dp != buforg) { + /* This is not the first digit, so we want to keep it */ + if (dp < buflim) *dp++ = c; + if (!dotseen) scale++; + } else { + /* No non-zero digits seen yet */ + /* If a . has been seen, scale must be adjusted */ + if (dotseen) scale--; + } + } else { + /* This is a nonzero digit, so we want to keep it */ + if (dp < buflim) *dp++ = c; + /* If it precedes a ., scale must be adjusted */ + if (!dotseen) scale++; + } + if (sp == save) { + if (ptr) *ptr = str; + errno = EDOM; /* what should this be? */ + return ZERO; + } + + while (dp > buforg && dp[-1] == '0') --dp; + if (dp == buforg) *dp++ = '0'; + *dp = '\0'; + /* Now the contents of buffer are + +--+--------+-+--------+ + |0.|fraction|\|leftover| + +--+--------+-+--------+ + ^dp points here + where fraction begins with 0 iff it is "0", and has at most + 45 digits in it, and leftover is at least 16 characters. + */ + save = sp, expt = 0, esign = 1; + do { + c = *sp++; + if (c != 'e' && c != 'E') break; + c = *sp++; + if (c == '-') esign -= 2, c = *sp++; else + if (c == '+' /* || c == ' ' */ ) c = *sp++; + if ((unsigned)(c-'0') > (unsigned)('9'-'0')) break; + while (c == '0') c = *sp++; + for (; (unsigned)(c-'0') <= (unsigned)('9'-'0'); c = *sp++) + expt = expt*10 + c-'0'; + if (esign < 0) expt = -expt; + save = sp-1; + } while (0); + if (ptr) *ptr = save; + expt += scale; + /* Now the number is sign*0.fraction*10**expt */ + errno = ERANGE; + if (expt > MDMAXEXPT) { + return HUGE*sign; + } else + if (expt == MDMAXEXPT) { + if (strcmp(buforg, MDMAXFRAC) > 0) return HUGE*sign; + } else + if (expt < MDMINEXPT) { + return ZERO*sign; + } else + if (expt == MDMINEXPT) { + if (strcmp(buforg, MDMINFRAC) < 0) return ZERO*sign; + } + /* We have now established that the number can be */ + /* represented without overflow or underflow */ + (void) sprintf(dp, "E%d", expt); + errno = 0; + return atof(buffer)*sign; +} -- cgit v1.3