Commit 41d97d67 authored by Andrew MacIntyre's avatar Andrew MacIntyre

Create and populate OS/2 EMX port build directory:

  PC/os2emx/
    Makefile
    README.os2emx
    config.c
    dlfcn.c            // libdl emulation code for loadable extensions
    dlfcn.h
    dllentry.c         // DLL initialisation routine for Python DLL
    getpath.c
    pyconfig.h
    python23.def       // Python DLL symbol export definitions
    pythonpm.c         // console-less PM interpreter wrapper
parent 18e6778b
This diff is collapsed.
This diff is collapsed.
/* -*- C -*- ***********************************************
Copyright 1991-1995 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 or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI 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.
******************************************************************/
/* Module configuration */
/* This file contains the table of built-in modules.
See init_builtin() in import.c. */
#include "Python.h"
extern void init_codecs();
extern void init_curses();
extern void init_curses_panel();
extern void init_hotshot();
extern void init_locale();
extern void init_socket();
extern void init_sre();
extern void init_testcapi();
extern void init_weakref();
extern void initarray();
extern void initbinascii();
extern void initbsddb();
extern void initcPickle();
extern void initcStringIO();
extern void initcmath();
extern void initdl();
extern void initerrno();
extern void initfcntl();
extern void initfpectl();
extern void initfpetest();
extern void initgc();
extern void initimageop();
extern void initmath();
extern void initmd5();
extern void initnew();
extern void initos2();
extern void initoperator();
extern void initparser();
extern void initpcre();
extern void initpwd();
extern void initregex();
extern void initrgbimg();
extern void initrotor();
extern void initselect();
extern void initsha();
extern void initsignal();
extern void initstrop();
extern void initstruct();
extern void inittermios();
extern void initthread();
extern void inittime();
extern void inittiming();
extern void initunicodedata();
extern void initxreadlines();
extern void initzlib();
/* -- ADDMODULE MARKER 1 -- */
extern void PyMarshal_Init();
extern void initimp();
struct _inittab _PyImport_Inittab[] = {
{"gc", initgc},
{"os2", initos2},
{"_sre", init_sre},
{"signal", initsignal},
#ifdef WITH_THREAD
{"thread", initthread},
#endif
#if !HAVE_DYNAMIC_LOADING
{"_codecs", init_codecs},
{"_curses", init_curses},
{"_curses_panel", init_curses_panel},
{"_hotshot", init_hotshot},
{"_locale", init_locale},
{"_testcapi", init_testcapi},
{"_weakref", init_weakref},
{"array", initarray},
{"binascii", initbinascii},
{"bsddb", initbsddb},
{"cPickle", initcPickle},
{"cStringIO", initcStringIO},
{"cmath", initcmath},
{"dl", initdl},
{"errno", initerrno},
{"fcntl", initfcntl},
{"fpectl", initfpectl},
{"fpetest", initfpetest},
{"imageop", initimageop},
{"math", initmath},
{"md5", initmd5},
{"new", initnew},
{"operator", initoperator},
{"parser", initparser},
{"pcre", initpcre},
{"pwd", initpwd},
{"regex", initregex},
{"rgbimg", initrgbimg},
{"rotor", initrotor},
{"sha", initsha},
{"strop", initstrop},
{"struct", initstruct},
{"termios", inittermios},
{"time", inittime},
{"timing", inittiming},
{"unicodedata", initunicodedata},
{"xreadlines", initxreadlines},
{"zlib", initzlib},
#ifdef USE_SOCKET
{"_socket", init_socket},
{"select", initselect},
#endif
#endif
/* -- ADDMODULE MARKER 2 -- */
/* This module "lives in" with marshal.c */
{"marshal", PyMarshal_Init},
/* This lives it with import.c */
{"imp", initimp},
/* These entries are here for sys.builtin_module_names */
{"__main__", NULL},
{"__builtin__", NULL},
{"sys", NULL},
{"exceptions", NULL},
/* Sentinel */
{0, 0}
};
/* -*- C -*- ***********************************************
Copyright 1991-1995 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 or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI 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.
******************************************************************/
/*
This library implements dlopen() - functions for OS/2 using
DosLoadModule() and company.
*/
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_DOSSESMGR
#define INCL_WINPROGRAMLIST
#define INCL_WINFRAMEMGR
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
/*-------------------------------------- Unix-like dynamic linking emulation -*/
typedef struct _track_rec {
char *name;
HMODULE handle;
void *id;
struct _track_rec *next;
} tDLLchain, *DLLchain;
static DLLchain dlload = NULL; /* A simple chained list of DLL names */
static char dlerr [256]; /* last error text string */
static void *last_id;
static DLLchain find_id(void *id)
{
DLLchain tmp;
for (tmp = dlload; tmp; tmp = tmp->next)
if (id == tmp->id)
return (tmp);
return (NULL);
}
/* load a dynamic-link library and return handle */
void *dlopen (char *filename, int flags)
{
HMODULE hm;
DLLchain tmp;
char err[256];
char *errtxt;
int rc = 0, set_chain = 0;
for (tmp = dlload; tmp; tmp = tmp->next)
if (strnicmp(tmp->name, filename, 999) == 0)
break;
if (!tmp)
{
tmp = (DLLchain)malloc (sizeof (tDLLchain));
if (!tmp)
goto nomem;
tmp->name = strdup (filename);
tmp->next = dlload;
set_chain = 1;
}
switch (rc = DosLoadModule((PSZ)&err, sizeof(err), filename, &hm))
{
case NO_ERROR:
tmp->handle = hm;
if (set_chain) {
do {
last_id++;
} while ((last_id == 0) || (find_id(last_id)));
tmp->id = last_id;
dlload = tmp;
}
return (tmp->id);
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
errtxt = "module `%s' not found";
break;
case ERROR_TOO_MANY_OPEN_FILES:
case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_SHARING_BUFFER_EXCEEDED:
nomem:
errtxt = "out of system resources";
break;
case ERROR_ACCESS_DENIED:
errtxt = "access denied";
break;
case ERROR_BAD_FORMAT:
case ERROR_INVALID_SEGMENT_NUMBER:
case ERROR_INVALID_ORDINAL:
case ERROR_INVALID_MODULETYPE:
case ERROR_INVALID_EXE_SIGNATURE:
case ERROR_EXE_MARKED_INVALID:
case ERROR_ITERATED_DATA_EXCEEDS_64K:
case ERROR_INVALID_MINALLOCSIZE:
case ERROR_INVALID_SEGDPL:
case ERROR_AUTODATASEG_EXCEEDS_64K:
case ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT:
errtxt = "invalid module format";
break;
case ERROR_INVALID_NAME:
errtxt = "filename doesn't match module name";
break;
case ERROR_SHARING_VIOLATION:
case ERROR_LOCK_VIOLATION:
errtxt = "sharing violation";
break;
case ERROR_INIT_ROUTINE_FAILED:
errtxt = "module initialization failed";
break;
default:
errtxt = "cause `%s', error code = %d";
break;
}
snprintf (dlerr, sizeof (dlerr), errtxt, &err, rc);
if (tmp) {
if (tmp->name)
free(tmp->name);
free (tmp);
}
return (0);
}
/* return a pointer to the `symbol' in DLL */
void *dlsym (void *handle, char *symbol)
{
int rc = 0;
PFN addr;
char *errtxt;
int symord = 0;
DLLchain tmp = find_id (handle);
if (!tmp)
goto inv_handle;
if (*symbol == '#')
symord = atoi (symbol + 1);
switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
{
case NO_ERROR:
return ((void *)addr);
case ERROR_INVALID_HANDLE:
inv_handle:
errtxt = "invalid module handle";
break;
case ERROR_PROC_NOT_FOUND:
case ERROR_INVALID_NAME:
errtxt = "no symbol `%s' in module";
break;
default:
errtxt = "symbol `%s', error code = %d";
break;
}
snprintf (dlerr, sizeof (dlerr), errtxt, symbol, rc);
return (NULL);
}
/* free dynamicaly-linked library */
int dlclose (void *handle)
{
int rc;
DLLchain tmp = find_id (handle);
if (!tmp)
goto inv_handle;
switch (rc = DosFreeModule (tmp->handle))
{
case NO_ERROR:
free (tmp->name);
dlload = tmp->next;
free (tmp);
return (0);
case ERROR_INVALID_HANDLE:
inv_handle:
strcpy(dlerr, "invalid module handle");
return (-1);
case ERROR_INVALID_ACCESS:
strcpy (dlerr, "access denied");
return (-1);
default:
return (-1);
}
}
/* return a string describing last occured dl error */
char *dlerror()
{
return (dlerr);
}
/* -*- C -*- ***********************************************
Copyright 1991-1995 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 or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI 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.
******************************************************************/
/*
This library implements dlopen() - functions for OS/2 using
DosLoadModule() and company.
*/
#ifndef _DLFCN_H
#define _DLFCN_H
/*-------------------------------------- Unix-like dynamic linking emulation -*/
/* load a dynamic-link library and return handle */
void *dlopen (char *filename, int flags);
/* return a pointer to the `symbol' in DLL */
void *dlsym (void *handle, char *symbol);
/* free dynamicaly-linked library */
int dlclose (void *handle);
/* return a string describing last occured dl error */
char *dlerror(void);
#endif /* !_DLFCN_H */
/*
This is the entry point for Python DLL(s).
It also provides an getenv() function that works from within DLLs.
*/
#define NULL 0
/* Make references to imported symbols to pull them from static library */
#define REF(s) extern void s (); void *____ref_##s = &s;
REF (Py_Main);
#if defined (__EMX__)
#include <signal.h>
extern int _CRT_init (void);
extern void _CRT_term (void);
extern void __ctordtorInit (void);
extern void __ctordtorTerm (void);
unsigned long _DLL_InitTerm (unsigned long mod_handle, unsigned long flag)
{
switch (flag)
{
case 0:
if (_CRT_init ()) return 0;
__ctordtorInit ();
/* Ignore fatal signals */
signal (SIGSEGV, SIG_IGN);
signal (SIGFPE, SIG_IGN);
return 1;
case 1:
__ctordtorTerm ();
_CRT_term ();
return 1;
default:
return 0;
}
}
#endif
/* A version of getenv() that works from DLLs */
extern int DosScanEnv (const char *pszName, char **ppszValue);
char *getenv (const char *name)
{
char *value;
if (DosScanEnv (name, &value))
return NULL;
else
return value;
}
/* Return the initial module search path. */
/* This version used by OS/2+EMX */
/* ----------------------------------------------------------------
PATH RULES FOR OS/2+EMX:
This describes how sys.path is formed on OS/2+EMX. It describes the
functionality, not the implementation (ie, the order in which these
are actually fetched is different)
* Python always adds an empty entry at the start, which corresponds
to the current directory.
* If the PYTHONPATH env. var. exists, it's entries are added next.
* We attempt to locate the "Python Home" - if the PYTHONHOME env var
is set, we believe it. Otherwise, we use the path of our host .EXE's
to try and locate our "landmark" (lib\\os.py) and deduce our home.
- If we DO have a Python Home: The relevant sub-directories (Lib,
plat-win, lib-tk, etc) are based on the Python Home
- If we DO NOT have a Python Home, the core Python Path is
loaded from the registry. This is the main PythonPath key,
and both HKLM and HKCU are combined to form the path)
* Iff - we can not locate the Python Home, and have not had a PYTHONPATH
specified (ie, we have _nothing_ we can assume is a good path), a
default path with relative entries is used (eg. .\Lib;.\plat-win, etc)
The end result of all this is:
* When running python.exe, or any other .exe in the main Python directory
(either an installed version, or directly from the PCbuild directory),
the core path is deduced.
* When Python is hosted in another exe (different directory, embedded via
COM, etc), the Python Home will not be deduced, so the core path from
the registry is used. Other "application paths "in the registry are
always read.
* If Python can't find its home and there is no registry (eg, frozen
exe, some very strange installation setup) you get a path with
some default, but relative, paths.
---------------------------------------------------------------- */
#include "Python.h"
#include "osdefs.h"
#ifndef PYOS_OS2
#error This file only compilable on OS/2
#endif
#define INCL_DOS
#include <os2.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
/* Search in some common locations for the associated Python libraries.
*
* Py_GetPath() tries to return a sensible Python module search path.
*
* The approach is an adaptation for Windows of the strategy used in
* ../Modules/getpath.c; it uses the Windows Registry as one of its
* information sources.
*/
#ifndef LANDMARK
#if defined(PYCC_GCC)
#define LANDMARK "lib/os.py"
#else
#define LANDMARK "lib\\os.py"
#endif
#endif
static char prefix[MAXPATHLEN+1];
static char progpath[MAXPATHLEN+1];
static char *module_search_path = NULL;
static int
is_sep(char ch) /* determine if "ch" is a separator character */
{
#ifdef ALTSEP
return ch == SEP || ch == ALTSEP;
#else
return ch == SEP;
#endif
}
/* assumes 'dir' null terminated in bounds. Never writes
beyond existing terminator.
*/
static void
reduce(char *dir)
{
size_t i = strlen(dir);
while (i > 0 && !is_sep(dir[i]))
--i;
dir[i] = '\0';
}
static int
exists(char *filename)
{
struct stat buf;
return stat(filename, &buf) == 0;
}
/* Assumes 'filename' MAXPATHLEN+1 bytes long -
may extend 'filename' by one character.
*/
static int
ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */
{
if (exists(filename))
return 1;
/* Check for the compiled version of prefix. */
if (strlen(filename) < MAXPATHLEN) {
strcat(filename, Py_OptimizeFlag ? "o" : "c");
if (exists(filename))
return 1;
}
return 0;
}
/* guarantees buffer will never overflow MAXPATHLEN+1 bytes */
static void
join(char *buffer, char *stuff)
{
size_t n, k;
if (is_sep(stuff[0]))
n = 0;
else {
n = strlen(buffer);
if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
buffer[n++] = SEP;
}
k = strlen(stuff);
if (n + k > MAXPATHLEN)
k = MAXPATHLEN - n;
strncpy(buffer+n, stuff, k);
buffer[n+k] = '\0';
}
/* gotlandmark only called by search_for_prefix, which ensures
'prefix' is null terminated in bounds. join() ensures
'landmark' can not overflow prefix if too long.
*/
static int
gotlandmark(char *landmark)
{
int n, ok;
n = strlen(prefix);
join(prefix, landmark);
ok = ismodule(prefix);
prefix[n] = '\0';
return ok;
}
/* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd.
assumption provided by only caller, calculate_path() */
static int
search_for_prefix(char *argv0_path, char *landmark)
{
/* Search from argv0_path, until landmark is found */
strcpy(prefix, argv0_path);
do {
if (gotlandmark(landmark))
return 1;
reduce(prefix);
} while (prefix[0]);
return 0;
}
static void
get_progpath(void)
{
extern char *Py_GetProgramName(void);
char *path = getenv("PATH");
char *prog = Py_GetProgramName();
PPIB pib;
if ((DosGetInfoBlocks(NULL, &pib) == 0) &&
(DosQueryModuleName(pib->pib_hmte, sizeof(progpath), progpath) == 0))
return;
if (prog == NULL || *prog == '\0')
prog = "python";
/* If there is no slash in the argv0 path, then we have to
* assume python is on the user's $PATH, since there's no
* other way to find a directory to start the search from. If
* $PATH isn't exported, you lose.
*/
#ifdef ALTSEP
if (strchr(prog, SEP) || strchr(prog, ALTSEP))
#else
if (strchr(prog, SEP))
#endif
strncpy(progpath, prog, MAXPATHLEN);
else if (path) {
while (1) {
char *delim = strchr(path, DELIM);
if (delim) {
size_t len = delim - path;
/* ensure we can't overwrite buffer */
#if !defined(PYCC_GCC)
len = min(MAXPATHLEN,len);
#else
len = MAXPATHLEN < len ? MAXPATHLEN : len;
#endif
strncpy(progpath, path, len);
*(progpath + len) = '\0';
}
else
strncpy(progpath, path, MAXPATHLEN);
/* join() is safe for MAXPATHLEN+1 size buffer */
join(progpath, prog);
if (exists(progpath))
break;
if (!delim) {
progpath[0] = '\0';
break;
}
path = delim + 1;
}
}
else
progpath[0] = '\0';
}
static void
calculate_path(void)
{
char argv0_path[MAXPATHLEN+1];
char *buf;
size_t bufsz;
char *pythonhome = Py_GetPythonHome();
char *envpath = getenv("PYTHONPATH");
get_progpath();
/* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
strcpy(argv0_path, progpath);
reduce(argv0_path);
if (pythonhome == NULL || *pythonhome == '\0') {
if (search_for_prefix(argv0_path, LANDMARK))
pythonhome = prefix;
else
pythonhome = NULL;
}
else
strncpy(prefix, pythonhome, MAXPATHLEN);
if (envpath && *envpath == '\0')
envpath = NULL;
/* We need to construct a path from the following parts.
(1) the PYTHONPATH environment variable, if set;
(2) the PYTHONPATH config macro, with the leading "."
of each component replaced with pythonhome, if set;
(3) the directory containing the executable (argv0_path).
The length calculation calculates #2 first.
*/
/* Calculate size of return buffer */
if (pythonhome != NULL) {
char *p;
bufsz = 1;
for (p = PYTHONPATH; *p; p++) {
if (*p == DELIM)
bufsz++; /* number of DELIM plus one */
}
bufsz *= strlen(pythonhome);
}
else
bufsz = 0;
bufsz += strlen(PYTHONPATH) + 1;
bufsz += strlen(argv0_path) + 1;
if (envpath != NULL)
bufsz += strlen(envpath) + 1;
module_search_path = buf = malloc(bufsz);
if (buf == NULL) {
/* We can't exit, so print a warning and limp along */
fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
if (envpath) {
fprintf(stderr, "Using environment $PYTHONPATH.\n");
module_search_path = envpath;
}
else {
fprintf(stderr, "Using default static path.\n");
module_search_path = PYTHONPATH;
}
return;
}
if (envpath) {
strcpy(buf, envpath);
buf = strchr(buf, '\0');
*buf++ = DELIM;
}
if (pythonhome == NULL) {
strcpy(buf, PYTHONPATH);
buf = strchr(buf, '\0');
}
else {
char *p = PYTHONPATH;
char *q;
size_t n;
for (;;) {
q = strchr(p, DELIM);
if (q == NULL)
n = strlen(p);
else
n = q-p;
if (p[0] == '.' && is_sep(p[1])) {
strcpy(buf, pythonhome);
buf = strchr(buf, '\0');
p++;
n--;
}
strncpy(buf, p, n);
buf += n;
if (q == NULL)
break;
*buf++ = DELIM;
p = q+1;
}
}
if (argv0_path) {
*buf++ = DELIM;
strcpy(buf, argv0_path);
buf = strchr(buf, '\0');
}
*buf = '\0';
}
/* External interface */
char *
Py_GetPath(void)
{
if (!module_search_path)
calculate_path();
return module_search_path;
}
char *
Py_GetPrefix(void)
{
if (!module_search_path)
calculate_path();
return prefix;
}
char *
Py_GetExecPrefix(void)
{
return Py_GetPrefix();
}
char *
Py_GetProgramFullPath(void)
{
if (!module_search_path)
calculate_path();
return progpath;
}
#ifndef Py_CONFIG_H
#define Py_CONFIG_H
/*
config.h.
At some time in the past, generated automatically by configure.
Maintained manually for better results.
*/
#define PLATFORM "os2emx"
#define COMPILER "[EMX GCC " __VERSION__ "]"
#define PYOS_OS2
#define PYCC_GCC
#define PREFIX "/usr"
/* Debugging */
#ifndef Py_DEBUG
/*#define Py_DEBUG 1*/
#endif
/* so that emx socket headers will define IP V4 socket types */
#define TCPIPV4
/* Use OS/2 flavour of threads */
#define WITH_THREAD
#define OS2_THREADS
/* We want sockets */
#define USE_SOCKET
#define socklen_t int
/* enable the GC module */
#define WITH_CYCLE_GC 1
/* Unicode related */
#define Py_USING_UNICODE
#define PY_UNICODE_TYPE wchar_t
#define Py_UNICODE_SIZE SIZEOF_SHORT
/* enable the Python object allocator */
/*#define WITH_PYMALLOC 1*/
#define PYTHONPATH ".;./Lib;./Lib/plat-" PLATFORM ";./Lib/lib-dynload;./Lib/site-packages"
#define HAVE_TTYNAME 1
#define HAVE_WAIT 1
#define HAVE_GETEGID 1
#define HAVE_GETEUID 1
#define HAVE_GETGID 1
#define HAVE_GETPPID 1
#define HAVE_GETUID 1
#define HAVE_OPENDIR 1
#define HAVE_PIPE 1
#define HAVE_POPEN 1
#define HAVE_SYSTEM 1
#define HAVE_TTYNAME 1
#define HAVE_DYNAMIC_LOADING 1
/* if port of GDBM installed, it includes NDBM emulation */
#define HAVE_NDBM_H 1
/* need this for spawnv code in posixmodule (cloned from WIN32 def'n) */
typedef long intptr_t;
/* we don't have tm_zone but do have the external array
tzname. */
#define HAVE_TZNAME 1
/* Define as the return type of signal handlers (int or void). */
#define RETSIGTYPE void
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Used for BeOS configuration */
/* #undef DL_EXPORT_HEADER */
#ifdef DL_EXPORT_HEADER
#include DL_EXPORT_HEADER
#endif
/* Define this if you have the type long long */
#define HAVE_LONG_LONG 1
/* Define if your compiler supports function prototypes */
#define HAVE_PROTOTYPES 1
/* Define if your compiler supports variable length function prototypes
(e.g. void fprintf(FILE *, char *, ...);) *and* <stdarg.h> */
#define HAVE_STDARG_PROTOTYPES 1
/* Define if malloc(0) returns a NULL pointer */
#define MALLOC_ZERO_RETURNS_NULL 1
/* Define to force use of thread-safe errno, h_errno, and other functions */
#define _REENTRANT 1
/* Define if you can safely include both <sys/select.h> and <sys/time.h>
(which you can't on SCO ODT 3.0). */
#define SYS_SELECT_WITH_SYS_TIME 1
/* The number of bytes in an off_t. */
#define SIZEOF_OFF_T 4
/* The number of bytes in an time_t. */
#define SIZEOF_TIME_T 4
/* The number of bytes in a short. */
#define SIZEOF_SHORT 2
/* The number of bytes in a int. */
#define SIZEOF_INT 4
/* The number of bytes in a long. */
#define SIZEOF_LONG 4
/* The number of bytes in a long long. */
#define SIZEOF_LONG_LONG 8
/* The number of bytes in a void *. */
#define SIZEOF_VOID_P 4
/* Define if you have the alarm function. */
#define HAVE_ALARM 1
/* Define if you have the clock function. */
#define HAVE_CLOCK 1
/* Define if you have the dup2 function. */
#define HAVE_DUP2 1
/* Define if you have the execv function. */
#define HAVE_EXECV 1
/* Define if you have the spawnv function. */
#define HAVE_SPAWNV 1
/* Define if you have the flock function. */
#define HAVE_FLOCK 1
/* Define if you have the fork function. */
#define HAVE_FORK 1
/* Define if you have the fsync function. */
#define HAVE_FSYNC 1
/* Define if you have the ftime function. */
#define HAVE_FTIME 1
/* Define if you have the ftruncate function. */
#define HAVE_FTRUNCATE 1
/* Define if you have the getcwd function. */
#define HAVE_GETCWD 1
/* Define if you have the getpeername function. */
#define HAVE_GETPEERNAME 1
/* Define if you have the getpgrp function. */
#define HAVE_GETPGRP 1
/* Define if you have the getpid function. */
#define HAVE_GETPID 1
/* Define if you have the getpwent function. */
#define HAVE_GETPWENT 1
/* Define if you have the gettimeofday function. */
#define HAVE_GETTIMEOFDAY 1
/* Define if you have the getwd function. */
#define HAVE_GETWD 1
/* Define if you have the hypot function. */
#define HAVE_HYPOT 1
/* Define if you have the kill function. */
#define HAVE_KILL 1
/* Define if you have the memmove function. */
#define HAVE_MEMMOVE 1
/* Define if you have the mktime function. */
#define HAVE_MKTIME 1
/* Define if you have the pause function. */
#define HAVE_PAUSE 1
/* Define if you have the putenv function. */
#define HAVE_PUTENV 1
/* Define if you have the select function. */
#define HAVE_SELECT 1
/* Define if you have the setgid function. */
#define HAVE_SETGID 1
/* Define if you have the setlocale function. */
#define HAVE_SETLOCALE 1
/* Define if you have the setpgid function. */
#define HAVE_SETPGID 1
/* Define if you have the setuid function. */
#define HAVE_SETUID 1
/* Define if you have the setvbuf function. */
#define HAVE_SETVBUF 1
/* Define if you have the sigaction function. */
#define HAVE_SIGACTION 1
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define if you have the strerror function. */
#define HAVE_STRERROR 1
/* Define if you have the strftime function. */
#define HAVE_STRFTIME 1
/* Define if you have the strptime function. */
#define HAVE_STRPTIME 1
/* Define if you have the tcgetpgrp function. */
#define HAVE_TCGETPGRP 1
/* Define if you have the tcsetpgrp function. */
#define HAVE_TCSETPGRP 1
/* Define if you have the times function. */
#define HAVE_TIMES 1
/* Define if you have the truncate function. */
#define HAVE_TRUNCATE 1
/* Define if you have the uname function. */
#define HAVE_UNAME 1
/* Define if you have the waitpid function. */
#define HAVE_WAITPID 1
/* Define if you have the <dirent.h> header file. */
#define HAVE_DIRENT_H 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
/* Define if you have the <ncurses.h> header file. */
#define HAVE_NCURSES_H 1
/* Define if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define if you have the <sys/file.h> header file. */
#define HAVE_SYS_FILE_H 1
/* Define if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/times.h> header file. */
#define HAVE_SYS_TIMES_H 1
/* Define if you have the <sys/un.h> header file. */
#define HAVE_SYS_UN_H 1
/* Define if you have the <sys/utsname.h> header file. */
#define HAVE_SYS_UTSNAME_H 1
/* Define if you have the <sys/wait.h> header file. */
#define HAVE_SYS_WAIT_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define if you have the <utime.h> header file. */
#define HAVE_UTIME_H 1
/* EMX has an snprintf() */
#define HAVE_SNPRINTF
#endif /* !Py_CONFIG_H */
This diff is collapsed.
/* OS/2 PM main program - creates a hidden window, and starts Python
* interpreter in a separate thread, so that Python scripts can be
* run in PM process space without a console Window. The interpreter
* is incorporated by linking in the Python DLL.
*
* As it stands, I don't think this is adequate for supporting Python
* GUI modules, as the Python thread doesn't have its own message
* queue - which is required of threads that want to create/use
* PM windows.
*
* This code owes a lot to "OS/2 Presentation Manager Programming", by
* Charles Petzold.
*
* Andrew MacIntyre <andymac@bullseye.apana.org.au>, August 2001.
* Released under the terms of the Python 2.1.1 licence - see the LICENCE
* file in the Python v2.1.1 (or later) source distribution.
* Copyright assigned to the Python Software Foundation, 2001.
*/
#define INCL_DOS
#define INCL_WIN
#include <os2.h>
#include <process.h>
#include "Python.h"
/* use structure to pass command line to Python thread */
typedef struct
{
int argc;
char **argv;
HWND Frame;
int running;
} arglist;
/* make this a global to simplify access.
* it should only be set from the Python thread, or by the code that
* initiates the Python thread when the thread cannot be created.
*/
int PythonRC;
extern DL_EXPORT(int) Py_Main(int, char **);
void PythonThread(void *);
int
main(int argc, char **argv)
{
ULONG FrameFlags = FCF_TITLEBAR |
FCF_SYSMENU |
FCF_SIZEBORDER |
FCF_HIDEBUTTON |
FCF_SHELLPOSITION |
FCF_TASKLIST;
HAB hab;
HMQ hmq;
HWND Client;
QMSG qmsg;
arglist args;
int python_tid;
/* init PM and create message queue */
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
/* create a (hidden) Window to house the window procedure */
args.Frame = WinCreateStdWindow(HWND_DESKTOP,
0,
&FrameFlags,
NULL,
"PythonPM",
0L,
0,
0,
&Client);
/* run Python interpreter in a thread */
args.argc = argc;
args.argv = argv;
args.running = 0;
if (-1 == (python_tid = _beginthread(PythonThread, NULL, 1024 * 1024, &args)))
{
/* couldn't start thread */
WinAlarm(HWND_DESKTOP, WA_ERROR);
PythonRC = 1;
}
else
{
/* process PM messages, until Python exits */
while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
WinDispatchMsg(hab, &qmsg);
if (args.running > 0)
DosKillThread(python_tid);
}
/* destroy window, shutdown message queue and PM */
WinDestroyWindow(args.Frame);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return PythonRC;
}
void PythonThread(void *argl)
{
HAB hab;
arglist *args;
/* PM initialisation */
hab = WinInitialize(0);
/* start Python */
args = (arglist *)argl;
args->running = 1;
PythonRC = Py_Main(args->argc, args->argv);
/* enter a critical section and send the termination message */
DosEnterCritSec();
args->running = 0;
WinPostMsg(args->Frame, WM_QUIT, NULL, NULL);
/* shutdown PM and terminate thread */
WinTerminate(hab);
_endthread();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment