minor cleanups and whitespace normalisation
This commit is contained in:
parent
699cbb7676
commit
0c83348d5c
|
@ -29,10 +29,9 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/*
|
/* This library implements dlopen() - Unix-like dynamic linking
|
||||||
This library implements dlopen() - functions for OS/2 using
|
* emulation functions for OS/2 using DosLoadModule() and company.
|
||||||
DosLoadModule() and company.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#define INCL_DOS
|
#define INCL_DOS
|
||||||
#define INCL_DOSERRORS
|
#define INCL_DOSERRORS
|
||||||
|
@ -46,8 +45,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
/*-------------------------------------- Unix-like dynamic linking emulation -*/
|
|
||||||
|
|
||||||
typedef struct _track_rec {
|
typedef struct _track_rec {
|
||||||
char *name;
|
char *name;
|
||||||
HMODULE handle;
|
HMODULE handle;
|
||||||
|
@ -55,8 +52,8 @@ typedef struct _track_rec {
|
||||||
struct _track_rec *next;
|
struct _track_rec *next;
|
||||||
} tDLLchain, *DLLchain;
|
} tDLLchain, *DLLchain;
|
||||||
|
|
||||||
static DLLchain dlload = NULL; /* A simple chained list of DLL names */
|
static DLLchain dlload = NULL; /* A simple chained list of DLL names */
|
||||||
static char dlerr [256]; /* last error text string */
|
static char dlerr [256]; /* last error text string */
|
||||||
static void *last_id;
|
static void *last_id;
|
||||||
|
|
||||||
static DLLchain find_id(void *id)
|
static DLLchain find_id(void *id)
|
||||||
|
@ -65,13 +62,13 @@ static DLLchain find_id(void *id)
|
||||||
|
|
||||||
for (tmp = dlload; tmp; tmp = tmp->next)
|
for (tmp = dlload; tmp; tmp = tmp->next)
|
||||||
if (id == tmp->id)
|
if (id == tmp->id)
|
||||||
return (tmp);
|
return tmp;
|
||||||
|
|
||||||
return (NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load a dynamic-link library and return handle */
|
/* load a dynamic-link library and return handle */
|
||||||
void *dlopen (char *filename, int flags)
|
void *dlopen(char *filename, int flags)
|
||||||
{
|
{
|
||||||
HMODULE hm;
|
HMODULE hm;
|
||||||
DLLchain tmp;
|
DLLchain tmp;
|
||||||
|
@ -85,10 +82,10 @@ void *dlopen (char *filename, int flags)
|
||||||
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
{
|
{
|
||||||
tmp = (DLLchain)malloc (sizeof (tDLLchain));
|
tmp = (DLLchain) malloc(sizeof(tDLLchain));
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto nomem;
|
goto nomem;
|
||||||
tmp->name = strdup (filename);
|
tmp->name = strdup(filename);
|
||||||
tmp->next = dlload;
|
tmp->next = dlload;
|
||||||
set_chain = 1;
|
set_chain = 1;
|
||||||
}
|
}
|
||||||
|
@ -97,14 +94,15 @@ void *dlopen (char *filename, int flags)
|
||||||
{
|
{
|
||||||
case NO_ERROR:
|
case NO_ERROR:
|
||||||
tmp->handle = hm;
|
tmp->handle = hm;
|
||||||
if (set_chain) {
|
if (set_chain)
|
||||||
do {
|
{
|
||||||
|
do
|
||||||
last_id++;
|
last_id++;
|
||||||
} while ((last_id == 0) || (find_id(last_id)));
|
while ((last_id == 0) || (find_id(last_id)));
|
||||||
tmp->id = last_id;
|
tmp->id = last_id;
|
||||||
dlload = tmp;
|
dlload = tmp;
|
||||||
}
|
}
|
||||||
return (tmp->id);
|
return tmp->id;
|
||||||
case ERROR_FILE_NOT_FOUND:
|
case ERROR_FILE_NOT_FOUND:
|
||||||
case ERROR_PATH_NOT_FOUND:
|
case ERROR_PATH_NOT_FOUND:
|
||||||
errtxt = "module `%s' not found";
|
errtxt = "module `%s' not found";
|
||||||
|
@ -145,34 +143,35 @@ nomem:
|
||||||
errtxt = "cause `%s', error code = %d";
|
errtxt = "cause `%s', error code = %d";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf (dlerr, sizeof (dlerr), errtxt, &err, rc);
|
snprintf(dlerr, sizeof(dlerr), errtxt, &err, rc);
|
||||||
if (tmp) {
|
if (tmp)
|
||||||
|
{
|
||||||
if (tmp->name)
|
if (tmp->name)
|
||||||
free(tmp->name);
|
free(tmp->name);
|
||||||
free (tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a pointer to the `symbol' in DLL */
|
/* return a pointer to the `symbol' in DLL */
|
||||||
void *dlsym (void *handle, char *symbol)
|
void *dlsym(void *handle, char *symbol)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
PFN addr;
|
PFN addr;
|
||||||
char *errtxt;
|
char *errtxt;
|
||||||
int symord = 0;
|
int symord = 0;
|
||||||
DLLchain tmp = find_id (handle);
|
DLLchain tmp = find_id(handle);
|
||||||
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto inv_handle;
|
goto inv_handle;
|
||||||
|
|
||||||
if (*symbol == '#')
|
if (*symbol == '#')
|
||||||
symord = atoi (symbol + 1);
|
symord = atoi(symbol + 1);
|
||||||
|
|
||||||
switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
|
switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
|
||||||
{
|
{
|
||||||
case NO_ERROR:
|
case NO_ERROR:
|
||||||
return ((void *)addr);
|
return (void *)addr;
|
||||||
case ERROR_INVALID_HANDLE:
|
case ERROR_INVALID_HANDLE:
|
||||||
inv_handle:
|
inv_handle:
|
||||||
errtxt = "invalid module handle";
|
errtxt = "invalid module handle";
|
||||||
|
@ -185,40 +184,40 @@ inv_handle:
|
||||||
errtxt = "symbol `%s', error code = %d";
|
errtxt = "symbol `%s', error code = %d";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf (dlerr, sizeof (dlerr), errtxt, symbol, rc);
|
snprintf(dlerr, sizeof(dlerr), errtxt, symbol, rc);
|
||||||
return (NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free dynamicaly-linked library */
|
/* free dynamicaly-linked library */
|
||||||
int dlclose (void *handle)
|
int dlclose(void *handle)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
DLLchain tmp = find_id (handle);
|
DLLchain tmp = find_id(handle);
|
||||||
|
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto inv_handle;
|
goto inv_handle;
|
||||||
|
|
||||||
switch (rc = DosFreeModule (tmp->handle))
|
switch (rc = DosFreeModule(tmp->handle))
|
||||||
{
|
{
|
||||||
case NO_ERROR:
|
case NO_ERROR:
|
||||||
free (tmp->name);
|
free(tmp->name);
|
||||||
dlload = tmp->next;
|
dlload = tmp->next;
|
||||||
free (tmp);
|
free(tmp);
|
||||||
return (0);
|
return 0;
|
||||||
case ERROR_INVALID_HANDLE:
|
case ERROR_INVALID_HANDLE:
|
||||||
inv_handle:
|
inv_handle:
|
||||||
strcpy(dlerr, "invalid module handle");
|
strcpy(dlerr, "invalid module handle");
|
||||||
return (-1);
|
return -1;
|
||||||
case ERROR_INVALID_ACCESS:
|
case ERROR_INVALID_ACCESS:
|
||||||
strcpy (dlerr, "access denied");
|
strcpy(dlerr, "access denied");
|
||||||
return (-1);
|
return -1;
|
||||||
default:
|
default:
|
||||||
return (-1);
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a string describing last occured dl error */
|
/* return a string describing last occured dl error */
|
||||||
char *dlerror()
|
char *dlerror()
|
||||||
{
|
{
|
||||||
return (dlerr);
|
return dlerr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,21 +29,22 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/*
|
/* This library implements dlopen() - Unix-like dynamic linking
|
||||||
This library implements dlopen() - functions for OS/2 using
|
* emulation functions for OS/2 using DosLoadModule() and company.
|
||||||
DosLoadModule() and company.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _DLFCN_H
|
#ifndef _DLFCN_H
|
||||||
#define _DLFCN_H
|
#define _DLFCN_H
|
||||||
|
|
||||||
/*-------------------------------------- Unix-like dynamic linking emulation -*/
|
|
||||||
/* load a dynamic-link library and return handle */
|
/* load a dynamic-link library and return handle */
|
||||||
void *dlopen (char *filename, int flags);
|
void *dlopen(char *filename, int flags);
|
||||||
|
|
||||||
/* return a pointer to the `symbol' in DLL */
|
/* return a pointer to the `symbol' in DLL */
|
||||||
void *dlsym (void *handle, char *symbol);
|
void *dlsym(void *handle, char *symbol);
|
||||||
|
|
||||||
/* free dynamicaly-linked library */
|
/* free dynamicaly-linked library */
|
||||||
int dlclose (void *handle);
|
int dlclose(void *handle);
|
||||||
|
|
||||||
/* return a string describing last occured dl error */
|
/* return a string describing last occured dl error */
|
||||||
char *dlerror(void);
|
char *dlerror(void);
|
||||||
|
|
||||||
|
|
|
@ -1,40 +1,39 @@
|
||||||
/*
|
/*
|
||||||
This is the entry point for Python DLL(s).
|
* This is the entry point for the Python 2.3 core DLL.
|
||||||
It also provides an getenv() function that works from within DLLs.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
|
||||||
/* Make references to imported symbols to pull them from static library */
|
#define REF(s) extern void s(); void *____ref_##s = &s;
|
||||||
#define REF(s) extern void s (); void *____ref_##s = &s;
|
|
||||||
|
|
||||||
REF (Py_Main);
|
/* Make references to imported symbols to pull them from static library */
|
||||||
|
REF(Py_Main);
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
extern int _CRT_init (void);
|
extern int _CRT_init(void);
|
||||||
extern void _CRT_term (void);
|
extern void _CRT_term(void);
|
||||||
extern void __ctordtorInit (void);
|
extern void __ctordtorInit(void);
|
||||||
extern void __ctordtorTerm (void);
|
extern void __ctordtorTerm(void);
|
||||||
|
|
||||||
unsigned long _DLL_InitTerm (unsigned long mod_handle, unsigned long flag)
|
unsigned long _DLL_InitTerm(unsigned long mod_handle, unsigned long flag)
|
||||||
{
|
{
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (_CRT_init ())
|
if (_CRT_init())
|
||||||
return 0;
|
return 0;
|
||||||
__ctordtorInit ();
|
__ctordtorInit();
|
||||||
|
|
||||||
/* Ignore fatal signals */
|
/* Ignore fatal signals */
|
||||||
signal (SIGSEGV, SIG_IGN);
|
signal(SIGSEGV, SIG_IGN);
|
||||||
signal (SIGFPE, SIG_IGN);
|
signal(SIGFPE, SIG_IGN);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
__ctordtorTerm ();
|
__ctordtorTerm();
|
||||||
_CRT_term ();
|
_CRT_term();
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -94,9 +94,9 @@ is_sep(char ch) /* determine if "ch" is a separator character */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assumes 'dir' null terminated in bounds. Never writes
|
/* assumes 'dir' null terminated in bounds.
|
||||||
beyond existing terminator.
|
* Never writes beyond existing terminator.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
reduce(char *dir)
|
reduce(char *dir)
|
||||||
{
|
{
|
||||||
|
@ -113,11 +113,12 @@ exists(char *filename)
|
||||||
return stat(filename, &buf) == 0;
|
return stat(filename, &buf) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assumes 'filename' MAXPATHLEN+1 bytes long -
|
/* Is module (check for .pyc/.pyo too)
|
||||||
may extend 'filename' by one character.
|
* Assumes 'filename' MAXPATHLEN+1 bytes long -
|
||||||
*/
|
* may extend 'filename' by one character.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */
|
ismodule(char *filename)
|
||||||
{
|
{
|
||||||
if (exists(filename))
|
if (exists(filename))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -151,9 +152,9 @@ join(char *buffer, char *stuff)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gotlandmark only called by search_for_prefix, which ensures
|
/* gotlandmark only called by search_for_prefix, which ensures
|
||||||
'prefix' is null terminated in bounds. join() ensures
|
* 'prefix' is null terminated in bounds. join() ensures
|
||||||
'landmark' can not overflow prefix if too long.
|
* 'landmark' can not overflow prefix if too long.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
gotlandmark(char *landmark)
|
gotlandmark(char *landmark)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +168,8 @@ gotlandmark(char *landmark)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
|
/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
|
||||||
assumption provided by only caller, calculate_path() */
|
* assumption provided by only caller, calculate_path()
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
search_for_prefix(char *argv0_path, char *landmark)
|
search_for_prefix(char *argv0_path, char *landmark)
|
||||||
{
|
{
|
||||||
|
@ -283,13 +285,13 @@ calculate_path(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need to construct a path from the following parts.
|
/* We need to construct a path from the following parts.
|
||||||
(1) the PYTHONPATH environment variable, if set;
|
* (1) the PYTHONPATH environment variable, if set;
|
||||||
(2) the zip archive file path;
|
* (2) the zip archive file path;
|
||||||
(3) the PYTHONPATH config macro, with the leading "."
|
* (3) the PYTHONPATH config macro, with the leading "."
|
||||||
of each component replaced with pythonhome, if set;
|
* of each component replaced with pythonhome, if set;
|
||||||
(4) the directory containing the executable (argv0_path).
|
* (4) the directory containing the executable (argv0_path).
|
||||||
The length calculation calculates #3 first.
|
* The length calculation calculates #3 first.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Calculate size of return buffer */
|
/* Calculate size of return buffer */
|
||||||
if (pythonhome != NULL) {
|
if (pythonhome != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue