Quickly renamed the remaining files -- this directory is done.

This commit is contained in:
Guido van Rossum 1997-04-29 20:08:16 +00:00
parent 65bf9f265e
commit 79f25d9a7b
10 changed files with 1832 additions and 1746 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -36,37 +36,38 @@ PERFORMANCE OF THIS SOFTWARE.
XXX Python source (or in an extension) uses ridiculously long names
XXX or riduculously deep nesting in format strings. */
#include "allobjects.h"
#include "Python.h"
#include <ctype.h>
int getargs PROTO((object *, char *, ...));
int newgetargs PROTO((object *, char *, ...));
int vgetargs PROTO((object *, char *, va_list));
int PyArg_Parse Py_PROTO((PyObject *, char *, ...));
int PyArg_ParseTuple Py_PROTO((PyObject *, char *, ...));
int PyArgs_VaParse Py_PROTO((PyObject *, char *, va_list));
int PyArg_ParseTupleAndKeywords PROTO((object *, object *,
int PyArg_ParseTupleAndKeywords Py_PROTO((PyObject *, PyObject *,
char *, char **, ...));
/* Forward */
static int vgetargs1 PROTO((object *, char *, va_list *, int));
static void seterror PROTO((int, char *, int *, char *, char *));
static char *convertitem PROTO((object *, char **, va_list *, int *, char *));
static char *converttuple PROTO((object *, char **, va_list *,
static int vgetargs1 Py_PROTO((PyObject *, char *, va_list *, int));
static void seterror Py_PROTO((int, char *, int *, char *, char *));
static char *convertitem Py_PROTO((PyObject *, char **, va_list *,
int *, char *));
static char *converttuple Py_PROTO((PyObject *, char **, va_list *,
int *, char *, int));
static char *convertsimple PROTO((object *, char **, va_list *, char *));
static char *convertsimple1 PROTO((object *, char **, va_list *));
static char *convertsimple Py_PROTO((PyObject *, char **, va_list *, char *));
static char *convertsimple1 Py_PROTO((PyObject *, char **, va_list *));
static int vgetargskeywords PROTO((object *, object *,
static int vgetargskeywords Py_PROTO((PyObject *, PyObject *,
char *, char **, va_list *));
static char *skipitem PROTO((char **, va_list *));
static char *skipitem Py_PROTO((char **, va_list *));
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */
int getargs(object *args, char *format, ...)
int PyArg_Parse(PyObject *args, char *format, ...)
#else
/* VARARGS */
int getargs(va_alist) va_dcl
int PyArg_Parse(va_alist) va_dcl
#endif
{
int retval;
@ -75,11 +76,11 @@ int getargs(va_alist) va_dcl
va_start(va, format);
#else
object *args;
PyObject *args;
char *format;
va_start(va);
args = va_arg(va, object *);
args = va_arg(va, PyObject *);
format = va_arg(va, char *);
#endif
retval = vgetargs1(args, format, &va, 1);
@ -90,10 +91,10 @@ int getargs(va_alist) va_dcl
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */
int newgetargs(object *args, char *format, ...)
int PyArg_ParseTuple(PyObject *args, char *format, ...)
#else
/* VARARGS */
int newgetargs(va_alist) va_dcl
int PyArg_ParseTuple(va_alist) va_dcl
#endif
{
int retval;
@ -102,11 +103,11 @@ int newgetargs(va_alist) va_dcl
va_start(va, format);
#else
object *args;
PyObject *args;
char *format;
va_start(va);
args = va_arg(va, object *);
args = va_arg(va, PyObject *);
format = va_arg(va, char *);
#endif
retval = vgetargs1(args, format, &va, 0);
@ -116,8 +117,8 @@ int newgetargs(va_alist) va_dcl
int
vgetargs(args, format, va)
object *args;
PyArgs_VaParse(args, format, va)
PyObject *args;
char *format;
va_list va;
{
@ -135,7 +136,7 @@ vgetargs(args, format, va)
static int
vgetargs1(args, format, p_va, compat)
object *args;
PyObject *args;
char *format;
va_list *p_va;
int compat;
@ -160,7 +161,7 @@ vgetargs1(args, format, p_va, compat)
}
else if (/* '(' */ c == ')') {
if (level == 0)
fatal(/* '(' */
Py_FatalError(/* '(' */
"excess ')' in getargs format");
else
level--;
@ -184,7 +185,7 @@ vgetargs1(args, format, p_va, compat)
}
if (level != 0)
fatal(/* '(' */ "missing ')' in getargs format");
Py_FatalError(/* '(' */ "missing ')' in getargs format");
if (min < 0)
min = max;
@ -197,7 +198,7 @@ vgetargs1(args, format, p_va, compat)
return 1;
sprintf(msgbuf, "%s requires no arguments",
fname==NULL ? "function" : fname);
err_setstr(TypeError, msgbuf);
PyErr_SetString(PyExc_TypeError, msgbuf);
return 0;
}
else if (min == 1 && max == 1) {
@ -205,7 +206,7 @@ vgetargs1(args, format, p_va, compat)
sprintf(msgbuf,
"%s requires at least one argument",
fname==NULL ? "function" : fname);
err_setstr(TypeError, msgbuf);
PyErr_SetString(PyExc_TypeError, msgbuf);
return 0;
}
msg = convertitem(args, &format, p_va, levels, msgbuf);
@ -215,19 +216,19 @@ vgetargs1(args, format, p_va, compat)
return 0;
}
else {
err_setstr(SystemError,
PyErr_SetString(PyExc_SystemError,
"old style getargs format uses new features");
return 0;
}
}
if (!is_tupleobject(args)) {
err_setstr(SystemError,
if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_SystemError,
"new style getargs format but argument is not a tuple");
return 0;
}
len = gettuplesize(args);
len = PyTuple_Size(args);
if (len < min || max < len) {
if (message == NULL) {
@ -241,14 +242,14 @@ vgetargs1(args, format, p_va, compat)
len);
message = msgbuf;
}
err_setstr(TypeError, message);
PyErr_SetString(PyExc_TypeError, message);
return 0;
}
for (i = 0; i < len; i++) {
if (*format == '|')
format++;
msg = convertitem(gettupleitem(args, i), &format, p_va,
msg = convertitem(PyTuple_GetItem(args, i), &format, p_va,
levels, msgbuf);
if (msg) {
seterror(i+1, msg, levels, fname, message);
@ -273,7 +274,7 @@ seterror(iarg, msg, levels, fname, message)
int i;
char *p = buf;
if (err_occurred())
if (PyErr_Occurred())
return;
if (iarg == 0 && message == NULL)
message = msg;
@ -293,7 +294,7 @@ seterror(iarg, msg, levels, fname, message)
sprintf(p, ": expected %s found", msg);
message = buf;
}
err_setstr(TypeError, message);
PyErr_SetString(PyExc_TypeError, message);
}
@ -318,7 +319,7 @@ seterror(iarg, msg, levels, fname, message)
static char *
converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
object *arg;
PyObject *arg;
char **p_format;
va_list *p_va;
int *levels;
@ -348,15 +349,15 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
n++;
}
if (!is_tupleobject(arg)) {
if (!PyTuple_Check(arg)) {
levels[0] = 0;
sprintf(msgbuf,
toplevel ? "%d arguments, %s" : "%d-tuple, %s",
n, arg == None ? "None" : arg->ob_type->tp_name);
n, arg == Py_None ? "None" : arg->ob_type->tp_name);
return msgbuf;
}
if ((i = gettuplesize(arg)) != n) {
if ((i = PyTuple_Size(arg)) != n) {
levels[0] = 0;
sprintf(msgbuf,
toplevel ? "%d arguments, %d" : "%d-tuple, %d-tuple",
@ -367,7 +368,7 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
format = *p_format;
for (i = 0; i < n; i++) {
char *msg;
msg = convertitem(gettupleitem(arg, i), &format, p_va,
msg = convertitem(PyTuple_GetItem(arg, i), &format, p_va,
levels+1, msgbuf);
if (msg != NULL) {
levels[0] = i+1;
@ -384,7 +385,7 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
static char *
convertitem(arg, p_format, p_va, levels, msgbuf)
object *arg;
PyObject *arg;
char **p_format;
va_list *p_va;
int *levels;
@ -415,7 +416,7 @@ convertitem(arg, p_format, p_va, levels, msgbuf)
static char *
convertsimple(arg, p_format, p_va, msgbuf)
object *arg;
PyObject *arg;
char **p_format;
va_list *p_va;
char *msgbuf;
@ -423,7 +424,7 @@ convertsimple(arg, p_format, p_va, msgbuf)
char *msg = convertsimple1(arg, p_format, p_va);
if (msg != NULL) {
sprintf(msgbuf, "%.50s, %.50s", msg,
arg == None ? "None" : arg->ob_type->tp_name);
arg == Py_None ? "None" : arg->ob_type->tp_name);
msg = msgbuf;
}
return msg;
@ -437,7 +438,7 @@ convertsimple(arg, p_format, p_va, msgbuf)
static char *
convertsimple1(arg, p_format, p_va)
object *arg;
PyObject *arg;
char **p_format;
va_list *p_va;
{
@ -449,8 +450,8 @@ convertsimple1(arg, p_format, p_va)
case 'b': /* byte -- very short int */
{
char *p = va_arg(*p_va, char *);
long ival = getintvalue(arg);
if (ival == -1 && err_occurred())
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<b>";
else
*p = (char) ival;
@ -460,8 +461,8 @@ convertsimple1(arg, p_format, p_va)
case 'h': /* short int */
{
short *p = va_arg(*p_va, short *);
long ival = getintvalue(arg);
if (ival == -1 && err_occurred())
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<h>";
else
*p = (short) ival;
@ -471,8 +472,8 @@ convertsimple1(arg, p_format, p_va)
case 'i': /* int */
{
int *p = va_arg(*p_va, int *);
long ival = getintvalue(arg);
if (ival == -1 && err_occurred())
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<i>";
else
*p = ival;
@ -482,8 +483,8 @@ convertsimple1(arg, p_format, p_va)
case 'l': /* long int */
{
long *p = va_arg(*p_va, long *);
long ival = getintvalue(arg);
if (ival == -1 && err_occurred())
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<l>";
else
*p = ival;
@ -493,8 +494,8 @@ convertsimple1(arg, p_format, p_va)
case 'f': /* float */
{
float *p = va_arg(*p_va, float *);
double dval = getfloatvalue(arg);
if (err_occurred())
double dval = PyFloat_AsDouble(arg);
if (PyErr_Occurred())
return "float<f>";
else
*p = (float) dval;
@ -504,8 +505,8 @@ convertsimple1(arg, p_format, p_va)
case 'd': /* double */
{
double *p = va_arg(*p_va, double *);
double dval = getfloatvalue(arg);
if (err_occurred())
double dval = PyFloat_AsDouble(arg);
if (PyErr_Occurred())
return "float<d>";
else
*p = dval;
@ -518,7 +519,7 @@ convertsimple1(arg, p_format, p_va)
Py_complex *p = va_arg(*p_va, Py_complex *);
Py_complex cval;
cval = PyComplex_AsCComplex(arg);
if (err_occurred())
if (PyErr_Occurred())
return "complex<D>";
else
*p = cval;
@ -529,8 +530,8 @@ convertsimple1(arg, p_format, p_va)
case 'c': /* char */
{
char *p = va_arg(*p_va, char *);
if (is_stringobject(arg) && getstringsize(arg) == 1)
*p = getstringvalue(arg)[0];
if (PyString_Check(arg) && PyString_Size(arg) == 1)
*p = PyString_AsString(arg)[0];
else
return "char";
break;
@ -539,16 +540,16 @@ convertsimple1(arg, p_format, p_va)
case 's': /* string */
{
char **p = va_arg(*p_va, char **);
if (is_stringobject(arg))
*p = getstringvalue(arg);
if (PyString_Check(arg))
*p = PyString_AsString(arg);
else
return "string";
if (*format == '#') {
int *q = va_arg(*p_va, int *);
*q = getstringsize(arg);
*q = PyString_Size(arg);
format++;
}
else if ((int)strlen(*p) != getstringsize(arg))
else if ((int)strlen(*p) != PyString_Size(arg))
return "string without null bytes";
break;
}
@ -556,30 +557,30 @@ convertsimple1(arg, p_format, p_va)
case 'z': /* string, may be NULL (None) */
{
char **p = va_arg(*p_va, char **);
if (arg == None)
if (arg == Py_None)
*p = 0;
else if (is_stringobject(arg))
*p = getstringvalue(arg);
else if (PyString_Check(arg))
*p = PyString_AsString(arg);
else
return "None or string";
if (*format == '#') {
int *q = va_arg(*p_va, int *);
if (arg == None)
if (arg == Py_None)
*q = 0;
else
*q = getstringsize(arg);
*q = PyString_Size(arg);
format++;
}
else if (*p != NULL &&
(int)strlen(*p) != getstringsize(arg))
(int)strlen(*p) != PyString_Size(arg))
return "None or string without null bytes";
break;
}
case 'S': /* string object */
{
object **p = va_arg(*p_va, object **);
if (is_stringobject(arg))
PyObject **p = va_arg(*p_va, PyObject **);
if (PyString_Check(arg))
*p = arg;
else
return "string";
@ -588,15 +589,15 @@ convertsimple1(arg, p_format, p_va)
case 'O': /* object */
{
typeobject *type;
object **p;
PyTypeObject *type;
PyObject **p;
if (*format == '!') {
format++;
type = va_arg(*p_va, typeobject*);
type = va_arg(*p_va, PyTypeObject*);
if (arg->ob_type != type)
return type->tp_name;
else {
p = va_arg(*p_va, object **);
p = va_arg(*p_va, PyObject **);
*p = arg;
}
}
@ -604,13 +605,13 @@ convertsimple1(arg, p_format, p_va)
inquiry pred = va_arg(*p_va, inquiry);
format++;
if ((*pred)(arg)) {
p = va_arg(*p_va, object **);
p = va_arg(*p_va, PyObject **);
*p = arg;
}
}
else if (*format == '&') {
typedef int (*converter)
PROTO((object *, void *));
Py_PROTO((PyObject *, void *));
converter convert = va_arg(*p_va, converter);
void *addr = va_arg(*p_va, void *);
format++;
@ -618,7 +619,7 @@ convertsimple1(arg, p_format, p_va)
return "(unspecified)";
}
else {
p = va_arg(*p_va, object **);
p = va_arg(*p_va, PyObject **);
*p = arg;
}
break;
@ -639,8 +640,8 @@ convertsimple1(arg, p_format, p_va)
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */
int PyArg_ParseTupleAndKeywords(object *args,
object *keywords,
int PyArg_ParseTupleAndKeywords(PyObject *args,
PyObject *keywords,
char *format,
char **kwlist, ...)
#else
@ -654,14 +655,14 @@ int PyArg_ParseTupleAndKeywords(va_alist) va_dcl
va_start(va, kwlist);
#else
object *args;
object *keywords;
PyObject *args;
PyObject *keywords;
char *format;
char **kwlist;
va_start(va);
args = va_arg(va, object *);
keywords = va_arg(va, object *);
args = va_arg(va, PyObject *);
keywords = va_arg(va, PyObject *);
format = va_arg(va, char *);
kwlist = va_arg(va, char **);
#endif
@ -673,8 +674,8 @@ int PyArg_ParseTupleAndKeywords(va_alist) va_dcl
static int
vgetargskeywords(args, keywords, format, kwlist, p_va)
object *args;
object *keywords;
PyObject *args;
PyObject *keywords;
char *format;
char **kwlist;
va_list *p_va;
@ -689,7 +690,7 @@ vgetargskeywords(args, keywords, format, kwlist, p_va)
int i, len, tplen, kwlen;
char *msg, *ks, **p;
int nkwds, pos, match, converted;
object *key, *value;
PyObject *key, *value;
/* nested tuples cannot be parsed when using keyword arguments */
@ -830,7 +831,7 @@ vgetargskeywords(args, keywords, format, kwlist, p_va)
converted = 0;
for (i = tplen; i < nkwds; i++) {
object *item;
PyObject *item;
if (*format == '|')
format++;
item = PyMapping_GetItemString(keywords, kwlist[i]);
@ -961,7 +962,7 @@ skipitem(p_format, p_va)
case 'S': /* string object */
{
(void) va_arg(*p_va, object **);
(void) va_arg(*p_va, PyObject **);
break;
}
@ -969,8 +970,8 @@ skipitem(p_format, p_va)
{
if (*format == '!') {
format++;
(void) va_arg(*p_va, typeobject*);
(void) va_arg(*p_va, object **);
(void) va_arg(*p_va, PyTypeObject*);
(void) va_arg(*p_va, PyObject **);
}
#if 0
/* I don't know what this is for */
@ -978,19 +979,19 @@ skipitem(p_format, p_va)
inquiry pred = va_arg(*p_va, inquiry);
format++;
if ((*pred)(arg)) {
(void) va_arg(*p_va, object **);
(void) va_arg(*p_va, PyObject **);
}
}
#endif
else if (*format == '&') {
typedef int (*converter)
PROTO((object *, void *));
Py_PROTO((PyObject *, void *));
(void) va_arg(*p_va, converter);
(void) va_arg(*p_va, void *);
format++;
}
else {
(void) va_arg(*p_va, object **);
(void) va_arg(*p_va, PyObject **);
}
break;
}

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Support for dynamic loading of extension modules */
/* If no dynamic linking is supported, this file still generates some code! */
#include "allobjects.h"
#include "Python.h"
#include "osdefs.h"
#include "importdl.h"
@ -167,7 +167,7 @@ typedef void (*dl_funcptr)();
#ifdef USE_MAC_DYNAMIC_LOADING
#include <Aliases.h>
#include <CodeFragments.h>
#ifdef SYMANTEC__CFM68K__ /* Really just an older version of Universal Headers */
#ifdef SYMANTEC__CFM68K__ /* Really an older version of Universal Headers */
#define CFragConnectionID ConnectionID
#define kLoadCFrag 0x01
#endif
@ -184,7 +184,7 @@ typedef void (*dl_funcptr)();
#endif
#endif /* USE_RLD */
extern char *getprogramname();
extern char *Py_GetProgramName();
#ifndef FUNCNAME_PATTERN
#if defined(__hp9000s300) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__BORLANDC__)
@ -207,9 +207,9 @@ extern char *getprogramname();
#endif
/* Pass it on to import.c */
int import_maxsuffixsize = MAXSUFFIXSIZE;
int _PyImport_MaxSuffixSize = MAXSUFFIXSIZE;
struct filedescr import_filetab[] = {
struct filedescr _PyImport_Filetab[] = {
#ifdef SHORT_EXT
{SHORT_EXT, "rb", C_EXTENSION},
#endif /* !SHORT_EXT */
@ -225,17 +225,18 @@ struct filedescr import_filetab[] = {
#undef DYNAMIC_LINK
#endif
object *
load_dynamic_module(name, pathname, fp)
PyObject *
_PyImport_LoadDynamicModule(name, pathname, fp)
char *name;
char *pathname;
FILE *fp;
{
#ifndef DYNAMIC_LINK
err_setstr(ImportError, "dynamically linked modules not supported");
PyErr_SetString(PyExc_ImportError,
"dynamically linked modules not supported");
return NULL;
#else
object *m, *d, *s;
PyObject *m, *d, *s;
char funcname[258];
dl_funcptr p = NULL;
#ifdef USE_SHLIB
@ -274,11 +275,12 @@ load_dynamic_module(name, pathname, fp)
#endif /* USE_SHLIB */
#ifdef USE_MAC_DYNAMIC_LOADING
/*
** Dynamic loading of CFM shared libraries on the Mac.
** The code has become more convoluted than it was, because we want to be able
** to put multiple modules in a single file. For this reason, we have to determine
** the fragment name, and we cannot use the library entry point but we have to locate
** the correct init routine "by hand".
** Dynamic loading of CFM shared libraries on the Mac. The
** code has become more convoluted than it was, because we
** want to be able to put multiple modules in a single
** file. For this reason, we have to determine the fragment
** name, and we cannot use the library entry point but we have
** to locate the correct init routine "by hand".
*/
{
FSSpec libspec;
@ -297,30 +299,35 @@ load_dynamic_module(name, pathname, fp)
err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
if ( err ) {
sprintf(buf, "%s: %s", pathname, PyMac_StrError(err));
err_setstr(ImportError, buf);
PyErr_SetString(PyExc_ImportError, buf);
return NULL;
}
/* Next, determine the fragment name, by stripping '.slb' and 'module' */
/* Next, determine the fragment name,
by stripping '.slb' and 'module' */
memcpy(fragname+1, libspec.name+1, libspec.name[0]);
fragname[0] = libspec.name[0];
if( strncmp((char *)(fragname+1+fragname[0]-4), ".slb", 4) == 0 )
if( strncmp((char *)(fragname+1+fragname[0]-4),
".slb", 4) == 0 )
fragname[0] -= 4;
if ( strncmp((char *)(fragname+1+fragname[0]-6), "module", 6) == 0 )
if ( strncmp((char *)(fragname+1+fragname[0]-6),
"module", 6) == 0 )
fragname[0] -= 6;
/* Load the fragment (or return the connID if it is already loaded */
/* Load the fragment
(or return the connID if it is already loaded */
err = GetDiskFragment(&libspec, 0, 0, fragname,
kLoadCFrag, &connID, &mainAddr,
errMessage);
if ( err ) {
sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err));
err_setstr(ImportError, buf);
sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1,
PyMac_StrError(err));
PyErr_SetString(PyExc_ImportError, buf);
return NULL;
}
/* Locate the address of the correct init function */
err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
if ( err ) {
sprintf(buf, "%s: %s", funcname, PyMac_StrError(err));
err_setstr(ImportError, buf);
PyErr_SetString(PyExc_ImportError, buf);
return NULL;
}
p = (dl_funcptr)symAddr;
@ -334,12 +341,12 @@ load_dynamic_module(name, pathname, fp)
void *handle = dlopen(pathname, RTLD_NOW);
#else
void *handle;
if (verbose)
if (Py_VerboseFlag)
printf("dlopen(\"%s\", %d);\n", pathname, RTLD_LAZY);
handle = dlopen(pathname, RTLD_LAZY);
#endif /* RTLD_NOW */
if (handle == NULL) {
err_setstr(ImportError, dlerror());
PyErr_SetString(PyExc_ImportError, dlerror());
return NULL;
}
if (fp != NULL && nhandles < 128)
@ -382,12 +389,14 @@ load_dynamic_module(name, pathname, fp)
unsigned int errorCode;
/* Get an error string from Win32 error code */
char theInfo[256]; /* Pointer to error text from system */
char theInfo[256]; /* Pointer to error text
from system */
int theLength; /* Length of error text */
errorCode = GetLastError();
theLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
theLength = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
NULL, /* message source */
errorCode, /* the message (error) ID */
0, /* default language environment */
@ -395,22 +404,29 @@ load_dynamic_module(name, pathname, fp)
sizeof(theInfo), /* the buffer size */
NULL); /* no additional format args. */
/* Problem: could not get the error message. This should not happen if called correctly. */
/* Problem: could not get the error message.
This should not happen if called correctly. */
if (theLength == 0) {
sprintf(errBuf, "DLL load failed with error code %d", errorCode);
sprintf(errBuf,
"DLL load failed with error code %d",
errorCode);
} else {
int len;
/* For some reason a \r\n is appended to the text */
if (theLength >= 2 && theInfo[theLength-2] == '\r' && theInfo[theLength-1] == '\n') {
/* For some reason a \r\n
is appended to the text */
if (theLength >= 2 &&
theInfo[theLength-2] == '\r' &&
theInfo[theLength-1] == '\n') {
theLength -= 2;
theInfo[theLength] = '\0';
}
strcpy(errBuf, "DLL load failed: ");
len = strlen(errBuf);
strncpy(errBuf+len, theInfo, sizeof(errBuf)-len);
strncpy(errBuf+len, theInfo,
sizeof(errBuf)-len);
errBuf[sizeof(errBuf)-1] = '\0';
}
err_setstr(ImportError, errBuf);
PyErr_SetString(PyExc_ImportError, errBuf);
return NULL;
}
p = GetProcAddress(hDLL, funcname);
@ -422,15 +438,16 @@ load_dynamic_module(name, pathname, fp)
hDLL = LoadLibrary(pathname);
if (hDLL < HINSTANCE_ERROR){
char errBuf[256];
sprintf(errBuf, "DLL load failed with error code %d", hDLL);
err_setstr(ImportError, errBuf);
sprintf(errBuf,
"DLL load failed with error code %d", hDLL);
PyErr_SetString(PyExc_ImportError, errBuf);
return NULL;
}
p = GetProcAddress(hDLL, funcname);
}
#endif /* MS_WIN16 */
#ifdef USE_DL
p = dl_loadmod(getprogramname(), pathname, funcname);
p = dl_loadmod(Py_GetProgramName(), pathname, funcname);
#endif /* USE_DL */
#ifdef USE_RLD
{
@ -455,7 +472,7 @@ load_dynamic_module(name, pathname, fp)
NXGetMemoryBuffer(errorStream,
&streamBuf, &len, &maxLen);
err_setstr(ImportError, streamBuf);
PyErr_SetString(PyExc_ImportError, streamBuf);
}
if(ret && rld_lookup(errorStream, funcname, &ptr))
@ -473,25 +490,26 @@ load_dynamic_module(name, pathname, fp)
int flags;
flags = BIND_FIRST | BIND_DEFERRED;
if (verbose)
if (Py_VerboseFlag)
{
flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE | BIND_NONFATAL | BIND_VERBOSE;
flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE |
BIND_NONFATAL | BIND_VERBOSE;
printf("shl_load %s\n",pathname);
}
lib = shl_load(pathname, flags, 0);
if (lib == NULL)
{
char buf[256];
if (verbose)
if (Py_VerboseFlag)
perror(pathname);
sprintf(buf, "Failed to load %.200s", pathname);
err_setstr(ImportError, buf);
PyErr_SetString(PyExc_ImportError, buf);
return NULL;
}
if (verbose)
if (Py_VerboseFlag)
printf("shl_findsym %s\n", funcname);
shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);
if (p == NULL && verbose)
if (p == NULL && Py_VerboseFlag)
perror(funcname);
}
#endif /* hpux */
@ -499,31 +517,31 @@ load_dynamic_module(name, pathname, fp)
got_it:
#endif
if (p == NULL) {
err_setstr(ImportError,
PyErr_SetString(PyExc_ImportError,
"dynamic module does not define init function");
return NULL;
}
(*p)();
/* XXX Need check for err_occurred() here */
m = dictlookup(import_modules, name);
m = PyDict_GetItemString(import_modules, name);
if (m == NULL) {
if (err_occurred() == NULL)
err_setstr(SystemError,
if (PyErr_Occurred() == NULL)
PyErr_SetString(PyExc_SystemError,
"dynamic module not initialized properly");
return NULL;
}
/* Remember the filename as the __file__ attribute */
d = getmoduledict(m);
s = newstringobject(pathname);
if (s == NULL || dictinsert(d, "__file__", s) != 0)
err_clear(); /* Not important enough to report */
XDECREF(s);
if (verbose)
d = PyModule_GetDict(m);
s = PyString_FromString(pathname);
if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0)
PyErr_Clear(); /* Not important enough to report */
Py_XDECREF(s);
if (Py_VerboseFlag)
fprintf(stderr,
"import %s # dynamically loaded from %s\n",
name, pathname);
INCREF(m);
Py_INCREF(m);
return m;
#endif /* DYNAMIC_LINK */
}
@ -555,7 +573,7 @@ aix_getoldmodules(modlistptr)
-- Get the list of loaded modules into ld_info structures.
*/
if ((ldibuf = malloc(bufsize)) == NULL) {
err_setstr(ImportError, strerror(errno));
PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1;
}
while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1
@ -563,12 +581,12 @@ aix_getoldmodules(modlistptr)
free(ldibuf);
bufsize += 1024;
if ((ldibuf = malloc(bufsize)) == NULL) {
err_setstr(ImportError, strerror(errno));
PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1;
}
}
if (errflag == -1) {
err_setstr(ImportError, strerror(errno));
PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1;
}
/*
@ -578,7 +596,7 @@ aix_getoldmodules(modlistptr)
prevmodptr = NULL;
do {
if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) {
err_setstr(ImportError, strerror(errno));
PyErr_SetString(PyExc_ImportError, strerror(errno));
while (*modlistptr) {
modptr = (ModulePtr)*modlistptr;
*modlistptr = (void *)modptr->next;
@ -662,7 +680,7 @@ aix_loaderror(pathname)
ERRBUF_APPEND("\n");
}
errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
err_setstr(ImportError, errbuf);
PyErr_SetString(PyExc_ImportError, errbuf);
return;
}

View File

@ -40,10 +40,11 @@ extern struct filedescr {
char *suffix;
char *mode;
enum filetype type;
} import_filetab[];
} _PyImport_Filetab[];
extern object *import_modules;
extern PyObject *import_modules;
extern object *load_dynamic_module PROTO((char *name, char *pathname, FILE *));
extern PyObject *_PyImport_LoadDynamicModule
Py_PROTO((char *name, char *pathname, FILE *));
extern int import_maxsuffixsize;
extern int _PyImport_MaxSuffixSize;

View File

@ -34,14 +34,11 @@ PERFORMANCE OF THIS SOFTWARE.
a true persistent storage facility would be much harder, since
it would have to take circular links and sharing into account. */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include "longintrepr.h"
#include "compile.h"
#include "marshal.h"
#include <errno.h>
#define TYPE_NULL '0'
#define TYPE_NONE 'N'
#define TYPE_ELLIPSIS '.'
@ -61,7 +58,7 @@ typedef struct {
FILE *fp;
int error;
/* If fp == NULL, the following are valid: */
object *str;
PyObject *str;
char *ptr;
char *end;
} WFILE;
@ -78,14 +75,15 @@ w_more(c, p)
int size, newsize;
if (p->str == NULL)
return; /* An error already occurred */
size = getstringsize(p->str);
size = PyString_Size(p->str);
newsize = size + 1024;
if (resizestring(&p->str, newsize) != 0) {
if (_PyString_Resize(&p->str, newsize) != 0) {
p->ptr = p->end = NULL;
}
else {
p->ptr = GETSTRINGVALUE((stringobject *)p->str) + size;
p->end = GETSTRINGVALUE((stringobject *)p->str) + newsize;
p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size;
p->end =
PyString_AS_STRING((PyStringObject *)p->str) + newsize;
*p->ptr++ = c;
}
}
@ -140,19 +138,19 @@ w_long64(x, p)
static void
w_object(v, p)
object *v;
PyObject *v;
WFILE *p;
{
int i, n;
if (v == NULL)
w_byte(TYPE_NULL, p);
else if (v == None)
else if (v == Py_None)
w_byte(TYPE_NONE, p);
else if (v == Py_Ellipsis)
w_byte(TYPE_ELLIPSIS, p);
else if (is_intobject(v)) {
long x = GETINTVALUE((intobject *)v);
else if (PyInt_Check(v)) {
long x = PyInt_AS_LONG((PyIntObject *)v);
#if SIZEOF_LONG > 4
long y = x>>31;
if (y && y != -1) {
@ -166,8 +164,8 @@ w_object(v, p)
w_long(x, p);
}
}
else if (is_longobject(v)) {
longobject *ob = (longobject *)v;
else if (PyLong_Check(v)) {
PyLongObject *ob = (PyLongObject *)v;
w_byte(TYPE_LONG, p);
n = ob->ob_size;
w_long((long)n, p);
@ -176,77 +174,81 @@ w_object(v, p)
for (i = 0; i < n; i++)
w_short(ob->ob_digit[i], p);
}
else if (is_floatobject(v)) {
extern void float_buf_repr PROTO((char *, floatobject *));
else if (PyFloat_Check(v)) {
extern void PyFloat_AsString
Py_PROTO((char *, PyFloatObject *));
char buf[256]; /* Plenty to format any double */
float_buf_repr(buf, (floatobject *)v);
PyFloat_AsString(buf, (PyFloatObject *)v);
n = strlen(buf);
w_byte(TYPE_FLOAT, p);
w_byte(n, p);
w_string(buf, n, p);
}
#ifndef WITHOUT_COMPLEX
else if (is_complexobject(v)) {
extern void float_buf_repr PROTO((char *, floatobject *));
else if (PyComplex_Check(v)) {
extern void PyFloat_AsString
Py_PROTO((char *, PyFloatObject *));
char buf[256]; /* Plenty to format any double */
floatobject *temp;
PyFloatObject *temp;
w_byte(TYPE_COMPLEX, p);
temp = (floatobject*)newfloatobject(PyComplex_RealAsDouble(v));
float_buf_repr(buf, temp);
DECREF(temp);
temp = (PyFloatObject*)PyFloat_FromDouble(
PyComplex_RealAsDouble(v));
PyFloat_AsString(buf, temp);
Py_DECREF(temp);
n = strlen(buf);
w_byte(n, p);
w_string(buf, n, p);
temp = (floatobject*)newfloatobject(PyComplex_ImagAsDouble(v));
float_buf_repr(buf, temp);
DECREF(temp);
temp = (PyFloatObject*)PyFloat_FromDouble(
PyComplex_ImagAsDouble(v));
PyFloat_AsString(buf, temp);
Py_DECREF(temp);
n = strlen(buf);
w_byte(n, p);
w_string(buf, n, p);
}
#endif
else if (is_stringobject(v)) {
else if (PyString_Check(v)) {
w_byte(TYPE_STRING, p);
n = getstringsize(v);
n = PyString_Size(v);
w_long((long)n, p);
w_string(getstringvalue(v), n, p);
w_string(PyString_AsString(v), n, p);
}
else if (is_tupleobject(v)) {
else if (PyTuple_Check(v)) {
w_byte(TYPE_TUPLE, p);
n = gettuplesize(v);
n = PyTuple_Size(v);
w_long((long)n, p);
for (i = 0; i < n; i++) {
w_object(GETTUPLEITEM(v, i), p);
w_object(PyTuple_GET_ITEM(v, i), p);
}
}
else if (is_listobject(v)) {
else if (PyList_Check(v)) {
w_byte(TYPE_LIST, p);
n = getlistsize(v);
n = PyList_Size(v);
w_long((long)n, p);
for (i = 0; i < n; i++) {
w_object(getlistitem(v, i), p);
w_object(PyList_GetItem(v, i), p);
}
}
else if (is_dictobject(v)) {
else if (PyDict_Check(v)) {
int pos;
object *key, *value;
PyObject *key, *value;
w_byte(TYPE_DICT, p);
/* This one is NULL object terminated! */
pos = 0;
while (mappinggetnext(v, &pos, &key, &value)) {
while (PyDict_Next(v, &pos, &key, &value)) {
w_object(key, p);
w_object(value, p);
}
w_object((object *)NULL, p);
w_object((PyObject *)NULL, p);
}
else if (is_codeobject(v)) {
codeobject *co = (codeobject *)v;
else if (PyCode_Check(v)) {
PyCodeObject *co = (PyCodeObject *)v;
w_byte(TYPE_CODE, p);
w_short(co->co_argcount, p);
w_short(co->co_nlocals, p);
w_short(co->co_stacksize, p);
w_short(co->co_flags, p);
w_object((object *)co->co_code, p);
w_object((PyObject *)co->co_code, p);
w_object(co->co_consts, p);
w_object(co->co_names, p);
w_object(co->co_varnames, p);
@ -262,7 +264,7 @@ w_object(v, p)
}
void
wr_long(x, fp)
PyMarshal_WriteLongToFile(x, fp)
long x;
FILE *fp;
{
@ -273,8 +275,8 @@ wr_long(x, fp)
}
void
wr_object(x, fp)
object *x;
PyMarshal_WriteObjectToFile(x, fp)
PyObject *x;
FILE *fp;
{
WFILE wf;
@ -351,10 +353,10 @@ r_long64(p)
x = (x & 0xFFFFFFFF) | (r_long(p) << 32);
#else
if (r_long(p) != 0) {
object *f = sysget("stderr");
err_clear();
PyObject *f = PySys_GetObject("stderr");
PyErr_Clear();
if (f != NULL)
writestring(
PyFile_WriteString(
"Warning: un-marshal 64-bit int in 32-bit mode\n",
f);
}
@ -362,60 +364,61 @@ r_long64(p)
return x;
}
static object *
static PyObject *
r_object(p)
RFILE *p;
{
object *v, *v2;
PyObject *v, *v2;
long i, n;
int type = r_byte(p);
switch (type) {
case EOF:
err_setstr(EOFError, "EOF read where object expected");
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
return NULL;
case TYPE_NULL:
return NULL;
case TYPE_NONE:
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
case TYPE_ELLIPSIS:
INCREF(Py_Ellipsis);
Py_INCREF(Py_Ellipsis);
return Py_Ellipsis;
case TYPE_INT:
return newintobject(r_long(p));
return PyInt_FromLong(r_long(p));
case TYPE_INT64:
return newintobject(r_long64(p));
return PyInt_FromLong(r_long64(p));
case TYPE_LONG:
{
int size;
longobject *ob;
PyLongObject *ob;
n = r_long(p);
size = n<0 ? -n : n;
ob = alloclongobject(size);
ob = _PyLong_New(size);
if (ob == NULL)
return NULL;
ob->ob_size = n;
for (i = 0; i < size; i++)
ob->ob_digit[i] = r_short(p);
return (object *)ob;
return (PyObject *)ob;
}
case TYPE_FLOAT:
{
extern double atof PROTO((const char *));
extern double atof Py_PROTO((const char *));
char buf[256];
double dx;
n = r_byte(p);
if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError,
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
return NULL;
}
@ -423,18 +426,18 @@ r_object(p)
PyFPE_START_PROTECT("atof", return 0)
dx = atof(buf);
PyFPE_END_PROTECT(dx)
return newfloatobject(dx);
return PyFloat_FromDouble(dx);
}
#ifndef WITHOUT_COMPLEX
case TYPE_COMPLEX:
{
extern double atof PROTO((const char *));
extern double atof Py_PROTO((const char *));
char buf[256];
Py_complex c;
n = r_byte(p);
if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError,
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
return NULL;
}
@ -444,7 +447,7 @@ r_object(p)
PyFPE_END_PROTECT(c)
n = r_byte(p);
if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError,
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
return NULL;
}
@ -452,18 +455,18 @@ r_object(p)
PyFPE_START_PROTECT("atof", return 0)
c.imag = atof(buf);
PyFPE_END_PROTECT(c)
return newcomplexobject(c);
return PyComplex_FromCComplex(c);
}
#endif
case TYPE_STRING:
n = r_long(p);
v = newsizedstringobject((char *)NULL, n);
v = PyString_FromStringAndSize((char *)NULL, n);
if (v != NULL) {
if (r_string(getstringvalue(v), (int)n, p) != n) {
DECREF(v);
if (r_string(PyString_AsString(v), (int)n, p) != n) {
Py_DECREF(v);
v = NULL;
err_setstr(EOFError,
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
}
}
@ -471,50 +474,50 @@ r_object(p)
case TYPE_TUPLE:
n = r_long(p);
v = newtupleobject((int)n);
v = PyTuple_New((int)n);
if (v == NULL)
return v;
for (i = 0; i < n; i++) {
v2 = r_object(p);
if ( v2 == NULL ) {
DECREF(v);
Py_DECREF(v);
v = NULL;
break;
}
SETTUPLEITEM(v, (int)i, v2);
PyTuple_SET_ITEM(v, (int)i, v2);
}
return v;
case TYPE_LIST:
n = r_long(p);
v = newlistobject((int)n);
v = PyList_New((int)n);
if (v == NULL)
return v;
for (i = 0; i < n; i++) {
v2 = r_object(p);
if ( v2 == NULL ) {
DECREF(v);
Py_DECREF(v);
v = NULL;
break;
}
setlistitem(v, (int)i, v2);
PyList_SetItem(v, (int)i, v2);
}
return v;
case TYPE_DICT:
v = newdictobject();
v = PyDict_New();
if (v == NULL)
return NULL;
for (;;) {
object *key, *val;
PyObject *key, *val;
key = r_object(p);
if (key == NULL)
break; /* XXX Assume TYPE_NULL, not an error */
val = r_object(p);
if (val != NULL)
dict2insert(v, key, val);
DECREF(key);
XDECREF(val);
PyDict_SetItem(v, key, val);
Py_DECREF(key);
Py_XDECREF(val);
}
return v;
@ -524,14 +527,14 @@ r_object(p)
int nlocals = r_short(p);
int stacksize = r_short(p);
int flags = r_short(p);
object *code = NULL;
object *consts = NULL;
object *names = NULL;
object *varnames = NULL;
object *filename = NULL;
object *name = NULL;
PyObject *code = NULL;
PyObject *consts = NULL;
PyObject *names = NULL;
PyObject *varnames = NULL;
PyObject *filename = NULL;
PyObject *name = NULL;
int firstlineno = 0;
object *lnotab = NULL;
PyObject *lnotab = NULL;
code = r_object(p);
if (code) consts = r_object(p);
@ -544,20 +547,20 @@ r_object(p)
lnotab = r_object(p);
}
if (!err_occurred()) {
v = (object *) newcodeobject(
if (!PyErr_Occurred()) {
v = (PyObject *) PyCode_New(
argcount, nlocals, stacksize, flags,
code, consts, names, varnames,
filename, name, firstlineno, lnotab);
}
else
v = NULL;
XDECREF(code);
XDECREF(consts);
XDECREF(names);
XDECREF(varnames);
XDECREF(filename);
XDECREF(name);
Py_XDECREF(code);
Py_XDECREF(consts);
Py_XDECREF(names);
Py_XDECREF(varnames);
Py_XDECREF(filename);
Py_XDECREF(name);
}
return v;
@ -565,14 +568,14 @@ r_object(p)
default:
/* Bogus data got written, which isn't ideal.
This will let you keep working and recover. */
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
}
long
rd_long(fp)
PyMarshal_ReadLongFromFile(fp)
FILE *fp;
{
RFILE rf;
@ -580,13 +583,12 @@ rd_long(fp)
return r_long(&rf);
}
object *
rd_object(fp)
PyObject *
PyMarshal_ReadObjectFromFile(fp)
FILE *fp;
{
RFILE rf;
if (err_occurred()) {
fatal("XXX rd_object called with exception set"); /* tmp */
if (PyErr_Occurred()) {
fprintf(stderr, "XXX rd_object called with exception set\n");
return NULL;
}
@ -594,13 +596,13 @@ rd_object(fp)
return r_object(&rf);
}
object *
rds_object(str, len)
PyObject *
PyMarshal_ReadObjectFromString(str, len)
char *str;
int len;
{
RFILE rf;
if (err_occurred()) {
if (PyErr_Occurred()) {
fprintf(stderr, "XXX rds_object called with exception set\n");
return NULL;
}
@ -611,25 +613,26 @@ rds_object(str, len)
return r_object(&rf);
}
object *
PyObject *
PyMarshal_WriteObjectToString(x) /* wrs_object() */
object *x;
PyObject *x;
{
WFILE wf;
wf.fp = NULL;
wf.str = newsizedstringobject((char *)NULL, 50);
wf.str = PyString_FromStringAndSize((char *)NULL, 50);
if (wf.str == NULL)
return NULL;
wf.ptr = GETSTRINGVALUE((stringobject *)wf.str);
wf.end = wf.ptr + getstringsize(wf.str);
wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str);
wf.end = wf.ptr + PyString_Size(wf.str);
wf.error = 0;
w_object(x, &wf);
if (wf.str != NULL)
resizestring(&wf.str,
(int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str)));
_PyString_Resize(&wf.str,
(int) (wf.ptr -
PyString_AS_STRING((PyStringObject *)wf.str)));
if (wf.error) {
XDECREF(wf.str);
err_setstr(ValueError, "unmarshallable object");
Py_XDECREF(wf.str);
PyErr_SetString(PyExc_ValueError, "unmarshallable object");
return NULL;
}
return wf.str;
@ -637,95 +640,97 @@ PyMarshal_WriteObjectToString(x) /* wrs_object() */
/* And an interface for Python programs... */
static object *
static PyObject *
marshal_dump(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
WFILE wf;
object *x;
object *f;
if (!getargs(args, "(OO)", &x, &f))
PyObject *x;
PyObject *f;
if (!PyArg_Parse(args, "(OO)", &x, &f))
return NULL;
if (!is_fileobject(f)) {
err_setstr(TypeError, "marshal.dump() 2nd arg must be file");
if (!PyFile_Check(f)) {
PyErr_SetString(PyExc_TypeError,
"marshal.dump() 2nd arg must be file");
return NULL;
}
wf.fp = getfilefile(f);
wf.fp = PyFile_AsFile(f);
wf.str = NULL;
wf.ptr = wf.end = NULL;
wf.error = 0;
w_object(x, &wf);
if (wf.error) {
err_setstr(ValueError, "unmarshallable object");
PyErr_SetString(PyExc_ValueError, "unmarshallable object");
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
marshal_load(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
RFILE rf;
object *f;
object *v;
if (!getargs(args, "O", &f))
PyObject *f;
PyObject *v;
if (!PyArg_Parse(args, "O", &f))
return NULL;
if (!is_fileobject(f)) {
err_setstr(TypeError, "marshal.load() arg must be file");
if (!PyFile_Check(f)) {
PyErr_SetString(PyExc_TypeError,
"marshal.load() arg must be file");
return NULL;
}
rf.fp = getfilefile(f);
rf.fp = PyFile_AsFile(f);
rf.str = NULL;
rf.ptr = rf.end = NULL;
err_clear();
PyErr_Clear();
v = r_object(&rf);
if (err_occurred()) {
XDECREF(v);
if (PyErr_Occurred()) {
Py_XDECREF(v);
v = NULL;
}
return v;
}
static object *
static PyObject *
marshal_dumps(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
object *x;
if (!getargs(args, "O", &x))
PyObject *x;
if (!PyArg_Parse(args, "O", &x))
return NULL;
return PyMarshal_WriteObjectToString(x);
}
static object *
static PyObject *
marshal_loads(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
RFILE rf;
object *v;
PyObject *v;
char *s;
int n;
if (!getargs(args, "s#", &s, &n))
if (!PyArg_Parse(args, "s#", &s, &n))
return NULL;
rf.fp = NULL;
rf.str = args;
rf.ptr = s;
rf.end = s + n;
err_clear();
PyErr_Clear();
v = r_object(&rf);
if (err_occurred()) {
XDECREF(v);
if (PyErr_Occurred()) {
Py_XDECREF(v);
v = NULL;
}
return v;
}
static struct methodlist marshal_methods[] = {
static PyMethodDef marshal_methods[] = {
{"dump", marshal_dump},
{"load", marshal_load},
{"dumps", marshal_dumps},
@ -734,7 +739,7 @@ static struct methodlist marshal_methods[] = {
};
void
initmarshal()
PyMarshal_Init()
{
(void) initmodule("marshal", marshal_methods);
(void) Py_InitModule("marshal", marshal_methods);
}

View File

@ -31,8 +31,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Module support implementation */
#include "allobjects.h"
#include "import.h"
#include "Python.h"
#ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */
typedef extended va_double;
@ -53,37 +52,39 @@ static char api_version_warning[] =
"WARNING: Python C API version mismatch for module %s:\n\
This Python has API version %d, module %s has version %d.\n";
object *
initmodule4(name, methods, doc, passthrough, module_api_version)
PyObject *
Py_InitModule4(name, methods, doc, passthrough, module_api_version)
char *name;
struct methodlist *methods;
PyMethodDef *methods;
char *doc;
object *passthrough;
PyObject *passthrough;
int module_api_version;
{
object *m, *d, *v;
struct methodlist *ml;
PyObject *m, *d, *v;
PyMethodDef *ml;
if (module_api_version != PYTHON_API_VERSION)
fprintf(stderr, api_version_warning,
name, PYTHON_API_VERSION, name, module_api_version);
if ((m = add_module(name)) == NULL) {
if ((m = PyImport_AddModule(name)) == NULL) {
fprintf(stderr, "initializing module: %s\n", name);
fatal("can't create a module");
Py_FatalError("can't create a module");
}
d = getmoduledict(m);
d = PyModule_GetDict(m);
for (ml = methods; ml->ml_name != NULL; ml++) {
v = newmethodobject(ml, passthrough);
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
v = PyCFunction_New(ml, passthrough);
if (v == NULL ||
PyDict_SetItemString(d, ml->ml_name, v) != 0)
{
fprintf(stderr, "initializing module: %s\n", name);
fatal("can't initialize module");
Py_FatalError("can't initialize module");
}
DECREF(v);
Py_DECREF(v);
}
if (doc != NULL) {
v = newstringobject(doc);
if (v == NULL || dictinsert(d, "__doc__", v) != 0)
fatal("can't add doc string");
DECREF(v);
v = PyString_FromString(doc);
if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0)
Py_FatalError("can't add doc string");
Py_DECREF(v);
}
return m;
}
@ -91,7 +92,7 @@ initmodule4(name, methods, doc, passthrough, module_api_version)
/* Helper for mkvalue() to scan the length of a format */
static int countformat PROTO((char *format, int endchar));
static int countformat Py_PROTO((char *format, int endchar));
static int countformat(format, endchar)
char *format;
int endchar;
@ -102,7 +103,8 @@ static int countformat(format, endchar)
switch (*format) {
case '\0':
/* Premature end */
err_setstr(SystemError, "unmatched paren in format");
PyErr_SetString(PyExc_SystemError,
"unmatched paren in format");
return -1;
case '(':
case '[':
@ -136,118 +138,121 @@ static int countformat(format, endchar)
/* Generic function to create a value -- the inverse of getargs() */
/* After an original idea and first implementation by Steven Miale */
static object *do_mktuple PROTO((char**, va_list *, int, int));
static object *do_mklist PROTO((char**, va_list *, int, int));
static object *do_mkdict PROTO((char**, va_list *, int, int));
static object *do_mkvalue PROTO((char**, va_list *));
static PyObject *do_mktuple Py_PROTO((char**, va_list *, int, int));
static PyObject *do_mklist Py_PROTO((char**, va_list *, int, int));
static PyObject *do_mkdict Py_PROTO((char**, va_list *, int, int));
static PyObject *do_mkvalue Py_PROTO((char**, va_list *));
static object *
static PyObject *
do_mkdict(p_format, p_va, endchar, n)
char **p_format;
va_list *p_va;
int endchar;
int n;
{
object *d;
PyObject *d;
int i;
if (n < 0)
return NULL;
if ((d = newdictobject()) == NULL)
if ((d = PyDict_New()) == NULL)
return NULL;
for (i = 0; i < n; i+= 2) {
object *k, *v;
PyObject *k, *v;
k = do_mkvalue(p_format, p_va);
if (k == NULL) {
DECREF(d);
Py_DECREF(d);
return NULL;
}
v = do_mkvalue(p_format, p_va);
if (v == NULL) {
DECREF(k);
DECREF(d);
Py_DECREF(k);
Py_DECREF(d);
return NULL;
}
if (dict2insert(d, k, v) < 0) {
DECREF(k);
DECREF(v);
DECREF(d);
if (PyDict_SetItem(d, k, v) < 0) {
Py_DECREF(k);
Py_DECREF(v);
Py_DECREF(d);
return NULL;
}
}
if (d != NULL && **p_format != endchar) {
DECREF(d);
Py_DECREF(d);
d = NULL;
err_setstr(SystemError, "Unmatched paren in format");
PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
}
else if (endchar)
++*p_format;
return d;
}
static object *
static PyObject *
do_mklist(p_format, p_va, endchar, n)
char **p_format;
va_list *p_va;
int endchar;
int n;
{
object *v;
PyObject *v;
int i;
if (n < 0)
return NULL;
if ((v = newlistobject(n)) == NULL)
if ((v = PyList_New(n)) == NULL)
return NULL;
for (i = 0; i < n; i++) {
object *w = do_mkvalue(p_format, p_va);
PyObject *w = do_mkvalue(p_format, p_va);
if (w == NULL) {
DECREF(v);
Py_DECREF(v);
return NULL;
}
setlistitem(v, i, w);
PyList_SetItem(v, i, w);
}
if (v != NULL && **p_format != endchar) {
DECREF(v);
Py_DECREF(v);
v = NULL;
err_setstr(SystemError, "Unmatched paren in format");
PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
}
else if (endchar)
++*p_format;
return v;
}
static object *
static PyObject *
do_mktuple(p_format, p_va, endchar, n)
char **p_format;
va_list *p_va;
int endchar;
int n;
{
object *v;
PyObject *v;
int i;
if (n < 0)
return NULL;
if ((v = newtupleobject(n)) == NULL)
if ((v = PyTuple_New(n)) == NULL)
return NULL;
for (i = 0; i < n; i++) {
object *w = do_mkvalue(p_format, p_va);
PyObject *w = do_mkvalue(p_format, p_va);
if (w == NULL) {
DECREF(v);
Py_DECREF(v);
return NULL;
}
settupleitem(v, i, w);
PyTuple_SetItem(v, i, w);
}
if (v != NULL && **p_format != endchar) {
DECREF(v);
Py_DECREF(v);
v = NULL;
err_setstr(SystemError, "Unmatched paren in format");
PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
}
else if (endchar)
++*p_format;
return v;
}
static object *
static PyObject *
do_mkvalue(p_format, p_va)
char **p_format;
va_list *p_va;
@ -269,26 +274,27 @@ do_mkvalue(p_format, p_va)
case 'b':
case 'h':
case 'i':
return newintobject((long)va_arg(*p_va, int));
return PyInt_FromLong((long)va_arg(*p_va, int));
case 'l':
return newintobject((long)va_arg(*p_va, long));
return PyInt_FromLong((long)va_arg(*p_va, long));
case 'f':
case 'd':
return newfloatobject((double)va_arg(*p_va, va_double));
return PyFloat_FromDouble(
(double)va_arg(*p_va, va_double));
case 'c':
{
char p[1];
p[0] = va_arg(*p_va, int);
return newsizedstringobject(p, 1);
return PyString_FromStringAndSize(p, 1);
}
case 's':
case 'z':
{
object *v;
PyObject *v;
char *str = va_arg(*p_va, char *);
int n;
if (**p_format == '#') {
@ -298,13 +304,13 @@ do_mkvalue(p_format, p_va)
else
n = -1;
if (str == NULL) {
v = None;
INCREF(v);
v = Py_None;
Py_INCREF(v);
}
else {
if (n < 0)
n = strlen(str);
v = newsizedstringobject(str, n);
v = PyString_FromStringAndSize(str, n);
}
return v;
}
@ -312,18 +318,18 @@ do_mkvalue(p_format, p_va)
case 'S':
case 'O':
if (**p_format == '&') {
typedef object *(*converter) PROTO((void *));
typedef PyObject *(*converter) Py_PROTO((void *));
converter func = va_arg(*p_va, converter);
void *arg = va_arg(*p_va, void *);
++*p_format;
return (*func)(arg);
}
else {
object *v;
v = va_arg(*p_va, object *);
PyObject *v;
v = va_arg(*p_va, PyObject *);
if (v != NULL)
INCREF(v);
else if (!err_occurred())
Py_INCREF(v);
else if (!PyErr_Occurred())
/* If a NULL was passed
* because a call that should
* have constructed a value
@ -332,7 +338,7 @@ do_mkvalue(p_format, p_va)
* no error occurred it's not
* clear that the caller knew
* what she was doing. */
err_setstr(SystemError,
PyErr_SetString(PyExc_SystemError,
"NULL object passed to mkvalue");
return v;
}
@ -344,7 +350,7 @@ do_mkvalue(p_format, p_va)
break;
default:
err_setstr(SystemError,
PyErr_SetString(PyExc_SystemError,
"bad format char passed to mkvalue");
return NULL;
@ -355,14 +361,14 @@ do_mkvalue(p_format, p_va)
#ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS 2 */
object *mkvalue(char *format, ...)
PyObject *Py_BuildValue(char *format, ...)
#else
/* VARARGS */
object *mkvalue(va_alist) va_dcl
PyObject *Py_BuildValue(va_alist) va_dcl
#endif
{
va_list va;
object* retval;
PyObject* retval;
#ifdef HAVE_STDARG_PROTOTYPES
va_start(va, format);
#else
@ -370,13 +376,13 @@ object *mkvalue(va_alist) va_dcl
va_start(va);
format = va_arg(va, char *);
#endif
retval = vmkvalue(format, va);
retval = Py_VaBuildValue(format, va);
va_end(va);
return retval;
}
object *
vmkvalue(format, va)
PyObject *
Py_VaBuildValue(format, va)
char *format;
va_list va;
{
@ -393,8 +399,8 @@ vmkvalue(format, va)
if (n < 0)
return NULL;
if (n == 0) {
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
if (n == 1)
return do_mkvalue(&f, &lva);
@ -403,19 +409,19 @@ vmkvalue(format, va)
#ifdef HAVE_STDARG_PROTOTYPES
object *
PyEval_CallFunction(object *obj, char *format, ...)
PyObject *
PyEval_CallFunction(PyObject *obj, char *format, ...)
#else
object *
PyObject *
PyEval_CallFunction(obj, format, va_alist)
object *obj;
PyObject *obj;
char *format;
va_dcl
#endif
{
va_list vargs;
object *args;
object *res;
PyObject *args;
PyObject *res;
#ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, format);
@ -423,37 +429,37 @@ PyEval_CallFunction(obj, format, va_alist)
va_start(vargs);
#endif
args = vmkvalue(format, vargs);
args = Py_VaBuildValue(format, vargs);
va_end(vargs);
if (args == NULL)
return NULL;
res = call_object(obj, args);
DECREF(args);
res = PyEval_CallObject(obj, args);
Py_DECREF(args);
return res;
}
#ifdef HAVE_STDARG_PROTOTYPES
object *
PyEval_CallMethod(object *obj, char *methonname, char *format, ...)
PyObject *
PyEval_CallMethod(PyObject *obj, char *methonname, char *format, ...)
#else
object *
PyObject *
PyEval_CallMethod(obj, methonname, format, va_alist)
object *obj;
PyObject *obj;
char *methonname;
char *format;
va_dcl
#endif
{
va_list vargs;
object *meth;
object *args;
object *res;
PyObject *meth;
PyObject *args;
PyObject *res;
meth = getattr(obj, methonname);
meth = PyObject_GetAttrString(obj, methonname);
if (meth == NULL)
return NULL;
@ -463,17 +469,17 @@ PyEval_CallMethod(obj, methonname, format, va_alist)
va_start(vargs);
#endif
args = vmkvalue(format, vargs);
args = Py_VaBuildValue(format, vargs);
va_end(vargs);
if (args == NULL) {
DECREF(meth);
Py_DECREF(meth);
return NULL;
}
res = call_object(meth, args);
DECREF(meth);
DECREF(args);
res = PyEval_CallObject(meth, args);
Py_DECREF(meth);
Py_DECREF(args);
return res;
}

View File

@ -36,15 +36,14 @@ PERFORMANCE OF THIS SOFTWARE.
overridden (at link time) by a more powerful version implemented in
signalmodule.c. */
#include "allobjects.h"
#include "intrcheck.h"
#include "Python.h"
/* ARGSUSED */
int
sigcheck()
PyErr_CheckSignals()
{
if (!intrcheck())
if (!PyOS_InterruptOccurred())
return 0;
err_set(KeyboardInterrupt);
PyErr_SetNone(PyExc_KeyboardInterrupt);
return -1;
}

View File

@ -31,35 +31,36 @@ PERFORMANCE OF THIS SOFTWARE.
/* Map C struct members to Python object attributes */
#include "allobjects.h"
#include "Python.h"
#include "structmember.h"
static object *
static PyObject *
listmembers(mlist)
struct memberlist *mlist;
{
int i, n;
object *v;
PyObject *v;
for (n = 0; mlist[n].name != NULL; n++)
;
v = newlistobject(n);
v = PyList_New(n);
if (v != NULL) {
for (i = 0; i < n; i++)
setlistitem(v, i, newstringobject(mlist[i].name));
if (err_occurred()) {
DECREF(v);
PyList_SetItem(v, i,
PyString_FromString(mlist[i].name));
if (PyErr_Occurred()) {
Py_DECREF(v);
v = NULL;
}
else {
sortlist(v);
PyList_Sort(v);
}
}
return v;
}
object *
getmember(addr, mlist, name)
PyObject *
PyMember_Get(addr, mlist, name)
char *addr;
struct memberlist *mlist;
char *name;
@ -70,111 +71,118 @@ getmember(addr, mlist, name)
return listmembers(mlist);
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
object *v;
PyObject *v;
addr += l->offset;
switch (l->type) {
case T_BYTE:
v = newintobject((long)
v = PyInt_FromLong((long)
(((*(char*)addr & 0xff)
^ 0x80) - 0x80));
break;
case T_UBYTE:
v = newintobject((long) *(char*)addr & 0xff);
v = PyInt_FromLong((long) *(char*)addr & 0xff);
break;
case T_SHORT:
v = newintobject((long) *(short*)addr);
v = PyInt_FromLong((long) *(short*)addr);
break;
case T_USHORT:
v = newintobject((long)
v = PyInt_FromLong((long)
*(unsigned short*)addr);
break;
case T_INT:
v = newintobject((long) *(int*)addr);
v = PyInt_FromLong((long) *(int*)addr);
break;
case T_UINT:
v = newintobject((long) *(unsigned int*)addr);
v = PyInt_FromLong((long)
*(unsigned int*)addr);
break;
case T_LONG:
v = newintobject(*(long*)addr);
v = PyInt_FromLong(*(long*)addr);
break;
case T_ULONG:
v = dnewlongobject((double)
v = PyLong_FromDouble((double)
*(unsigned long*)addr);
break;
case T_FLOAT:
v = newfloatobject((double)*(float*)addr);
v = PyFloat_FromDouble((double)*(float*)addr);
break;
case T_DOUBLE:
v = newfloatobject(*(double*)addr);
v = PyFloat_FromDouble(*(double*)addr);
break;
case T_STRING:
if (*(char**)addr == NULL) {
INCREF(None);
v = None;
Py_INCREF(Py_None);
v = Py_None;
}
else
v = newstringobject(*(char**)addr);
v = PyString_FromString(*(char**)addr);
break;
case T_STRING_INPLACE:
v = newstringobject((char*)addr);
v = PyString_FromString((char*)addr);
break;
#ifdef macintosh
case T_PSTRING:
if (*(char**)addr == NULL) {
INCREF(None);
v = None;
Py_INCREF(Py_None);
v = Py_None;
}
else
v = newsizedstringobject((*(char**)addr)+1,
v = PyString_FromStringAndSize(
(*(char**)addr)+1,
**(unsigned char**)addr);
break;
case T_PSTRING_INPLACE:
v = newsizedstringobject(((char*)addr)+1,
v = PyString_FromStringAndSize(
((char*)addr)+1,
*(unsigned char*)addr);
break;
#endif /* macintosh */
case T_CHAR:
v = newsizedstringobject((char*)addr, 1);
v = PyString_FromStringAndSize((char*)addr, 1);
break;
case T_OBJECT:
v = *(object **)addr;
v = *(PyObject **)addr;
if (v == NULL)
v = None;
INCREF(v);
v = Py_None;
Py_INCREF(v);
break;
default:
err_setstr(SystemError, "bad memberlist type");
PyErr_SetString(PyExc_SystemError,
"bad memberlist type");
v = NULL;
}
return v;
}
}
err_setstr(AttributeError, name);
PyErr_SetString(PyExc_AttributeError, name);
return NULL;
}
int
setmember(addr, mlist, name, v)
PyMember_Set(addr, mlist, name, v)
char *addr;
struct memberlist *mlist;
char *name;
object *v;
PyObject *v;
{
struct memberlist *l;
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
#ifdef macintosh
if (l->readonly || l->type == T_STRING || l->type == T_PSTRING) {
if (l->readonly || l->type == T_STRING ||
l->type == T_PSTRING)
{
#else
if (l->readonly || l->type == T_STRING ) {
#endif /* macintosh */
err_setstr(TypeError, "readonly attribute");
PyErr_SetString(PyExc_TypeError,
"readonly attribute");
return -1;
}
if (v == NULL && l->type != T_OBJECT) {
err_setstr(TypeError,
PyErr_SetString(PyExc_TypeError,
"can't delete numeric/char attribute");
return -1;
}
@ -182,90 +190,92 @@ setmember(addr, mlist, name, v)
switch (l->type) {
case T_BYTE:
case T_UBYTE:
if (!is_intobject(v)) {
err_badarg();
if (!PyInt_Check(v)) {
PyErr_BadArgument();
return -1;
}
*(char*)addr = (char) getintvalue(v);
*(char*)addr = (char) PyInt_AsLong(v);
break;
case T_SHORT:
case T_USHORT:
if (!is_intobject(v)) {
err_badarg();
if (!PyInt_Check(v)) {
PyErr_BadArgument();
return -1;
}
*(short*)addr = (short) getintvalue(v);
*(short*)addr = (short) PyInt_AsLong(v);
break;
case T_UINT:
case T_INT:
if (!is_intobject(v)) {
err_badarg();
if (!PyInt_Check(v)) {
PyErr_BadArgument();
return -1;
}
*(int*)addr = (int) getintvalue(v);
*(int*)addr = (int) PyInt_AsLong(v);
break;
case T_LONG:
if (!is_intobject(v)) {
err_badarg();
if (!PyInt_Check(v)) {
PyErr_BadArgument();
return -1;
}
*(long*)addr = getintvalue(v);
*(long*)addr = PyInt_AsLong(v);
break;
case T_ULONG:
if (is_intobject(v))
*(long*)addr = getintvalue(v);
else if (is_longobject(v))
*(long*)addr = getlongvalue(v);
if (PyInt_Check(v))
*(long*)addr = PyInt_AsLong(v);
else if (PyLong_Check(v))
*(long*)addr = PyLong_AsLong(v);
else {
err_badarg();
PyErr_BadArgument();
return -1;
}
break;
case T_FLOAT:
if (is_intobject(v))
*(float*)addr = (float) getintvalue(v);
else if (is_floatobject(v))
if (PyInt_Check(v))
*(float*)addr =
(float) getfloatvalue(v);
(float) PyInt_AsLong(v);
else if (PyFloat_Check(v))
*(float*)addr =
(float) PyFloat_AsDouble(v);
else {
err_badarg();
PyErr_BadArgument();
return -1;
}
break;
case T_DOUBLE:
if (is_intobject(v))
if (PyInt_Check(v))
*(double*)addr =
(double) getintvalue(v);
else if (is_floatobject(v))
*(double*)addr = getfloatvalue(v);
(double) PyInt_AsLong(v);
else if (PyFloat_Check(v))
*(double*)addr = PyFloat_AsDouble(v);
else {
err_badarg();
PyErr_BadArgument();
return -1;
}
break;
case T_OBJECT:
XDECREF(*(object **)addr);
XINCREF(v);
*(object **)addr = v;
Py_XDECREF(*(PyObject **)addr);
Py_XINCREF(v);
*(PyObject **)addr = v;
break;
case T_CHAR:
if (is_stringobject(v) &&
getstringsize(v) == 1) {
if (PyString_Check(v) &&
PyString_Size(v) == 1) {
*(char*)addr =
getstringvalue(v)[0];
PyString_AsString(v)[0];
}
else {
err_badarg();
PyErr_BadArgument();
return -1;
}
default:
err_setstr(SystemError, "bad memberlist type");
PyErr_SetString(PyExc_SystemError,
"bad memberlist type");
return -1;
}
return 0;
}
}
err_setstr(AttributeError, name);
PyErr_SetString(PyExc_AttributeError, name);
return -1;
}