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 Python source (or in an extension) uses ridiculously long names
XXX or riduculously deep nesting in format strings. */ XXX or riduculously deep nesting in format strings. */
#include "allobjects.h" #include "Python.h"
#include <ctype.h> #include <ctype.h>
int getargs PROTO((object *, char *, ...)); int PyArg_Parse Py_PROTO((PyObject *, char *, ...));
int newgetargs PROTO((object *, char *, ...)); int PyArg_ParseTuple Py_PROTO((PyObject *, char *, ...));
int vgetargs PROTO((object *, char *, va_list)); int PyArgs_VaParse Py_PROTO((PyObject *, char *, va_list));
int PyArg_ParseTupleAndKeywords PROTO((object *, object *, int PyArg_ParseTupleAndKeywords Py_PROTO((PyObject *, PyObject *,
char *, char **, ...)); char *, char **, ...));
/* Forward */ /* Forward */
static int vgetargs1 PROTO((object *, char *, va_list *, int)); static int vgetargs1 Py_PROTO((PyObject *, char *, va_list *, int));
static void seterror PROTO((int, char *, int *, char *, char *)); static void seterror Py_PROTO((int, char *, int *, char *, char *));
static char *convertitem PROTO((object *, char **, va_list *, int *, char *)); static char *convertitem Py_PROTO((PyObject *, char **, va_list *,
static char *converttuple PROTO((object *, char **, va_list *, int *, char *));
static char *converttuple Py_PROTO((PyObject *, char **, va_list *,
int *, char *, int)); int *, char *, int));
static char *convertsimple PROTO((object *, char **, va_list *, char *)); static char *convertsimple Py_PROTO((PyObject *, char **, va_list *, char *));
static char *convertsimple1 PROTO((object *, char **, va_list *)); 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 *)); char *, char **, va_list *));
static char *skipitem PROTO((char **, va_list *)); static char *skipitem Py_PROTO((char **, va_list *));
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */ /* VARARGS2 */
int getargs(object *args, char *format, ...) int PyArg_Parse(PyObject *args, char *format, ...)
#else #else
/* VARARGS */ /* VARARGS */
int getargs(va_alist) va_dcl int PyArg_Parse(va_alist) va_dcl
#endif #endif
{ {
int retval; int retval;
@ -75,11 +76,11 @@ int getargs(va_alist) va_dcl
va_start(va, format); va_start(va, format);
#else #else
object *args; PyObject *args;
char *format; char *format;
va_start(va); va_start(va);
args = va_arg(va, object *); args = va_arg(va, PyObject *);
format = va_arg(va, char *); format = va_arg(va, char *);
#endif #endif
retval = vgetargs1(args, format, &va, 1); retval = vgetargs1(args, format, &va, 1);
@ -90,10 +91,10 @@ int getargs(va_alist) va_dcl
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */ /* VARARGS2 */
int newgetargs(object *args, char *format, ...) int PyArg_ParseTuple(PyObject *args, char *format, ...)
#else #else
/* VARARGS */ /* VARARGS */
int newgetargs(va_alist) va_dcl int PyArg_ParseTuple(va_alist) va_dcl
#endif #endif
{ {
int retval; int retval;
@ -102,11 +103,11 @@ int newgetargs(va_alist) va_dcl
va_start(va, format); va_start(va, format);
#else #else
object *args; PyObject *args;
char *format; char *format;
va_start(va); va_start(va);
args = va_arg(va, object *); args = va_arg(va, PyObject *);
format = va_arg(va, char *); format = va_arg(va, char *);
#endif #endif
retval = vgetargs1(args, format, &va, 0); retval = vgetargs1(args, format, &va, 0);
@ -116,8 +117,8 @@ int newgetargs(va_alist) va_dcl
int int
vgetargs(args, format, va) PyArgs_VaParse(args, format, va)
object *args; PyObject *args;
char *format; char *format;
va_list va; va_list va;
{ {
@ -135,7 +136,7 @@ vgetargs(args, format, va)
static int static int
vgetargs1(args, format, p_va, compat) vgetargs1(args, format, p_va, compat)
object *args; PyObject *args;
char *format; char *format;
va_list *p_va; va_list *p_va;
int compat; int compat;
@ -160,7 +161,7 @@ vgetargs1(args, format, p_va, compat)
} }
else if (/* '(' */ c == ')') { else if (/* '(' */ c == ')') {
if (level == 0) if (level == 0)
fatal(/* '(' */ Py_FatalError(/* '(' */
"excess ')' in getargs format"); "excess ')' in getargs format");
else else
level--; level--;
@ -184,7 +185,7 @@ vgetargs1(args, format, p_va, compat)
} }
if (level != 0) if (level != 0)
fatal(/* '(' */ "missing ')' in getargs format"); Py_FatalError(/* '(' */ "missing ')' in getargs format");
if (min < 0) if (min < 0)
min = max; min = max;
@ -197,7 +198,7 @@ vgetargs1(args, format, p_va, compat)
return 1; return 1;
sprintf(msgbuf, "%s requires no arguments", sprintf(msgbuf, "%s requires no arguments",
fname==NULL ? "function" : fname); fname==NULL ? "function" : fname);
err_setstr(TypeError, msgbuf); PyErr_SetString(PyExc_TypeError, msgbuf);
return 0; return 0;
} }
else if (min == 1 && max == 1) { else if (min == 1 && max == 1) {
@ -205,7 +206,7 @@ vgetargs1(args, format, p_va, compat)
sprintf(msgbuf, sprintf(msgbuf,
"%s requires at least one argument", "%s requires at least one argument",
fname==NULL ? "function" : fname); fname==NULL ? "function" : fname);
err_setstr(TypeError, msgbuf); PyErr_SetString(PyExc_TypeError, msgbuf);
return 0; return 0;
} }
msg = convertitem(args, &format, p_va, levels, msgbuf); msg = convertitem(args, &format, p_va, levels, msgbuf);
@ -215,19 +216,19 @@ vgetargs1(args, format, p_va, compat)
return 0; return 0;
} }
else { else {
err_setstr(SystemError, PyErr_SetString(PyExc_SystemError,
"old style getargs format uses new features"); "old style getargs format uses new features");
return 0; return 0;
} }
} }
if (!is_tupleobject(args)) { if (!PyTuple_Check(args)) {
err_setstr(SystemError, PyErr_SetString(PyExc_SystemError,
"new style getargs format but argument is not a tuple"); "new style getargs format but argument is not a tuple");
return 0; return 0;
} }
len = gettuplesize(args); len = PyTuple_Size(args);
if (len < min || max < len) { if (len < min || max < len) {
if (message == NULL) { if (message == NULL) {
@ -241,14 +242,14 @@ vgetargs1(args, format, p_va, compat)
len); len);
message = msgbuf; message = msgbuf;
} }
err_setstr(TypeError, message); PyErr_SetString(PyExc_TypeError, message);
return 0; return 0;
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (*format == '|') if (*format == '|')
format++; format++;
msg = convertitem(gettupleitem(args, i), &format, p_va, msg = convertitem(PyTuple_GetItem(args, i), &format, p_va,
levels, msgbuf); levels, msgbuf);
if (msg) { if (msg) {
seterror(i+1, msg, levels, fname, message); seterror(i+1, msg, levels, fname, message);
@ -273,7 +274,7 @@ seterror(iarg, msg, levels, fname, message)
int i; int i;
char *p = buf; char *p = buf;
if (err_occurred()) if (PyErr_Occurred())
return; return;
if (iarg == 0 && message == NULL) if (iarg == 0 && message == NULL)
message = msg; message = msg;
@ -293,7 +294,7 @@ seterror(iarg, msg, levels, fname, message)
sprintf(p, ": expected %s found", msg); sprintf(p, ": expected %s found", msg);
message = buf; message = buf;
} }
err_setstr(TypeError, message); PyErr_SetString(PyExc_TypeError, message);
} }
@ -318,7 +319,7 @@ seterror(iarg, msg, levels, fname, message)
static char * static char *
converttuple(arg, p_format, p_va, levels, msgbuf, toplevel) converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
object *arg; PyObject *arg;
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
int *levels; int *levels;
@ -348,15 +349,15 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
n++; n++;
} }
if (!is_tupleobject(arg)) { if (!PyTuple_Check(arg)) {
levels[0] = 0; levels[0] = 0;
sprintf(msgbuf, sprintf(msgbuf,
toplevel ? "%d arguments, %s" : "%d-tuple, %s", 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; return msgbuf;
} }
if ((i = gettuplesize(arg)) != n) { if ((i = PyTuple_Size(arg)) != n) {
levels[0] = 0; levels[0] = 0;
sprintf(msgbuf, sprintf(msgbuf,
toplevel ? "%d arguments, %d" : "%d-tuple, %d-tuple", toplevel ? "%d arguments, %d" : "%d-tuple, %d-tuple",
@ -367,7 +368,7 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
format = *p_format; format = *p_format;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
char *msg; char *msg;
msg = convertitem(gettupleitem(arg, i), &format, p_va, msg = convertitem(PyTuple_GetItem(arg, i), &format, p_va,
levels+1, msgbuf); levels+1, msgbuf);
if (msg != NULL) { if (msg != NULL) {
levels[0] = i+1; levels[0] = i+1;
@ -384,7 +385,7 @@ converttuple(arg, p_format, p_va, levels, msgbuf, toplevel)
static char * static char *
convertitem(arg, p_format, p_va, levels, msgbuf) convertitem(arg, p_format, p_va, levels, msgbuf)
object *arg; PyObject *arg;
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
int *levels; int *levels;
@ -415,7 +416,7 @@ convertitem(arg, p_format, p_va, levels, msgbuf)
static char * static char *
convertsimple(arg, p_format, p_va, msgbuf) convertsimple(arg, p_format, p_va, msgbuf)
object *arg; PyObject *arg;
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
char *msgbuf; char *msgbuf;
@ -423,7 +424,7 @@ convertsimple(arg, p_format, p_va, msgbuf)
char *msg = convertsimple1(arg, p_format, p_va); char *msg = convertsimple1(arg, p_format, p_va);
if (msg != NULL) { if (msg != NULL) {
sprintf(msgbuf, "%.50s, %.50s", msg, sprintf(msgbuf, "%.50s, %.50s", msg,
arg == None ? "None" : arg->ob_type->tp_name); arg == Py_None ? "None" : arg->ob_type->tp_name);
msg = msgbuf; msg = msgbuf;
} }
return msg; return msg;
@ -437,7 +438,7 @@ convertsimple(arg, p_format, p_va, msgbuf)
static char * static char *
convertsimple1(arg, p_format, p_va) convertsimple1(arg, p_format, p_va)
object *arg; PyObject *arg;
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
{ {
@ -449,8 +450,8 @@ convertsimple1(arg, p_format, p_va)
case 'b': /* byte -- very short int */ case 'b': /* byte -- very short int */
{ {
char *p = va_arg(*p_va, char *); char *p = va_arg(*p_va, char *);
long ival = getintvalue(arg); long ival = PyInt_AsLong(arg);
if (ival == -1 && err_occurred()) if (ival == -1 && PyErr_Occurred())
return "integer<b>"; return "integer<b>";
else else
*p = (char) ival; *p = (char) ival;
@ -460,8 +461,8 @@ convertsimple1(arg, p_format, p_va)
case 'h': /* short int */ case 'h': /* short int */
{ {
short *p = va_arg(*p_va, short *); short *p = va_arg(*p_va, short *);
long ival = getintvalue(arg); long ival = PyInt_AsLong(arg);
if (ival == -1 && err_occurred()) if (ival == -1 && PyErr_Occurred())
return "integer<h>"; return "integer<h>";
else else
*p = (short) ival; *p = (short) ival;
@ -471,8 +472,8 @@ convertsimple1(arg, p_format, p_va)
case 'i': /* int */ case 'i': /* int */
{ {
int *p = va_arg(*p_va, int *); int *p = va_arg(*p_va, int *);
long ival = getintvalue(arg); long ival = PyInt_AsLong(arg);
if (ival == -1 && err_occurred()) if (ival == -1 && PyErr_Occurred())
return "integer<i>"; return "integer<i>";
else else
*p = ival; *p = ival;
@ -482,8 +483,8 @@ convertsimple1(arg, p_format, p_va)
case 'l': /* long int */ case 'l': /* long int */
{ {
long *p = va_arg(*p_va, long *); long *p = va_arg(*p_va, long *);
long ival = getintvalue(arg); long ival = PyInt_AsLong(arg);
if (ival == -1 && err_occurred()) if (ival == -1 && PyErr_Occurred())
return "integer<l>"; return "integer<l>";
else else
*p = ival; *p = ival;
@ -493,8 +494,8 @@ convertsimple1(arg, p_format, p_va)
case 'f': /* float */ case 'f': /* float */
{ {
float *p = va_arg(*p_va, float *); float *p = va_arg(*p_va, float *);
double dval = getfloatvalue(arg); double dval = PyFloat_AsDouble(arg);
if (err_occurred()) if (PyErr_Occurred())
return "float<f>"; return "float<f>";
else else
*p = (float) dval; *p = (float) dval;
@ -504,8 +505,8 @@ convertsimple1(arg, p_format, p_va)
case 'd': /* double */ case 'd': /* double */
{ {
double *p = va_arg(*p_va, double *); double *p = va_arg(*p_va, double *);
double dval = getfloatvalue(arg); double dval = PyFloat_AsDouble(arg);
if (err_occurred()) if (PyErr_Occurred())
return "float<d>"; return "float<d>";
else else
*p = dval; *p = dval;
@ -518,7 +519,7 @@ convertsimple1(arg, p_format, p_va)
Py_complex *p = va_arg(*p_va, Py_complex *); Py_complex *p = va_arg(*p_va, Py_complex *);
Py_complex cval; Py_complex cval;
cval = PyComplex_AsCComplex(arg); cval = PyComplex_AsCComplex(arg);
if (err_occurred()) if (PyErr_Occurred())
return "complex<D>"; return "complex<D>";
else else
*p = cval; *p = cval;
@ -529,8 +530,8 @@ convertsimple1(arg, p_format, p_va)
case 'c': /* char */ case 'c': /* char */
{ {
char *p = va_arg(*p_va, char *); char *p = va_arg(*p_va, char *);
if (is_stringobject(arg) && getstringsize(arg) == 1) if (PyString_Check(arg) && PyString_Size(arg) == 1)
*p = getstringvalue(arg)[0]; *p = PyString_AsString(arg)[0];
else else
return "char"; return "char";
break; break;
@ -539,16 +540,16 @@ convertsimple1(arg, p_format, p_va)
case 's': /* string */ case 's': /* string */
{ {
char **p = va_arg(*p_va, char **); char **p = va_arg(*p_va, char **);
if (is_stringobject(arg)) if (PyString_Check(arg))
*p = getstringvalue(arg); *p = PyString_AsString(arg);
else else
return "string"; return "string";
if (*format == '#') { if (*format == '#') {
int *q = va_arg(*p_va, int *); int *q = va_arg(*p_va, int *);
*q = getstringsize(arg); *q = PyString_Size(arg);
format++; format++;
} }
else if ((int)strlen(*p) != getstringsize(arg)) else if ((int)strlen(*p) != PyString_Size(arg))
return "string without null bytes"; return "string without null bytes";
break; break;
} }
@ -556,30 +557,30 @@ convertsimple1(arg, p_format, p_va)
case 'z': /* string, may be NULL (None) */ case 'z': /* string, may be NULL (None) */
{ {
char **p = va_arg(*p_va, char **); char **p = va_arg(*p_va, char **);
if (arg == None) if (arg == Py_None)
*p = 0; *p = 0;
else if (is_stringobject(arg)) else if (PyString_Check(arg))
*p = getstringvalue(arg); *p = PyString_AsString(arg);
else else
return "None or string"; return "None or string";
if (*format == '#') { if (*format == '#') {
int *q = va_arg(*p_va, int *); int *q = va_arg(*p_va, int *);
if (arg == None) if (arg == Py_None)
*q = 0; *q = 0;
else else
*q = getstringsize(arg); *q = PyString_Size(arg);
format++; format++;
} }
else if (*p != NULL && else if (*p != NULL &&
(int)strlen(*p) != getstringsize(arg)) (int)strlen(*p) != PyString_Size(arg))
return "None or string without null bytes"; return "None or string without null bytes";
break; break;
} }
case 'S': /* string object */ case 'S': /* string object */
{ {
object **p = va_arg(*p_va, object **); PyObject **p = va_arg(*p_va, PyObject **);
if (is_stringobject(arg)) if (PyString_Check(arg))
*p = arg; *p = arg;
else else
return "string"; return "string";
@ -588,15 +589,15 @@ convertsimple1(arg, p_format, p_va)
case 'O': /* object */ case 'O': /* object */
{ {
typeobject *type; PyTypeObject *type;
object **p; PyObject **p;
if (*format == '!') { if (*format == '!') {
format++; format++;
type = va_arg(*p_va, typeobject*); type = va_arg(*p_va, PyTypeObject*);
if (arg->ob_type != type) if (arg->ob_type != type)
return type->tp_name; return type->tp_name;
else { else {
p = va_arg(*p_va, object **); p = va_arg(*p_va, PyObject **);
*p = arg; *p = arg;
} }
} }
@ -604,13 +605,13 @@ convertsimple1(arg, p_format, p_va)
inquiry pred = va_arg(*p_va, inquiry); inquiry pred = va_arg(*p_va, inquiry);
format++; format++;
if ((*pred)(arg)) { if ((*pred)(arg)) {
p = va_arg(*p_va, object **); p = va_arg(*p_va, PyObject **);
*p = arg; *p = arg;
} }
} }
else if (*format == '&') { else if (*format == '&') {
typedef int (*converter) typedef int (*converter)
PROTO((object *, void *)); Py_PROTO((PyObject *, void *));
converter convert = va_arg(*p_va, converter); converter convert = va_arg(*p_va, converter);
void *addr = va_arg(*p_va, void *); void *addr = va_arg(*p_va, void *);
format++; format++;
@ -618,7 +619,7 @@ convertsimple1(arg, p_format, p_va)
return "(unspecified)"; return "(unspecified)";
} }
else { else {
p = va_arg(*p_va, object **); p = va_arg(*p_va, PyObject **);
*p = arg; *p = arg;
} }
break; break;
@ -639,8 +640,8 @@ convertsimple1(arg, p_format, p_va)
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS2 */ /* VARARGS2 */
int PyArg_ParseTupleAndKeywords(object *args, int PyArg_ParseTupleAndKeywords(PyObject *args,
object *keywords, PyObject *keywords,
char *format, char *format,
char **kwlist, ...) char **kwlist, ...)
#else #else
@ -654,14 +655,14 @@ int PyArg_ParseTupleAndKeywords(va_alist) va_dcl
va_start(va, kwlist); va_start(va, kwlist);
#else #else
object *args; PyObject *args;
object *keywords; PyObject *keywords;
char *format; char *format;
char **kwlist; char **kwlist;
va_start(va); va_start(va);
args = va_arg(va, object *); args = va_arg(va, PyObject *);
keywords = va_arg(va, object *); keywords = va_arg(va, PyObject *);
format = va_arg(va, char *); format = va_arg(va, char *);
kwlist = va_arg(va, char **); kwlist = va_arg(va, char **);
#endif #endif
@ -673,8 +674,8 @@ int PyArg_ParseTupleAndKeywords(va_alist) va_dcl
static int static int
vgetargskeywords(args, keywords, format, kwlist, p_va) vgetargskeywords(args, keywords, format, kwlist, p_va)
object *args; PyObject *args;
object *keywords; PyObject *keywords;
char *format; char *format;
char **kwlist; char **kwlist;
va_list *p_va; va_list *p_va;
@ -689,7 +690,7 @@ vgetargskeywords(args, keywords, format, kwlist, p_va)
int i, len, tplen, kwlen; int i, len, tplen, kwlen;
char *msg, *ks, **p; char *msg, *ks, **p;
int nkwds, pos, match, converted; int nkwds, pos, match, converted;
object *key, *value; PyObject *key, *value;
/* nested tuples cannot be parsed when using keyword arguments */ /* nested tuples cannot be parsed when using keyword arguments */
@ -830,7 +831,7 @@ vgetargskeywords(args, keywords, format, kwlist, p_va)
converted = 0; converted = 0;
for (i = tplen; i < nkwds; i++) { for (i = tplen; i < nkwds; i++) {
object *item; PyObject *item;
if (*format == '|') if (*format == '|')
format++; format++;
item = PyMapping_GetItemString(keywords, kwlist[i]); item = PyMapping_GetItemString(keywords, kwlist[i]);
@ -961,7 +962,7 @@ skipitem(p_format, p_va)
case 'S': /* string object */ case 'S': /* string object */
{ {
(void) va_arg(*p_va, object **); (void) va_arg(*p_va, PyObject **);
break; break;
} }
@ -969,8 +970,8 @@ skipitem(p_format, p_va)
{ {
if (*format == '!') { if (*format == '!') {
format++; format++;
(void) va_arg(*p_va, typeobject*); (void) va_arg(*p_va, PyTypeObject*);
(void) va_arg(*p_va, object **); (void) va_arg(*p_va, PyObject **);
} }
#if 0 #if 0
/* I don't know what this is for */ /* I don't know what this is for */
@ -978,19 +979,19 @@ skipitem(p_format, p_va)
inquiry pred = va_arg(*p_va, inquiry); inquiry pred = va_arg(*p_va, inquiry);
format++; format++;
if ((*pred)(arg)) { if ((*pred)(arg)) {
(void) va_arg(*p_va, object **); (void) va_arg(*p_va, PyObject **);
} }
} }
#endif #endif
else if (*format == '&') { else if (*format == '&') {
typedef int (*converter) typedef int (*converter)
PROTO((object *, void *)); Py_PROTO((PyObject *, void *));
(void) va_arg(*p_va, converter); (void) va_arg(*p_va, converter);
(void) va_arg(*p_va, void *); (void) va_arg(*p_va, void *);
format++; format++;
} }
else { else {
(void) va_arg(*p_va, object **); (void) va_arg(*p_va, PyObject **);
} }
break; 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 */ /* Support for dynamic loading of extension modules */
/* If no dynamic linking is supported, this file still generates some code! */ /* If no dynamic linking is supported, this file still generates some code! */
#include "allobjects.h" #include "Python.h"
#include "osdefs.h" #include "osdefs.h"
#include "importdl.h" #include "importdl.h"
@ -167,7 +167,7 @@ typedef void (*dl_funcptr)();
#ifdef USE_MAC_DYNAMIC_LOADING #ifdef USE_MAC_DYNAMIC_LOADING
#include <Aliases.h> #include <Aliases.h>
#include <CodeFragments.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 CFragConnectionID ConnectionID
#define kLoadCFrag 0x01 #define kLoadCFrag 0x01
#endif #endif
@ -184,7 +184,7 @@ typedef void (*dl_funcptr)();
#endif #endif
#endif /* USE_RLD */ #endif /* USE_RLD */
extern char *getprogramname(); extern char *Py_GetProgramName();
#ifndef FUNCNAME_PATTERN #ifndef FUNCNAME_PATTERN
#if defined(__hp9000s300) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__BORLANDC__) #if defined(__hp9000s300) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__BORLANDC__)
@ -207,9 +207,9 @@ extern char *getprogramname();
#endif #endif
/* Pass it on to import.c */ /* 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 #ifdef SHORT_EXT
{SHORT_EXT, "rb", C_EXTENSION}, {SHORT_EXT, "rb", C_EXTENSION},
#endif /* !SHORT_EXT */ #endif /* !SHORT_EXT */
@ -225,17 +225,18 @@ struct filedescr import_filetab[] = {
#undef DYNAMIC_LINK #undef DYNAMIC_LINK
#endif #endif
object * PyObject *
load_dynamic_module(name, pathname, fp) _PyImport_LoadDynamicModule(name, pathname, fp)
char *name; char *name;
char *pathname; char *pathname;
FILE *fp; FILE *fp;
{ {
#ifndef DYNAMIC_LINK #ifndef DYNAMIC_LINK
err_setstr(ImportError, "dynamically linked modules not supported"); PyErr_SetString(PyExc_ImportError,
"dynamically linked modules not supported");
return NULL; return NULL;
#else #else
object *m, *d, *s; PyObject *m, *d, *s;
char funcname[258]; char funcname[258];
dl_funcptr p = NULL; dl_funcptr p = NULL;
#ifdef USE_SHLIB #ifdef USE_SHLIB
@ -274,11 +275,12 @@ load_dynamic_module(name, pathname, fp)
#endif /* USE_SHLIB */ #endif /* USE_SHLIB */
#ifdef USE_MAC_DYNAMIC_LOADING #ifdef USE_MAC_DYNAMIC_LOADING
/* /*
** Dynamic loading of CFM shared libraries on the Mac. ** Dynamic loading of CFM shared libraries on the Mac. The
** The code has become more convoluted than it was, because we want to be able ** code has become more convoluted than it was, because we
** to put multiple modules in a single file. For this reason, we have to determine ** want to be able to put multiple modules in a single
** the fragment name, and we cannot use the library entry point but we have to locate ** file. For this reason, we have to determine the fragment
** the correct init routine "by hand". ** name, and we cannot use the library entry point but we have
** to locate the correct init routine "by hand".
*/ */
{ {
FSSpec libspec; FSSpec libspec;
@ -297,30 +299,35 @@ load_dynamic_module(name, pathname, fp)
err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething); err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
if ( err ) { if ( err ) {
sprintf(buf, "%s: %s", pathname, PyMac_StrError(err)); sprintf(buf, "%s: %s", pathname, PyMac_StrError(err));
err_setstr(ImportError, buf); PyErr_SetString(PyExc_ImportError, buf);
return NULL; 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]); memcpy(fragname+1, libspec.name+1, libspec.name[0]);
fragname[0] = 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; 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; 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, err = GetDiskFragment(&libspec, 0, 0, fragname,
kLoadCFrag, &connID, &mainAddr, kLoadCFrag, &connID, &mainAddr,
errMessage); errMessage);
if ( err ) { if ( err ) {
sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1, PyMac_StrError(err)); sprintf(buf, "%.*s: %s", errMessage[0], errMessage+1,
err_setstr(ImportError, buf); PyMac_StrError(err));
PyErr_SetString(PyExc_ImportError, buf);
return NULL; return NULL;
} }
/* Locate the address of the correct init function */ /* Locate the address of the correct init function */
err = FindSymbol(connID, Pstring(funcname), &symAddr, &class); err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
if ( err ) { if ( err ) {
sprintf(buf, "%s: %s", funcname, PyMac_StrError(err)); sprintf(buf, "%s: %s", funcname, PyMac_StrError(err));
err_setstr(ImportError, buf); PyErr_SetString(PyExc_ImportError, buf);
return NULL; return NULL;
} }
p = (dl_funcptr)symAddr; p = (dl_funcptr)symAddr;
@ -334,12 +341,12 @@ load_dynamic_module(name, pathname, fp)
void *handle = dlopen(pathname, RTLD_NOW); void *handle = dlopen(pathname, RTLD_NOW);
#else #else
void *handle; void *handle;
if (verbose) if (Py_VerboseFlag)
printf("dlopen(\"%s\", %d);\n", pathname, RTLD_LAZY); printf("dlopen(\"%s\", %d);\n", pathname, RTLD_LAZY);
handle = dlopen(pathname, RTLD_LAZY); handle = dlopen(pathname, RTLD_LAZY);
#endif /* RTLD_NOW */ #endif /* RTLD_NOW */
if (handle == NULL) { if (handle == NULL) {
err_setstr(ImportError, dlerror()); PyErr_SetString(PyExc_ImportError, dlerror());
return NULL; return NULL;
} }
if (fp != NULL && nhandles < 128) if (fp != NULL && nhandles < 128)
@ -382,35 +389,44 @@ load_dynamic_module(name, pathname, fp)
unsigned int errorCode; unsigned int errorCode;
/* Get an error string from Win32 error code */ /* Get an error string from Win32 error code */
char theInfo[256]; /* Pointer to error text from system */ char theInfo[256]; /* Pointer to error text
int theLength; /* Length of error text */ from system */
int theLength; /* Length of error text */
errorCode = GetLastError(); errorCode = GetLastError();
theLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, /* flags */ theLength = FormatMessage(
NULL, /* message source */ FORMAT_MESSAGE_FROM_SYSTEM, /* flags */
errorCode, /* the message (error) ID */ NULL, /* message source */
0, /* default language environment */ errorCode, /* the message (error) ID */
(LPTSTR) theInfo, /* the buffer */ 0, /* default language environment */
sizeof(theInfo), /* the buffer size */ (LPTSTR) theInfo, /* the buffer */
NULL); /* no additional format args. */ 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) { if (theLength == 0) {
sprintf(errBuf, "DLL load failed with error code %d", errorCode); sprintf(errBuf,
"DLL load failed with error code %d",
errorCode);
} else { } else {
int len; int len;
/* For some reason a \r\n is appended to the text */ /* For some reason a \r\n
if (theLength >= 2 && theInfo[theLength-2] == '\r' && theInfo[theLength-1] == '\n') { is appended to the text */
if (theLength >= 2 &&
theInfo[theLength-2] == '\r' &&
theInfo[theLength-1] == '\n') {
theLength -= 2; theLength -= 2;
theInfo[theLength] = '\0'; theInfo[theLength] = '\0';
} }
strcpy(errBuf, "DLL load failed: "); strcpy(errBuf, "DLL load failed: ");
len = strlen(errBuf); len = strlen(errBuf);
strncpy(errBuf+len, theInfo, sizeof(errBuf)-len); strncpy(errBuf+len, theInfo,
sizeof(errBuf)-len);
errBuf[sizeof(errBuf)-1] = '\0'; errBuf[sizeof(errBuf)-1] = '\0';
} }
err_setstr(ImportError, errBuf); PyErr_SetString(PyExc_ImportError, errBuf);
return NULL; return NULL;
} }
p = GetProcAddress(hDLL, funcname); p = GetProcAddress(hDLL, funcname);
@ -422,15 +438,16 @@ load_dynamic_module(name, pathname, fp)
hDLL = LoadLibrary(pathname); hDLL = LoadLibrary(pathname);
if (hDLL < HINSTANCE_ERROR){ if (hDLL < HINSTANCE_ERROR){
char errBuf[256]; char errBuf[256];
sprintf(errBuf, "DLL load failed with error code %d", hDLL); sprintf(errBuf,
err_setstr(ImportError, errBuf); "DLL load failed with error code %d", hDLL);
PyErr_SetString(PyExc_ImportError, errBuf);
return NULL; return NULL;
} }
p = GetProcAddress(hDLL, funcname); p = GetProcAddress(hDLL, funcname);
} }
#endif /* MS_WIN16 */ #endif /* MS_WIN16 */
#ifdef USE_DL #ifdef USE_DL
p = dl_loadmod(getprogramname(), pathname, funcname); p = dl_loadmod(Py_GetProgramName(), pathname, funcname);
#endif /* USE_DL */ #endif /* USE_DL */
#ifdef USE_RLD #ifdef USE_RLD
{ {
@ -455,7 +472,7 @@ load_dynamic_module(name, pathname, fp)
NXGetMemoryBuffer(errorStream, NXGetMemoryBuffer(errorStream,
&streamBuf, &len, &maxLen); &streamBuf, &len, &maxLen);
err_setstr(ImportError, streamBuf); PyErr_SetString(PyExc_ImportError, streamBuf);
} }
if(ret && rld_lookup(errorStream, funcname, &ptr)) if(ret && rld_lookup(errorStream, funcname, &ptr))
@ -473,25 +490,26 @@ load_dynamic_module(name, pathname, fp)
int flags; int flags;
flags = BIND_FIRST | BIND_DEFERRED; 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); printf("shl_load %s\n",pathname);
} }
lib = shl_load(pathname, flags, 0); lib = shl_load(pathname, flags, 0);
if (lib == NULL) if (lib == NULL)
{ {
char buf[256]; char buf[256];
if (verbose) if (Py_VerboseFlag)
perror(pathname); perror(pathname);
sprintf(buf, "Failed to load %.200s", pathname); sprintf(buf, "Failed to load %.200s", pathname);
err_setstr(ImportError, buf); PyErr_SetString(PyExc_ImportError, buf);
return NULL; return NULL;
} }
if (verbose) if (Py_VerboseFlag)
printf("shl_findsym %s\n", funcname); printf("shl_findsym %s\n", funcname);
shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p); shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);
if (p == NULL && verbose) if (p == NULL && Py_VerboseFlag)
perror(funcname); perror(funcname);
} }
#endif /* hpux */ #endif /* hpux */
@ -499,31 +517,31 @@ load_dynamic_module(name, pathname, fp)
got_it: got_it:
#endif #endif
if (p == NULL) { if (p == NULL) {
err_setstr(ImportError, PyErr_SetString(PyExc_ImportError,
"dynamic module does not define init function"); "dynamic module does not define init function");
return NULL; return NULL;
} }
(*p)(); (*p)();
/* XXX Need check for err_occurred() here */ /* XXX Need check for err_occurred() here */
m = dictlookup(import_modules, name); m = PyDict_GetItemString(import_modules, name);
if (m == NULL) { if (m == NULL) {
if (err_occurred() == NULL) if (PyErr_Occurred() == NULL)
err_setstr(SystemError, PyErr_SetString(PyExc_SystemError,
"dynamic module not initialized properly"); "dynamic module not initialized properly");
return NULL; return NULL;
} }
/* Remember the filename as the __file__ attribute */ /* Remember the filename as the __file__ attribute */
d = getmoduledict(m); d = PyModule_GetDict(m);
s = newstringobject(pathname); s = PyString_FromString(pathname);
if (s == NULL || dictinsert(d, "__file__", s) != 0) if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0)
err_clear(); /* Not important enough to report */ PyErr_Clear(); /* Not important enough to report */
XDECREF(s); Py_XDECREF(s);
if (verbose) if (Py_VerboseFlag)
fprintf(stderr, fprintf(stderr,
"import %s # dynamically loaded from %s\n", "import %s # dynamically loaded from %s\n",
name, pathname); name, pathname);
INCREF(m); Py_INCREF(m);
return m; return m;
#endif /* DYNAMIC_LINK */ #endif /* DYNAMIC_LINK */
} }
@ -555,7 +573,7 @@ aix_getoldmodules(modlistptr)
-- Get the list of loaded modules into ld_info structures. -- Get the list of loaded modules into ld_info structures.
*/ */
if ((ldibuf = malloc(bufsize)) == NULL) { if ((ldibuf = malloc(bufsize)) == NULL) {
err_setstr(ImportError, strerror(errno)); PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1; return -1;
} }
while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1 while ((errflag = loadquery(L_GETINFO, ldibuf, bufsize)) == -1
@ -563,12 +581,12 @@ aix_getoldmodules(modlistptr)
free(ldibuf); free(ldibuf);
bufsize += 1024; bufsize += 1024;
if ((ldibuf = malloc(bufsize)) == NULL) { if ((ldibuf = malloc(bufsize)) == NULL) {
err_setstr(ImportError, strerror(errno)); PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1; return -1;
} }
} }
if (errflag == -1) { if (errflag == -1) {
err_setstr(ImportError, strerror(errno)); PyErr_SetString(PyExc_ImportError, strerror(errno));
return -1; return -1;
} }
/* /*
@ -578,7 +596,7 @@ aix_getoldmodules(modlistptr)
prevmodptr = NULL; prevmodptr = NULL;
do { do {
if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) { if ((modptr = (ModulePtr)malloc(sizeof(Module))) == NULL) {
err_setstr(ImportError, strerror(errno)); PyErr_SetString(PyExc_ImportError, strerror(errno));
while (*modlistptr) { while (*modlistptr) {
modptr = (ModulePtr)*modlistptr; modptr = (ModulePtr)*modlistptr;
*modlistptr = (void *)modptr->next; *modlistptr = (void *)modptr->next;
@ -662,7 +680,7 @@ aix_loaderror(pathname)
ERRBUF_APPEND("\n"); ERRBUF_APPEND("\n");
} }
errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */ errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
err_setstr(ImportError, errbuf); PyErr_SetString(PyExc_ImportError, errbuf);
return; return;
} }

View File

@ -40,10 +40,11 @@ extern struct filedescr {
char *suffix; char *suffix;
char *mode; char *mode;
enum filetype type; 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 a true persistent storage facility would be much harder, since
it would have to take circular links and sharing into account. */ it would have to take circular links and sharing into account. */
#include "allobjects.h" #include "Python.h"
#include "modsupport.h"
#include "longintrepr.h" #include "longintrepr.h"
#include "compile.h" #include "compile.h"
#include "marshal.h" #include "marshal.h"
#include <errno.h>
#define TYPE_NULL '0' #define TYPE_NULL '0'
#define TYPE_NONE 'N' #define TYPE_NONE 'N'
#define TYPE_ELLIPSIS '.' #define TYPE_ELLIPSIS '.'
@ -61,7 +58,7 @@ typedef struct {
FILE *fp; FILE *fp;
int error; int error;
/* If fp == NULL, the following are valid: */ /* If fp == NULL, the following are valid: */
object *str; PyObject *str;
char *ptr; char *ptr;
char *end; char *end;
} WFILE; } WFILE;
@ -78,14 +75,15 @@ w_more(c, p)
int size, newsize; int size, newsize;
if (p->str == NULL) if (p->str == NULL)
return; /* An error already occurred */ return; /* An error already occurred */
size = getstringsize(p->str); size = PyString_Size(p->str);
newsize = size + 1024; newsize = size + 1024;
if (resizestring(&p->str, newsize) != 0) { if (_PyString_Resize(&p->str, newsize) != 0) {
p->ptr = p->end = NULL; p->ptr = p->end = NULL;
} }
else { else {
p->ptr = GETSTRINGVALUE((stringobject *)p->str) + size; p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size;
p->end = GETSTRINGVALUE((stringobject *)p->str) + newsize; p->end =
PyString_AS_STRING((PyStringObject *)p->str) + newsize;
*p->ptr++ = c; *p->ptr++ = c;
} }
} }
@ -140,19 +138,19 @@ w_long64(x, p)
static void static void
w_object(v, p) w_object(v, p)
object *v; PyObject *v;
WFILE *p; WFILE *p;
{ {
int i, n; int i, n;
if (v == NULL) if (v == NULL)
w_byte(TYPE_NULL, p); w_byte(TYPE_NULL, p);
else if (v == None) else if (v == Py_None)
w_byte(TYPE_NONE, p); w_byte(TYPE_NONE, p);
else if (v == Py_Ellipsis) else if (v == Py_Ellipsis)
w_byte(TYPE_ELLIPSIS, p); w_byte(TYPE_ELLIPSIS, p);
else if (is_intobject(v)) { else if (PyInt_Check(v)) {
long x = GETINTVALUE((intobject *)v); long x = PyInt_AS_LONG((PyIntObject *)v);
#if SIZEOF_LONG > 4 #if SIZEOF_LONG > 4
long y = x>>31; long y = x>>31;
if (y && y != -1) { if (y && y != -1) {
@ -166,8 +164,8 @@ w_object(v, p)
w_long(x, p); w_long(x, p);
} }
} }
else if (is_longobject(v)) { else if (PyLong_Check(v)) {
longobject *ob = (longobject *)v; PyLongObject *ob = (PyLongObject *)v;
w_byte(TYPE_LONG, p); w_byte(TYPE_LONG, p);
n = ob->ob_size; n = ob->ob_size;
w_long((long)n, p); w_long((long)n, p);
@ -176,77 +174,81 @@ w_object(v, p)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
w_short(ob->ob_digit[i], p); w_short(ob->ob_digit[i], p);
} }
else if (is_floatobject(v)) { else if (PyFloat_Check(v)) {
extern void float_buf_repr PROTO((char *, floatobject *)); extern void PyFloat_AsString
Py_PROTO((char *, PyFloatObject *));
char buf[256]; /* Plenty to format any double */ char buf[256]; /* Plenty to format any double */
float_buf_repr(buf, (floatobject *)v); PyFloat_AsString(buf, (PyFloatObject *)v);
n = strlen(buf); n = strlen(buf);
w_byte(TYPE_FLOAT, p); w_byte(TYPE_FLOAT, p);
w_byte(n, p); w_byte(n, p);
w_string(buf, n, p); w_string(buf, n, p);
} }
#ifndef WITHOUT_COMPLEX #ifndef WITHOUT_COMPLEX
else if (is_complexobject(v)) { else if (PyComplex_Check(v)) {
extern void float_buf_repr PROTO((char *, floatobject *)); extern void PyFloat_AsString
Py_PROTO((char *, PyFloatObject *));
char buf[256]; /* Plenty to format any double */ char buf[256]; /* Plenty to format any double */
floatobject *temp; PyFloatObject *temp;
w_byte(TYPE_COMPLEX, p); w_byte(TYPE_COMPLEX, p);
temp = (floatobject*)newfloatobject(PyComplex_RealAsDouble(v)); temp = (PyFloatObject*)PyFloat_FromDouble(
float_buf_repr(buf, temp); PyComplex_RealAsDouble(v));
DECREF(temp); PyFloat_AsString(buf, temp);
Py_DECREF(temp);
n = strlen(buf); n = strlen(buf);
w_byte(n, p); w_byte(n, p);
w_string(buf, n, p); w_string(buf, n, p);
temp = (floatobject*)newfloatobject(PyComplex_ImagAsDouble(v)); temp = (PyFloatObject*)PyFloat_FromDouble(
float_buf_repr(buf, temp); PyComplex_ImagAsDouble(v));
DECREF(temp); PyFloat_AsString(buf, temp);
Py_DECREF(temp);
n = strlen(buf); n = strlen(buf);
w_byte(n, p); w_byte(n, p);
w_string(buf, n, p); w_string(buf, n, p);
} }
#endif #endif
else if (is_stringobject(v)) { else if (PyString_Check(v)) {
w_byte(TYPE_STRING, p); w_byte(TYPE_STRING, p);
n = getstringsize(v); n = PyString_Size(v);
w_long((long)n, p); 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); w_byte(TYPE_TUPLE, p);
n = gettuplesize(v); n = PyTuple_Size(v);
w_long((long)n, p); w_long((long)n, p);
for (i = 0; i < n; i++) { 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); w_byte(TYPE_LIST, p);
n = getlistsize(v); n = PyList_Size(v);
w_long((long)n, p); w_long((long)n, p);
for (i = 0; i < n; i++) { 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; int pos;
object *key, *value; PyObject *key, *value;
w_byte(TYPE_DICT, p); w_byte(TYPE_DICT, p);
/* This one is NULL object terminated! */ /* This one is NULL object terminated! */
pos = 0; pos = 0;
while (mappinggetnext(v, &pos, &key, &value)) { while (PyDict_Next(v, &pos, &key, &value)) {
w_object(key, p); w_object(key, p);
w_object(value, p); w_object(value, p);
} }
w_object((object *)NULL, p); w_object((PyObject *)NULL, p);
} }
else if (is_codeobject(v)) { else if (PyCode_Check(v)) {
codeobject *co = (codeobject *)v; PyCodeObject *co = (PyCodeObject *)v;
w_byte(TYPE_CODE, p); w_byte(TYPE_CODE, p);
w_short(co->co_argcount, p); w_short(co->co_argcount, p);
w_short(co->co_nlocals, p); w_short(co->co_nlocals, p);
w_short(co->co_stacksize, p); w_short(co->co_stacksize, p);
w_short(co->co_flags, 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_consts, p);
w_object(co->co_names, p); w_object(co->co_names, p);
w_object(co->co_varnames, p); w_object(co->co_varnames, p);
@ -262,7 +264,7 @@ w_object(v, p)
} }
void void
wr_long(x, fp) PyMarshal_WriteLongToFile(x, fp)
long x; long x;
FILE *fp; FILE *fp;
{ {
@ -273,8 +275,8 @@ wr_long(x, fp)
} }
void void
wr_object(x, fp) PyMarshal_WriteObjectToFile(x, fp)
object *x; PyObject *x;
FILE *fp; FILE *fp;
{ {
WFILE wf; WFILE wf;
@ -351,10 +353,10 @@ r_long64(p)
x = (x & 0xFFFFFFFF) | (r_long(p) << 32); x = (x & 0xFFFFFFFF) | (r_long(p) << 32);
#else #else
if (r_long(p) != 0) { if (r_long(p) != 0) {
object *f = sysget("stderr"); PyObject *f = PySys_GetObject("stderr");
err_clear(); PyErr_Clear();
if (f != NULL) if (f != NULL)
writestring( PyFile_WriteString(
"Warning: un-marshal 64-bit int in 32-bit mode\n", "Warning: un-marshal 64-bit int in 32-bit mode\n",
f); f);
} }
@ -362,60 +364,61 @@ r_long64(p)
return x; return x;
} }
static object * static PyObject *
r_object(p) r_object(p)
RFILE *p; RFILE *p;
{ {
object *v, *v2; PyObject *v, *v2;
long i, n; long i, n;
int type = r_byte(p); int type = r_byte(p);
switch (type) { switch (type) {
case EOF: case EOF:
err_setstr(EOFError, "EOF read where object expected"); PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
return NULL; return NULL;
case TYPE_NULL: case TYPE_NULL:
return NULL; return NULL;
case TYPE_NONE: case TYPE_NONE:
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
case TYPE_ELLIPSIS: case TYPE_ELLIPSIS:
INCREF(Py_Ellipsis); Py_INCREF(Py_Ellipsis);
return Py_Ellipsis; return Py_Ellipsis;
case TYPE_INT: case TYPE_INT:
return newintobject(r_long(p)); return PyInt_FromLong(r_long(p));
case TYPE_INT64: case TYPE_INT64:
return newintobject(r_long64(p)); return PyInt_FromLong(r_long64(p));
case TYPE_LONG: case TYPE_LONG:
{ {
int size; int size;
longobject *ob; PyLongObject *ob;
n = r_long(p); n = r_long(p);
size = n<0 ? -n : n; size = n<0 ? -n : n;
ob = alloclongobject(size); ob = _PyLong_New(size);
if (ob == NULL) if (ob == NULL)
return NULL; return NULL;
ob->ob_size = n; ob->ob_size = n;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
ob->ob_digit[i] = r_short(p); ob->ob_digit[i] = r_short(p);
return (object *)ob; return (PyObject *)ob;
} }
case TYPE_FLOAT: case TYPE_FLOAT:
{ {
extern double atof PROTO((const char *)); extern double atof Py_PROTO((const char *));
char buf[256]; char buf[256];
double dx; double dx;
n = r_byte(p); n = r_byte(p);
if (r_string(buf, (int)n, p) != n) { if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError, PyErr_SetString(PyExc_EOFError,
"EOF read where object expected"); "EOF read where object expected");
return NULL; return NULL;
} }
@ -423,18 +426,18 @@ r_object(p)
PyFPE_START_PROTECT("atof", return 0) PyFPE_START_PROTECT("atof", return 0)
dx = atof(buf); dx = atof(buf);
PyFPE_END_PROTECT(dx) PyFPE_END_PROTECT(dx)
return newfloatobject(dx); return PyFloat_FromDouble(dx);
} }
#ifndef WITHOUT_COMPLEX #ifndef WITHOUT_COMPLEX
case TYPE_COMPLEX: case TYPE_COMPLEX:
{ {
extern double atof PROTO((const char *)); extern double atof Py_PROTO((const char *));
char buf[256]; char buf[256];
Py_complex c; Py_complex c;
n = r_byte(p); n = r_byte(p);
if (r_string(buf, (int)n, p) != n) { if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError, PyErr_SetString(PyExc_EOFError,
"EOF read where object expected"); "EOF read where object expected");
return NULL; return NULL;
} }
@ -444,7 +447,7 @@ r_object(p)
PyFPE_END_PROTECT(c) PyFPE_END_PROTECT(c)
n = r_byte(p); n = r_byte(p);
if (r_string(buf, (int)n, p) != n) { if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError, PyErr_SetString(PyExc_EOFError,
"EOF read where object expected"); "EOF read where object expected");
return NULL; return NULL;
} }
@ -452,18 +455,18 @@ r_object(p)
PyFPE_START_PROTECT("atof", return 0) PyFPE_START_PROTECT("atof", return 0)
c.imag = atof(buf); c.imag = atof(buf);
PyFPE_END_PROTECT(c) PyFPE_END_PROTECT(c)
return newcomplexobject(c); return PyComplex_FromCComplex(c);
} }
#endif #endif
case TYPE_STRING: case TYPE_STRING:
n = r_long(p); n = r_long(p);
v = newsizedstringobject((char *)NULL, n); v = PyString_FromStringAndSize((char *)NULL, n);
if (v != NULL) { if (v != NULL) {
if (r_string(getstringvalue(v), (int)n, p) != n) { if (r_string(PyString_AsString(v), (int)n, p) != n) {
DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
err_setstr(EOFError, PyErr_SetString(PyExc_EOFError,
"EOF read where object expected"); "EOF read where object expected");
} }
} }
@ -471,50 +474,50 @@ r_object(p)
case TYPE_TUPLE: case TYPE_TUPLE:
n = r_long(p); n = r_long(p);
v = newtupleobject((int)n); v = PyTuple_New((int)n);
if (v == NULL) if (v == NULL)
return v; return v;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
v2 = r_object(p); v2 = r_object(p);
if ( v2 == NULL ) { if ( v2 == NULL ) {
DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
break; break;
} }
SETTUPLEITEM(v, (int)i, v2); PyTuple_SET_ITEM(v, (int)i, v2);
} }
return v; return v;
case TYPE_LIST: case TYPE_LIST:
n = r_long(p); n = r_long(p);
v = newlistobject((int)n); v = PyList_New((int)n);
if (v == NULL) if (v == NULL)
return v; return v;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
v2 = r_object(p); v2 = r_object(p);
if ( v2 == NULL ) { if ( v2 == NULL ) {
DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
break; break;
} }
setlistitem(v, (int)i, v2); PyList_SetItem(v, (int)i, v2);
} }
return v; return v;
case TYPE_DICT: case TYPE_DICT:
v = newdictobject(); v = PyDict_New();
if (v == NULL) if (v == NULL)
return NULL; return NULL;
for (;;) { for (;;) {
object *key, *val; PyObject *key, *val;
key = r_object(p); key = r_object(p);
if (key == NULL) if (key == NULL)
break; /* XXX Assume TYPE_NULL, not an error */ break; /* XXX Assume TYPE_NULL, not an error */
val = r_object(p); val = r_object(p);
if (val != NULL) if (val != NULL)
dict2insert(v, key, val); PyDict_SetItem(v, key, val);
DECREF(key); Py_DECREF(key);
XDECREF(val); Py_XDECREF(val);
} }
return v; return v;
@ -524,14 +527,14 @@ r_object(p)
int nlocals = r_short(p); int nlocals = r_short(p);
int stacksize = r_short(p); int stacksize = r_short(p);
int flags = r_short(p); int flags = r_short(p);
object *code = NULL; PyObject *code = NULL;
object *consts = NULL; PyObject *consts = NULL;
object *names = NULL; PyObject *names = NULL;
object *varnames = NULL; PyObject *varnames = NULL;
object *filename = NULL; PyObject *filename = NULL;
object *name = NULL; PyObject *name = NULL;
int firstlineno = 0; int firstlineno = 0;
object *lnotab = NULL; PyObject *lnotab = NULL;
code = r_object(p); code = r_object(p);
if (code) consts = r_object(p); if (code) consts = r_object(p);
@ -544,20 +547,20 @@ r_object(p)
lnotab = r_object(p); lnotab = r_object(p);
} }
if (!err_occurred()) { if (!PyErr_Occurred()) {
v = (object *) newcodeobject( v = (PyObject *) PyCode_New(
argcount, nlocals, stacksize, flags, argcount, nlocals, stacksize, flags,
code, consts, names, varnames, code, consts, names, varnames,
filename, name, firstlineno, lnotab); filename, name, firstlineno, lnotab);
} }
else else
v = NULL; v = NULL;
XDECREF(code); Py_XDECREF(code);
XDECREF(consts); Py_XDECREF(consts);
XDECREF(names); Py_XDECREF(names);
XDECREF(varnames); Py_XDECREF(varnames);
XDECREF(filename); Py_XDECREF(filename);
XDECREF(name); Py_XDECREF(name);
} }
return v; return v;
@ -565,14 +568,14 @@ r_object(p)
default: default:
/* Bogus data got written, which isn't ideal. /* Bogus data got written, which isn't ideal.
This will let you keep working and recover. */ This will let you keep working and recover. */
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
} }
long long
rd_long(fp) PyMarshal_ReadLongFromFile(fp)
FILE *fp; FILE *fp;
{ {
RFILE rf; RFILE rf;
@ -580,13 +583,12 @@ rd_long(fp)
return r_long(&rf); return r_long(&rf);
} }
object * PyObject *
rd_object(fp) PyMarshal_ReadObjectFromFile(fp)
FILE *fp; FILE *fp;
{ {
RFILE rf; RFILE rf;
if (err_occurred()) { if (PyErr_Occurred()) {
fatal("XXX rd_object called with exception set"); /* tmp */
fprintf(stderr, "XXX rd_object called with exception set\n"); fprintf(stderr, "XXX rd_object called with exception set\n");
return NULL; return NULL;
} }
@ -594,13 +596,13 @@ rd_object(fp)
return r_object(&rf); return r_object(&rf);
} }
object * PyObject *
rds_object(str, len) PyMarshal_ReadObjectFromString(str, len)
char *str; char *str;
int len; int len;
{ {
RFILE rf; RFILE rf;
if (err_occurred()) { if (PyErr_Occurred()) {
fprintf(stderr, "XXX rds_object called with exception set\n"); fprintf(stderr, "XXX rds_object called with exception set\n");
return NULL; return NULL;
} }
@ -611,25 +613,26 @@ rds_object(str, len)
return r_object(&rf); return r_object(&rf);
} }
object * PyObject *
PyMarshal_WriteObjectToString(x) /* wrs_object() */ PyMarshal_WriteObjectToString(x) /* wrs_object() */
object *x; PyObject *x;
{ {
WFILE wf; WFILE wf;
wf.fp = NULL; wf.fp = NULL;
wf.str = newsizedstringobject((char *)NULL, 50); wf.str = PyString_FromStringAndSize((char *)NULL, 50);
if (wf.str == NULL) if (wf.str == NULL)
return NULL; return NULL;
wf.ptr = GETSTRINGVALUE((stringobject *)wf.str); wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str);
wf.end = wf.ptr + getstringsize(wf.str); wf.end = wf.ptr + PyString_Size(wf.str);
wf.error = 0; wf.error = 0;
w_object(x, &wf); w_object(x, &wf);
if (wf.str != NULL) if (wf.str != NULL)
resizestring(&wf.str, _PyString_Resize(&wf.str,
(int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str))); (int) (wf.ptr -
PyString_AS_STRING((PyStringObject *)wf.str)));
if (wf.error) { if (wf.error) {
XDECREF(wf.str); Py_XDECREF(wf.str);
err_setstr(ValueError, "unmarshallable object"); PyErr_SetString(PyExc_ValueError, "unmarshallable object");
return NULL; return NULL;
} }
return wf.str; return wf.str;
@ -637,95 +640,97 @@ PyMarshal_WriteObjectToString(x) /* wrs_object() */
/* And an interface for Python programs... */ /* And an interface for Python programs... */
static object * static PyObject *
marshal_dump(self, args) marshal_dump(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
WFILE wf; WFILE wf;
object *x; PyObject *x;
object *f; PyObject *f;
if (!getargs(args, "(OO)", &x, &f)) if (!PyArg_Parse(args, "(OO)", &x, &f))
return NULL; return NULL;
if (!is_fileobject(f)) { if (!PyFile_Check(f)) {
err_setstr(TypeError, "marshal.dump() 2nd arg must be file"); PyErr_SetString(PyExc_TypeError,
"marshal.dump() 2nd arg must be file");
return NULL; return NULL;
} }
wf.fp = getfilefile(f); wf.fp = PyFile_AsFile(f);
wf.str = NULL; wf.str = NULL;
wf.ptr = wf.end = NULL; wf.ptr = wf.end = NULL;
wf.error = 0; wf.error = 0;
w_object(x, &wf); w_object(x, &wf);
if (wf.error) { if (wf.error) {
err_setstr(ValueError, "unmarshallable object"); PyErr_SetString(PyExc_ValueError, "unmarshallable object");
return NULL; return NULL;
} }
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
marshal_load(self, args) marshal_load(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
RFILE rf; RFILE rf;
object *f; PyObject *f;
object *v; PyObject *v;
if (!getargs(args, "O", &f)) if (!PyArg_Parse(args, "O", &f))
return NULL; return NULL;
if (!is_fileobject(f)) { if (!PyFile_Check(f)) {
err_setstr(TypeError, "marshal.load() arg must be file"); PyErr_SetString(PyExc_TypeError,
"marshal.load() arg must be file");
return NULL; return NULL;
} }
rf.fp = getfilefile(f); rf.fp = PyFile_AsFile(f);
rf.str = NULL; rf.str = NULL;
rf.ptr = rf.end = NULL; rf.ptr = rf.end = NULL;
err_clear(); PyErr_Clear();
v = r_object(&rf); v = r_object(&rf);
if (err_occurred()) { if (PyErr_Occurred()) {
XDECREF(v); Py_XDECREF(v);
v = NULL; v = NULL;
} }
return v; return v;
} }
static object * static PyObject *
marshal_dumps(self, args) marshal_dumps(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
object *x; PyObject *x;
if (!getargs(args, "O", &x)) if (!PyArg_Parse(args, "O", &x))
return NULL; return NULL;
return PyMarshal_WriteObjectToString(x); return PyMarshal_WriteObjectToString(x);
} }
static object * static PyObject *
marshal_loads(self, args) marshal_loads(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
RFILE rf; RFILE rf;
object *v; PyObject *v;
char *s; char *s;
int n; int n;
if (!getargs(args, "s#", &s, &n)) if (!PyArg_Parse(args, "s#", &s, &n))
return NULL; return NULL;
rf.fp = NULL; rf.fp = NULL;
rf.str = args; rf.str = args;
rf.ptr = s; rf.ptr = s;
rf.end = s + n; rf.end = s + n;
err_clear(); PyErr_Clear();
v = r_object(&rf); v = r_object(&rf);
if (err_occurred()) { if (PyErr_Occurred()) {
XDECREF(v); Py_XDECREF(v);
v = NULL; v = NULL;
} }
return v; return v;
} }
static struct methodlist marshal_methods[] = { static PyMethodDef marshal_methods[] = {
{"dump", marshal_dump}, {"dump", marshal_dump},
{"load", marshal_load}, {"load", marshal_load},
{"dumps", marshal_dumps}, {"dumps", marshal_dumps},
@ -734,7 +739,7 @@ static struct methodlist marshal_methods[] = {
}; };
void 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 */ /* Module support implementation */
#include "allobjects.h" #include "Python.h"
#include "import.h"
#ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */ #ifdef MPW /* MPW pushes 'extended' for float and double types with varargs */
typedef extended va_double; typedef extended va_double;
@ -53,37 +52,39 @@ static char api_version_warning[] =
"WARNING: Python C API version mismatch for module %s:\n\ "WARNING: Python C API version mismatch for module %s:\n\
This Python has API version %d, module %s has version %d.\n"; This Python has API version %d, module %s has version %d.\n";
object * PyObject *
initmodule4(name, methods, doc, passthrough, module_api_version) Py_InitModule4(name, methods, doc, passthrough, module_api_version)
char *name; char *name;
struct methodlist *methods; PyMethodDef *methods;
char *doc; char *doc;
object *passthrough; PyObject *passthrough;
int module_api_version; int module_api_version;
{ {
object *m, *d, *v; PyObject *m, *d, *v;
struct methodlist *ml; PyMethodDef *ml;
if (module_api_version != PYTHON_API_VERSION) if (module_api_version != PYTHON_API_VERSION)
fprintf(stderr, api_version_warning, fprintf(stderr, api_version_warning,
name, PYTHON_API_VERSION, name, module_api_version); 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); 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++) { for (ml = methods; ml->ml_name != NULL; ml++) {
v = newmethodobject(ml, passthrough); v = PyCFunction_New(ml, passthrough);
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) { if (v == NULL ||
PyDict_SetItemString(d, ml->ml_name, v) != 0)
{
fprintf(stderr, "initializing module: %s\n", name); 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) { if (doc != NULL) {
v = newstringobject(doc); v = PyString_FromString(doc);
if (v == NULL || dictinsert(d, "__doc__", v) != 0) if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0)
fatal("can't add doc string"); Py_FatalError("can't add doc string");
DECREF(v); Py_DECREF(v);
} }
return m; return m;
} }
@ -91,7 +92,7 @@ initmodule4(name, methods, doc, passthrough, module_api_version)
/* Helper for mkvalue() to scan the length of a format */ /* 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) static int countformat(format, endchar)
char *format; char *format;
int endchar; int endchar;
@ -102,7 +103,8 @@ static int countformat(format, endchar)
switch (*format) { switch (*format) {
case '\0': case '\0':
/* Premature end */ /* Premature end */
err_setstr(SystemError, "unmatched paren in format"); PyErr_SetString(PyExc_SystemError,
"unmatched paren in format");
return -1; return -1;
case '(': case '(':
case '[': case '[':
@ -136,118 +138,121 @@ static int countformat(format, endchar)
/* Generic function to create a value -- the inverse of getargs() */ /* Generic function to create a value -- the inverse of getargs() */
/* After an original idea and first implementation by Steven Miale */ /* After an original idea and first implementation by Steven Miale */
static object *do_mktuple PROTO((char**, va_list *, int, int)); static PyObject *do_mktuple Py_PROTO((char**, va_list *, int, int));
static object *do_mklist PROTO((char**, va_list *, int, int)); static PyObject *do_mklist Py_PROTO((char**, va_list *, int, int));
static object *do_mkdict PROTO((char**, va_list *, int, int)); static PyObject *do_mkdict Py_PROTO((char**, va_list *, int, int));
static object *do_mkvalue PROTO((char**, va_list *)); static PyObject *do_mkvalue Py_PROTO((char**, va_list *));
static object * static PyObject *
do_mkdict(p_format, p_va, endchar, n) do_mkdict(p_format, p_va, endchar, n)
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
int endchar; int endchar;
int n; int n;
{ {
object *d; PyObject *d;
int i; int i;
if (n < 0) if (n < 0)
return NULL; return NULL;
if ((d = newdictobject()) == NULL) if ((d = PyDict_New()) == NULL)
return NULL; return NULL;
for (i = 0; i < n; i+= 2) { for (i = 0; i < n; i+= 2) {
object *k, *v; PyObject *k, *v;
k = do_mkvalue(p_format, p_va); k = do_mkvalue(p_format, p_va);
if (k == NULL) { if (k == NULL) {
DECREF(d); Py_DECREF(d);
return NULL; return NULL;
} }
v = do_mkvalue(p_format, p_va); v = do_mkvalue(p_format, p_va);
if (v == NULL) { if (v == NULL) {
DECREF(k); Py_DECREF(k);
DECREF(d); Py_DECREF(d);
return NULL; return NULL;
} }
if (dict2insert(d, k, v) < 0) { if (PyDict_SetItem(d, k, v) < 0) {
DECREF(k); Py_DECREF(k);
DECREF(v); Py_DECREF(v);
DECREF(d); Py_DECREF(d);
return NULL; return NULL;
} }
} }
if (d != NULL && **p_format != endchar) { if (d != NULL && **p_format != endchar) {
DECREF(d); Py_DECREF(d);
d = NULL; d = NULL;
err_setstr(SystemError, "Unmatched paren in format"); PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
} }
else if (endchar) else if (endchar)
++*p_format; ++*p_format;
return d; return d;
} }
static object * static PyObject *
do_mklist(p_format, p_va, endchar, n) do_mklist(p_format, p_va, endchar, n)
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
int endchar; int endchar;
int n; int n;
{ {
object *v; PyObject *v;
int i; int i;
if (n < 0) if (n < 0)
return NULL; return NULL;
if ((v = newlistobject(n)) == NULL) if ((v = PyList_New(n)) == NULL)
return NULL; return NULL;
for (i = 0; i < n; i++) { 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) { if (w == NULL) {
DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
setlistitem(v, i, w); PyList_SetItem(v, i, w);
} }
if (v != NULL && **p_format != endchar) { if (v != NULL && **p_format != endchar) {
DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
err_setstr(SystemError, "Unmatched paren in format"); PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
} }
else if (endchar) else if (endchar)
++*p_format; ++*p_format;
return v; return v;
} }
static object * static PyObject *
do_mktuple(p_format, p_va, endchar, n) do_mktuple(p_format, p_va, endchar, n)
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
int endchar; int endchar;
int n; int n;
{ {
object *v; PyObject *v;
int i; int i;
if (n < 0) if (n < 0)
return NULL; return NULL;
if ((v = newtupleobject(n)) == NULL) if ((v = PyTuple_New(n)) == NULL)
return NULL; return NULL;
for (i = 0; i < n; i++) { 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) { if (w == NULL) {
DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
settupleitem(v, i, w); PyTuple_SetItem(v, i, w);
} }
if (v != NULL && **p_format != endchar) { if (v != NULL && **p_format != endchar) {
DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
err_setstr(SystemError, "Unmatched paren in format"); PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
} }
else if (endchar) else if (endchar)
++*p_format; ++*p_format;
return v; return v;
} }
static object * static PyObject *
do_mkvalue(p_format, p_va) do_mkvalue(p_format, p_va)
char **p_format; char **p_format;
va_list *p_va; va_list *p_va;
@ -269,26 +274,27 @@ do_mkvalue(p_format, p_va)
case 'b': case 'b':
case 'h': case 'h':
case 'i': case 'i':
return newintobject((long)va_arg(*p_va, int)); return PyInt_FromLong((long)va_arg(*p_va, int));
case 'l': case 'l':
return newintobject((long)va_arg(*p_va, long)); return PyInt_FromLong((long)va_arg(*p_va, long));
case 'f': case 'f':
case 'd': case 'd':
return newfloatobject((double)va_arg(*p_va, va_double)); return PyFloat_FromDouble(
(double)va_arg(*p_va, va_double));
case 'c': case 'c':
{ {
char p[1]; char p[1];
p[0] = va_arg(*p_va, int); p[0] = va_arg(*p_va, int);
return newsizedstringobject(p, 1); return PyString_FromStringAndSize(p, 1);
} }
case 's': case 's':
case 'z': case 'z':
{ {
object *v; PyObject *v;
char *str = va_arg(*p_va, char *); char *str = va_arg(*p_va, char *);
int n; int n;
if (**p_format == '#') { if (**p_format == '#') {
@ -298,13 +304,13 @@ do_mkvalue(p_format, p_va)
else else
n = -1; n = -1;
if (str == NULL) { if (str == NULL) {
v = None; v = Py_None;
INCREF(v); Py_INCREF(v);
} }
else { else {
if (n < 0) if (n < 0)
n = strlen(str); n = strlen(str);
v = newsizedstringobject(str, n); v = PyString_FromStringAndSize(str, n);
} }
return v; return v;
} }
@ -312,18 +318,18 @@ do_mkvalue(p_format, p_va)
case 'S': case 'S':
case 'O': case 'O':
if (**p_format == '&') { if (**p_format == '&') {
typedef object *(*converter) PROTO((void *)); typedef PyObject *(*converter) Py_PROTO((void *));
converter func = va_arg(*p_va, converter); converter func = va_arg(*p_va, converter);
void *arg = va_arg(*p_va, void *); void *arg = va_arg(*p_va, void *);
++*p_format; ++*p_format;
return (*func)(arg); return (*func)(arg);
} }
else { else {
object *v; PyObject *v;
v = va_arg(*p_va, object *); v = va_arg(*p_va, PyObject *);
if (v != NULL) if (v != NULL)
INCREF(v); Py_INCREF(v);
else if (!err_occurred()) else if (!PyErr_Occurred())
/* If a NULL was passed /* If a NULL was passed
* because a call that should * because a call that should
* have constructed a value * have constructed a value
@ -332,7 +338,7 @@ do_mkvalue(p_format, p_va)
* no error occurred it's not * no error occurred it's not
* clear that the caller knew * clear that the caller knew
* what she was doing. */ * what she was doing. */
err_setstr(SystemError, PyErr_SetString(PyExc_SystemError,
"NULL object passed to mkvalue"); "NULL object passed to mkvalue");
return v; return v;
} }
@ -344,7 +350,7 @@ do_mkvalue(p_format, p_va)
break; break;
default: default:
err_setstr(SystemError, PyErr_SetString(PyExc_SystemError,
"bad format char passed to mkvalue"); "bad format char passed to mkvalue");
return NULL; return NULL;
@ -355,14 +361,14 @@ do_mkvalue(p_format, p_va)
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
/* VARARGS 2 */ /* VARARGS 2 */
object *mkvalue(char *format, ...) PyObject *Py_BuildValue(char *format, ...)
#else #else
/* VARARGS */ /* VARARGS */
object *mkvalue(va_alist) va_dcl PyObject *Py_BuildValue(va_alist) va_dcl
#endif #endif
{ {
va_list va; va_list va;
object* retval; PyObject* retval;
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
va_start(va, format); va_start(va, format);
#else #else
@ -370,13 +376,13 @@ object *mkvalue(va_alist) va_dcl
va_start(va); va_start(va);
format = va_arg(va, char *); format = va_arg(va, char *);
#endif #endif
retval = vmkvalue(format, va); retval = Py_VaBuildValue(format, va);
va_end(va); va_end(va);
return retval; return retval;
} }
object * PyObject *
vmkvalue(format, va) Py_VaBuildValue(format, va)
char *format; char *format;
va_list va; va_list va;
{ {
@ -393,8 +399,8 @@ vmkvalue(format, va)
if (n < 0) if (n < 0)
return NULL; return NULL;
if (n == 0) { if (n == 0) {
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
if (n == 1) if (n == 1)
return do_mkvalue(&f, &lva); return do_mkvalue(&f, &lva);
@ -403,19 +409,19 @@ vmkvalue(format, va)
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
object * PyObject *
PyEval_CallFunction(object *obj, char *format, ...) PyEval_CallFunction(PyObject *obj, char *format, ...)
#else #else
object * PyObject *
PyEval_CallFunction(obj, format, va_alist) PyEval_CallFunction(obj, format, va_alist)
object *obj; PyObject *obj;
char *format; char *format;
va_dcl va_dcl
#endif #endif
{ {
va_list vargs; va_list vargs;
object *args; PyObject *args;
object *res; PyObject *res;
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, format); va_start(vargs, format);
@ -423,37 +429,37 @@ PyEval_CallFunction(obj, format, va_alist)
va_start(vargs); va_start(vargs);
#endif #endif
args = vmkvalue(format, vargs); args = Py_VaBuildValue(format, vargs);
va_end(vargs); va_end(vargs);
if (args == NULL) if (args == NULL)
return NULL; return NULL;
res = call_object(obj, args); res = PyEval_CallObject(obj, args);
DECREF(args); Py_DECREF(args);
return res; return res;
} }
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
object * PyObject *
PyEval_CallMethod(object *obj, char *methonname, char *format, ...) PyEval_CallMethod(PyObject *obj, char *methonname, char *format, ...)
#else #else
object * PyObject *
PyEval_CallMethod(obj, methonname, format, va_alist) PyEval_CallMethod(obj, methonname, format, va_alist)
object *obj; PyObject *obj;
char *methonname; char *methonname;
char *format; char *format;
va_dcl va_dcl
#endif #endif
{ {
va_list vargs; va_list vargs;
object *meth; PyObject *meth;
object *args; PyObject *args;
object *res; PyObject *res;
meth = getattr(obj, methonname); meth = PyObject_GetAttrString(obj, methonname);
if (meth == NULL) if (meth == NULL)
return NULL; return NULL;
@ -463,17 +469,17 @@ PyEval_CallMethod(obj, methonname, format, va_alist)
va_start(vargs); va_start(vargs);
#endif #endif
args = vmkvalue(format, vargs); args = Py_VaBuildValue(format, vargs);
va_end(vargs); va_end(vargs);
if (args == NULL) { if (args == NULL) {
DECREF(meth); Py_DECREF(meth);
return NULL; return NULL;
} }
res = call_object(meth, args); res = PyEval_CallObject(meth, args);
DECREF(meth); Py_DECREF(meth);
DECREF(args); Py_DECREF(args);
return res; return res;
} }

View File

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

View File

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