[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.221,2.222 ceval.c,2.262,2.263 exceptions.c,1.24,1.25 import.c,2.180,2.181 pythonrun.c,2.139,2.140

Tim Peters tim_one@users.sourceforge.net
2001年8月01日 21:15:03 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv8810/python/dist/src/Python
Modified Files:
	bltinmodule.c ceval.c exceptions.c import.c pythonrun.c 
Log Message:
Merge of descr-branch back into trunk.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.221
retrieving revision 2.222
diff -C2 -d -r2.221 -r2.222
*** bltinmodule.c	2001年07月30日 22:45:19	2.221
--- bltinmodule.c	2001年08月02日 04:15:00	2.222
***************
*** 133,156 ****
 
 static PyObject *
- builtin_unicode(PyObject *self, PyObject *args)
- {
- PyObject *v;
- 	char *encoding = NULL;
- 	char *errors = NULL;
- 
- 	if ( !PyArg_ParseTuple(args, "O|ss:unicode", &v, &encoding, &errors) )
- 	 return NULL;
- 	return PyUnicode_FromEncodedObject(v, encoding, errors);
- }
- 
- static char unicode_doc[] =
- "unicode(string [, encoding[, errors]]) -> object\n\
- \n\
- Create a new Unicode object from the given encoded string.\n\
- encoding defaults to the current default string encoding and \n\
- errors, defining the error handling, to 'strict'.";
- 
- 
- static PyObject *
 builtin_callable(PyObject *self, PyObject *args)
 {
--- 133,136 ----
***************
*** 436,691 ****
 
 
- #ifndef WITHOUT_COMPLEX
- 
- static PyObject *
- complex_from_string(PyObject *v)
- {
- 	extern double strtod(const char *, char **);
- 	const char *s, *start;
- 	char *end;
- 	double x=0.0, y=0.0, z;
- 	int got_re=0, got_im=0, done=0;
- 	int digit_or_dot;
- 	int sw_error=0;
- 	int sign;
- 	char buffer[256]; /* For errors */
- 	char s_buffer[256];
- 	int len;
- 
- 	if (PyString_Check(v)) {
- 		s = PyString_AS_STRING(v);
- 		len = PyString_GET_SIZE(v);
- 	}
- 	else if (PyUnicode_Check(v)) {
- 		if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
- 			PyErr_SetString(PyExc_ValueError,
- 				 "complex() literal too large to convert");
- 			return NULL;
- 		}
- 		if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
- 					 PyUnicode_GET_SIZE(v),
- 					 s_buffer,
- 					 NULL))
- 			return NULL;
- 		s = s_buffer;
- 		len = (int)strlen(s);
- 	}
- 	else if (PyObject_AsCharBuffer(v, &s, &len)) {
- 		PyErr_SetString(PyExc_TypeError,
- 				"complex() arg is not a string");
- 		return NULL;
- 	}
- 
- 	/* position on first nonblank */
- 	start = s;
- 	while (*s && isspace(Py_CHARMASK(*s)))
- 		s++;
- 	if (s[0] == '0円') {
- 		PyErr_SetString(PyExc_ValueError,
- 				"complex() arg is an empty string");
- 		return NULL;
- 	}
- 
- 	z = -1.0;
- 	sign = 1;
- 	do {
- 
- 		switch (*s) {
- 
- 		case '0円':
- 			if (s-start != len) {
- 				PyErr_SetString(
- 					PyExc_ValueError,
- 					"complex() arg contains a null byte");
- 				return NULL;
- 			}
- 			if(!done) sw_error=1;
- 			break;
- 
- 		case '-':
- 			sign = -1;
- 				/* Fallthrough */
- 		case '+':
- 			if (done) sw_error=1;
- 			s++;
- 			if ( *s=='0円'||*s=='+'||*s=='-' ||
- 			 isspace(Py_CHARMASK(*s)) ) sw_error=1;
- 			break;
- 
- 		case 'J':
- 		case 'j':
- 			if (got_im || done) {
- 				sw_error = 1;
- 				break;
- 			}
- 			if (z<0.0) {
- 				y=sign;
- 			}
- 			else{
- 				y=sign*z;
- 			}
- 			got_im=1;
- 			s++;
- 			if (*s!='+' && *s!='-' )
- 				done=1;
- 			break;
- 
- 		default:
- 			if (isspace(Py_CHARMASK(*s))) {
- 				while (*s && isspace(Py_CHARMASK(*s)))
- 					s++;
- 				if (s[0] != '0円')
- 					sw_error=1;
- 				else
- 					done = 1;
- 				break;
- 			}
- 			digit_or_dot =
- 				(*s=='.' || isdigit(Py_CHARMASK(*s)));
- 			if (done||!digit_or_dot) {
- 				sw_error=1;
- 				break;
- 			}
- 			errno = 0;
- 			PyFPE_START_PROTECT("strtod", return 0)
- 				z = strtod(s, &end) ;
- 			PyFPE_END_PROTECT(z)
- 				if (errno != 0) {
- 					sprintf(buffer,
- 					 "float() out of range: %.150s", s);
- 					PyErr_SetString(
- 						PyExc_ValueError,
- 						buffer);
- 					return NULL;
- 				}
- 			s=end;
- 			if (*s=='J' || *s=='j') {
- 
- 				break;
- 			}
- 			if (got_re) {
- 				sw_error=1;
- 				break;
- 			}
- 
- 				/* accept a real part */
- 			x=sign*z;
- 			got_re=1;
- 			if (got_im) done=1;
- 			z = -1.0;
- 			sign = 1;
- 			break;
- 
- 		} /* end of switch */
- 
- 	} while (*s!='0円' && !sw_error);
- 
- 	if (sw_error) {
- 		PyErr_SetString(PyExc_ValueError,
- 				"complex() arg is a malformed string");
- 		return NULL;
- 	}
- 
- 	return PyComplex_FromDoubles(x,y);
- }
- 
 static PyObject *
- builtin_complex(PyObject *self, PyObject *args)
- {
- 	PyObject *r, *i, *tmp;
- 	PyNumberMethods *nbr, *nbi = NULL;
- 	Py_complex cr, ci;
- 	int own_r = 0;
- 
- 	i = NULL;
- 	if (!PyArg_ParseTuple(args, "O|O:complex", &r, &i))
- 		return NULL;
- 	if (PyString_Check(r) || PyUnicode_Check(r))
- 		return complex_from_string(r);
- 	if ((nbr = r->ob_type->tp_as_number) == NULL ||
- 	 nbr->nb_float == NULL ||
- 	 (i != NULL &&
- 	 ((nbi = i->ob_type->tp_as_number) == NULL ||
- 	 nbi->nb_float == NULL))) {
- 		PyErr_SetString(PyExc_TypeError,
- 			 "complex() arg can't be converted to complex");
- 		return NULL;
- 	}
- 	/* XXX Hack to support classes with __complex__ method */
- 	if (PyInstance_Check(r)) {
- 		static PyObject *complexstr;
- 		PyObject *f;
- 		if (complexstr == NULL) {
- 			complexstr = PyString_InternFromString("__complex__");
- 			if (complexstr == NULL)
- 				return NULL;
- 		}
- 		f = PyObject_GetAttr(r, complexstr);
- 		if (f == NULL)
- 			PyErr_Clear();
- 		else {
- 			PyObject *args = Py_BuildValue("()");
- 			if (args == NULL)
- 				return NULL;
- 			r = PyEval_CallObject(f, args);
- 			Py_DECREF(args);
- 			Py_DECREF(f);
- 			if (r == NULL)
- 				return NULL;
- 			own_r = 1;
- 		}
- 	}
- 	if (PyComplex_Check(r)) {
- 		cr = ((PyComplexObject*)r)->cval;
- 		if (own_r) {
- 			Py_DECREF(r);
- 		}
- 	}
- 	else {
- 		tmp = PyNumber_Float(r);
- 		if (own_r) {
- 			Py_DECREF(r);
- 		}
- 		if (tmp == NULL)
- 			return NULL;
- 		if (!PyFloat_Check(tmp)) {
- 			PyErr_SetString(PyExc_TypeError,
- 					"float(r) didn't return a float");
- 			Py_DECREF(tmp);
- 			return NULL;
- 		}
- 		cr.real = PyFloat_AsDouble(tmp);
- 		Py_DECREF(tmp);
- 		cr.imag = 0.0;
- 	}
- 	if (i == NULL) {
- 		ci.real = 0.0;
- 		ci.imag = 0.0;
- 	}
- 	else if (PyComplex_Check(i))
- 		ci = ((PyComplexObject*)i)->cval;
- 	else {
- 		tmp = (*nbi->nb_float)(i);
- 		if (tmp == NULL)
- 			return NULL;
- 		ci.real = PyFloat_AsDouble(tmp);
- 		Py_DECREF(tmp);
- 		ci.imag = 0.;
- 	}
- 	cr.real -= ci.imag;
- 	cr.imag += ci.real;
- 	return PyComplex_FromCComplex(cr);
- }
- 
- static char complex_doc[] =
- "complex(real[, imag]) -> complex number\n\
- \n\
- Create a complex number from a real part and an optional imaginary part.\n\
- This is equivalent to (real + imag*1j) where imag defaults to 0.";
- 
- 
- #endif
- 
- static PyObject *
 builtin_dir(PyObject *self, PyObject *args)
 {
--- 416,420 ----
***************
*** 1061,1066 ****
 		if (curlen < 0)
 			curlen = 8; /* arbitrary */
! 		if (curlen > len)
! 			len = curlen;
 	}
 
--- 790,795 ----
 		if (curlen < 0)
 			curlen = 8; /* arbitrary */
! 			if (curlen > len)
! 				len = curlen;
 	}
 
***************
*** 1302,1390 ****
 
 static PyObject *
- builtin_int(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 	int base = -909;		 /* unlikely! */
- 
- 	if (!PyArg_ParseTuple(args, "O|i:int", &v, &base))
- 		return NULL;
- 	if (base == -909)
- 		return PyNumber_Int(v);
- 	else if (PyString_Check(v))
- 		return PyInt_FromString(PyString_AS_STRING(v), NULL, base);
- 	else if (PyUnicode_Check(v))
- 		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(v),
- 					 PyUnicode_GET_SIZE(v),
- 					 base);
- 	else {
- 		PyErr_SetString(PyExc_TypeError,
- 				"int() can't convert non-string with explicit base");
- 		return NULL;
- 	}
- }
- 
- static char int_doc[] =
- "int(x[, base]) -> integer\n\
- \n\
- Convert a string or number to an integer, if possible. A floating point\n\
- argument will be truncated towards zero (this does not include a string\n\
- representation of a floating point number!) When converting a string, use\n\
- the optional base. It is an error to supply a base when converting a\n\
- non-string.";
- 
- 
- static PyObject *
- builtin_long(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 	int base = -909;		 /* unlikely! */
- 
- 	if (!PyArg_ParseTuple(args, "O|i:long", &v, &base))
- 		return NULL;
- 	if (base == -909)
- 		return PyNumber_Long(v);
- 	else if (PyString_Check(v))
- 		return PyLong_FromString(PyString_AS_STRING(v), NULL, base);
- 	else if (PyUnicode_Check(v))
- 		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(v),
- 					 PyUnicode_GET_SIZE(v),
- 					 base);
- 	else {
- 		PyErr_SetString(PyExc_TypeError,
- 				"long() can't convert non-string with explicit base");
- 		return NULL;
- 	}
- }
- 
- static char long_doc[] =
- "long(x) -> long integer\n\
- long(x, base) -> long integer\n\
- \n\
- Convert a string or number to a long integer, if possible. A floating\n\
- point argument will be truncated towards zero (this does not include a\n\
- string representation of a floating point number!) When converting a\n\
- string, use the given base. It is an error to supply a base when\n\
- converting a non-string.";
- 
- 
- static PyObject *
- builtin_float(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 
- 	if (!PyArg_ParseTuple(args, "O:float", &v))
- 		return NULL;
- 	if (PyString_Check(v))
- 		return PyFloat_FromString(v, NULL);
- 	return PyNumber_Float(v);
- }
- 
- static char float_doc[] =
- "float(x) -> floating point number\n\
- \n\
- Convert a string or number to a floating point number, if possible.";
- 
- 
- static PyObject *
 builtin_iter(PyObject *self, PyObject *args)
 {
--- 1031,1034 ----
***************
*** 1433,1452 ****
 
 static PyObject *
- builtin_list(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 
- 	if (!PyArg_ParseTuple(args, "O:list", &v))
- 		return NULL;
- 	return PySequence_List(v);
- }
- 
- static char list_doc[] =
- "list(sequence) -> list\n\
- \n\
- Return a new list whose items are the same as those of the argument sequence.";
- 
- 
- static PyObject *
 builtin_slice(PyObject *self, PyObject *args)
 {
--- 1077,1080 ----
***************
*** 2034,2089 ****
 
 static PyObject *
- builtin_str(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 
- 	if (!PyArg_ParseTuple(args, "O:str", &v))
- 		return NULL;
- 	return PyObject_Str(v);
- }
- 
- static char str_doc[] =
- "str(object) -> string\n\
- \n\
- Return a nice string representation of the object.\n\
- If the argument is a string, the return value is the same object.";
- 
- 
- static PyObject *
- builtin_tuple(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 
- 	if (!PyArg_ParseTuple(args, "O:tuple", &v))
- 		return NULL;
- 	return PySequence_Tuple(v);
- }
- 
- static char tuple_doc[] =
- "tuple(sequence) -> list\n\
- \n\
- Return a tuple whose items are the same as those of the argument sequence.\n\
- If the argument is a tuple, the return value is the same object.";
- 
- 
- static PyObject *
- builtin_type(PyObject *self, PyObject *args)
- {
- 	PyObject *v;
- 
- 	if (!PyArg_ParseTuple(args, "O:type", &v))
- 		return NULL;
- 	v = (PyObject *)v->ob_type;
- 	Py_INCREF(v);
- 	return v;
- }
- 
- static char type_doc[] =
- "type(object) -> type object\n\
- \n\
- Return the type of the object.";
- 
- 
- static PyObject *
 builtin_vars(PyObject *self, PyObject *args)
 {
--- 1662,1665 ----
***************
*** 2256,2262 ****
 	{"coerce",	builtin_coerce, 1, coerce_doc},
 	{"compile",	builtin_compile, 1, compile_doc},
- #ifndef WITHOUT_COMPLEX
- 	{"complex",	builtin_complex, 1, complex_doc},
- #endif
 	{"delattr",	builtin_delattr, 1, delattr_doc},
 	{"dir",		builtin_dir, 1, dir_doc},
--- 1832,1835 ----
***************
*** 2265,2269 ****
 	{"execfile",	builtin_execfile, 1, execfile_doc},
 	{"filter",	builtin_filter, 1, filter_doc},
- 	{"float",	builtin_float, 1, float_doc},
 	{"getattr",	builtin_getattr, 1, getattr_doc},
 	{"globals",	builtin_globals, 1, globals_doc},
--- 1838,1841 ----
***************
*** 2274,2285 ****
 	{"input",	builtin_input, 1, input_doc},
 	{"intern",	builtin_intern, 1, intern_doc},
- 	{"int",		builtin_int, 1, int_doc},
 	{"isinstance", builtin_isinstance, 1, isinstance_doc},
 	{"issubclass", builtin_issubclass, 1, issubclass_doc},
 	{"iter",	builtin_iter, 1, iter_doc},
 	{"len",		builtin_len, 1, len_doc},
- 	{"list",	builtin_list, 1, list_doc},
 	{"locals",	builtin_locals, 1, locals_doc},
- 	{"long",	builtin_long, 1, long_doc},
 	{"map",		builtin_map, 1, map_doc},
 	{"max",		builtin_max, 1, max_doc},
--- 1846,1854 ----
***************
*** 2297,2304 ****
 	{"setattr",	builtin_setattr, 1, setattr_doc},
 	{"slice", builtin_slice, 1, slice_doc},
- 	{"str",		builtin_str, 1, str_doc},
- 	{"tuple",	builtin_tuple, 1, tuple_doc},
- 	{"type",	builtin_type, 1, type_doc},
- 	{"unicode",	builtin_unicode, 1, unicode_doc},
 	{"unichr",	builtin_unichr, 1, unichr_doc},
 	{"vars",	builtin_vars, 1, vars_doc},
--- 1866,1869 ----
***************
*** 2329,2332 ****
--- 1894,1933 ----
 	if (PyDict_SetItemString(dict, "NotImplemented",
 				 Py_NotImplemented) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "classmethod",
+ 				 (PyObject *) &PyClassMethod_Type) < 0)
+ 		return NULL;
+ #ifndef WITHOUT_COMPLEX
+ 	if (PyDict_SetItemString(dict, "complex",
+ 				 (PyObject *) &PyComplex_Type) < 0)
+ 		return NULL;
+ #endif
+ 	if (PyDict_SetItemString(dict, "dictionary",
+ 				 (PyObject *) &PyDict_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "float",
+ 				 (PyObject *) &PyFloat_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "int", (PyObject *) &PyInt_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "list", (PyObject *) &PyList_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "long", (PyObject *) &PyLong_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "object",
+ 				 (PyObject *) &PyBaseObject_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "staticmethod",
+ 				 (PyObject *) &PyStaticMethod_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "str", (PyObject *) &PyString_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "tuple",
+ 				 (PyObject *) &PyTuple_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "type", (PyObject *) &PyType_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "unicode",
+ 				 (PyObject *) &PyUnicode_Type) < 0)
 		return NULL;
 	debug = PyInt_FromLong(Py_OptimizeFlag == 0);
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.262
retrieving revision 2.263
diff -C2 -d -r2.262 -r2.263
*** ceval.c	2001年07月16日 02:29:45	2.262
--- ceval.c	2001年08月02日 04:15:00	2.263
***************
*** 14,17 ****
--- 14,18 ----
 #include "eval.h"
 #include "opcode.h"
+ #include "structmember.h"
 
 #ifdef macintosh
***************
*** 33,47 ****
 
 /* Forward declarations */
- 
- static PyObject *eval_code2(PyCodeObject *,
- 			 PyObject *, PyObject *,
- 			 PyObject **, int,
- 			 PyObject **, int,
- 			 PyObject **, int,
- 			 PyObject *);
- 
 static PyObject *eval_frame(PyFrameObject *);
- static char *get_func_name(PyObject *);
- static char *get_func_desc(PyObject *);
 static PyObject *call_object(PyObject *, PyObject *, PyObject *);
 static PyObject *call_cfunction(PyObject *, PyObject *, PyObject *);
--- 34,38 ----
***************
*** 99,103 ****
 #endif
 
- 
 staticforward PyTypeObject gentype;
 
--- 90,93 ----
***************
*** 211,233 ****
 	{NULL, NULL} /* Sentinel */
 };
- 
- static PyObject *
- gen_getattr(genobject *gen, char *name)
- {
- 	PyObject *result;
 
! 	if (strcmp(name, "gi_frame") == 0) {
! 		result = (PyObject *)gen->gi_frame;
! 		assert(result != NULL);
! 		Py_INCREF(result);
! 	}
! 	else if (strcmp(name, "gi_running") == 0)
! 		result = (PyObject *)PyInt_FromLong((long)gen->gi_running);
! 	else if (strcmp(name, "__members__") == 0)
! 		result = Py_BuildValue("[ss]", "gi_frame", "gi_running");
! 	else
! 		result = Py_FindMethod(gen_methods, (PyObject *)gen, name);
! 	return result;
! }
 
 statichere PyTypeObject gentype = {
--- 201,210 ----
 	{NULL, NULL} /* Sentinel */
 };
 
! static struct memberlist gen_memberlist[] = {
! 	{"gi_frame",	T_OBJECT, offsetof(genobject, gi_frame),	RO},
! 	{"gi_running",	T_INT, offsetof(genobject, gi_running),	RO},
! 	{NULL}	/* Sentinel */
! };
 
 statichere PyTypeObject gentype = {
***************
*** 240,244 ****
 	(destructor)gen_dealloc, 		/* tp_dealloc */
 	0,					/* tp_print */
! 	(getattrfunc)gen_getattr,		/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
--- 217,221 ----
 	(destructor)gen_dealloc, 		/* tp_dealloc */
 	0,					/* tp_print */
! 	0, 					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
***************
*** 250,254 ****
 	0,					/* tp_call */
 	0,					/* tp_str */
! 	0,					/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
--- 227,231 ----
 	0,					/* tp_call */
 	0,					/* tp_str */
! 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
***************
*** 261,264 ****
--- 238,246 ----
 	(getiterfunc)gen_getiter,		/* tp_iter */
 	(iternextfunc)gen_iternext,		/* tp_iternext */
+ 	gen_methods,				/* tp_methods */
+ 	gen_memberlist,				/* tp_members */
+ 	0,					/* tp_getset */
+ 	0,					/* tp_base */
+ 	0,					/* tp_dict */
 };
 
***************
*** 506,510 ****
 PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
 {
! 	return eval_code2(co,
 			 globals, locals,
 			 (PyObject **)NULL, 0,
--- 488,492 ----
 PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
 {
! 	return PyEval_EvalCodeEx(co,
 			 globals, locals,
 			 (PyObject **)NULL, 0,
***************
*** 517,521 ****
 /* Interpreter main loop */
 
! PyObject *
 eval_frame(PyFrameObject *f)
 {
--- 499,503 ----
 /* Interpreter main loop */
 
! static PyObject *
 eval_frame(PyFrameObject *f)
 {
***************
*** 966,970 ****
 			w = POP();
 			v = POP();
! 			if (PyList_Check(v) && PyInt_Check(w)) {
 				/* INLINE: list[int] */
 				long i = PyInt_AsLong(w);
--- 948,952 ----
 			w = POP();
 			v = POP();
! 			if (v->ob_type == &PyList_Type && PyInt_Check(w)) {
 				/* INLINE: list[int] */
 				long i = PyInt_AsLong(w);
***************
*** 2274,2279 ****
 }
 
! static PyObject *
! eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
 	 PyObject **args, int argcount, PyObject **kws, int kwcount,
 	 PyObject **defs, int defcount, PyObject *closure)
--- 2256,2261 ----
 }
 
! PyObject *
! PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
 	 PyObject **args, int argcount, PyObject **kws, int kwcount,
 	 PyObject **defs, int defcount, PyObject *closure)
***************
*** 2974,2978 ****
 	}
 
! 	result = call_object(func, arg, kw);
 	Py_DECREF(arg);
 	return result;
--- 2956,2960 ----
 	}
 
! 	result = PyObject_Call(func, arg, kw);
 	Py_DECREF(arg);
 	return result;
***************
*** 2980,2984 ****
 
 /* How often is each kind of object called? The answer depends on the
! program. An instrumented call_object() was used to run the Python
 regression test suite. The results were:
 4200000 PyCFunctions
--- 2962,2966 ----
 
 /* How often is each kind of object called? The answer depends on the
! program. An instrumented PyObject_Call() was used to run the Python
 regression test suite. The results were:
 4200000 PyCFunctions
***************
*** 2993,3001 ****
 */
 
! static char *
! get_func_name(PyObject *func)
 {
 	if (PyMethod_Check(func))
! 		return get_func_name(PyMethod_GET_FUNCTION(func));
 	else if (PyFunction_Check(func))
 		return PyString_AsString(((PyFunctionObject*)func)->func_name);
--- 2975,2983 ----
 */
 
! char *
! PyEval_GetFuncName(PyObject *func)
 {
 	if (PyMethod_Check(func))
! 		return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
 	else if (PyFunction_Check(func))
 		return PyString_AsString(((PyFunctionObject*)func)->func_name);
***************
*** 3012,3017 ****
 }
 
! static char *
! get_func_desc(PyObject *func)
 {
 	if (PyMethod_Check(func))
--- 2994,2999 ----
 }
 
! char *
! PyEval_GetFuncDesc(PyObject *func)
 {
 	if (PyMethod_Check(func))
***************
*** 3137,3141 ****
 				 "unbound method %s%s must be "
 				 "called with instance as first argument",
! 				 get_func_name(func), get_func_desc(func));
 			return NULL;
 		}
--- 3119,3124 ----
 				 "unbound method %s%s must be "
 				 "called with instance as first argument",
! 				 PyEval_GetFuncName(func),
! 				 PyEval_GetFuncDesc(func));
 			return NULL;
 		}
***************
*** 3200,3204 ****
 	}
 
! 	result = eval_code2(
 		(PyCodeObject *)PyFunction_GET_CODE(func),
 		PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
--- 3183,3187 ----
 	}
 
! 	result = PyEval_EvalCodeEx(
 		(PyCodeObject *)PyFunction_GET_CODE(func),
 		PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
***************
*** 3256,3260 ****
 		nd = ((PyTupleObject *)argdefs)->ob_size;
 	}
! 	return eval_code2((PyCodeObject *)co, globals,
 			 (PyObject *)NULL, (*pp_stack)-n, na,
 			 (*pp_stack)-2*nk, nk, d, nd,
--- 3239,3243 ----
 		nd = ((PyTupleObject *)argdefs)->ob_size;
 	}
! 	return PyEval_EvalCodeEx((PyCodeObject *)co, globals,
 			 (PyObject *)NULL, (*pp_stack)-n, na,
 			 (*pp_stack)-2*nk, nk, d, nd,
***************
*** 3283,3288 ****
 "%.200s%s got multiple values "
 "for keyword argument '%.200s'",
! 				 get_func_name(func),
! 				 get_func_desc(func),
 				 PyString_AsString(key));
 			Py_DECREF(key);
--- 3266,3271 ----
 "%.200s%s got multiple values "
 "for keyword argument '%.200s'",
! 				 PyEval_GetFuncName(func),
! 				 PyEval_GetFuncDesc(func),
 				 PyString_AsString(key));
 			Py_DECREF(key);
***************
*** 3357,3361 ****
 	if (callargs == NULL)
 		goto call_fail;
! 	result = call_object(func, callargs, kwdict);
 call_fail:
 	Py_XDECREF(callargs);
--- 3340,3344 ----
 	if (callargs == NULL)
 		goto call_fail;
! 	result = PyObject_Call(func, callargs, kwdict);
 call_fail:
 	Py_XDECREF(callargs);
***************
*** 3379,3384 ****
 				 "%s%s argument after ** "
 				 "must be a dictionary",
! 				 get_func_name(func),
! 				 get_func_desc(func));
 			goto ext_call_fail;
 		}
--- 3362,3367 ----
 				 "%s%s argument after ** "
 				 "must be a dictionary",
! 				 PyEval_GetFuncName(func),
! 				 PyEval_GetFuncDesc(func));
 			goto ext_call_fail;
 		}
***************
*** 3394,3399 ****
 						 "%s%s argument after * "
 						 "must be a sequence",
! 						 get_func_name(func),
! 						 get_func_desc(func));
 				}
 				goto ext_call_fail;
--- 3377,3382 ----
 						 "%s%s argument after * "
 						 "must be a sequence",
! 						 PyEval_GetFuncName(func),
! 						 PyEval_GetFuncDesc(func));
 				}
 				goto ext_call_fail;
***************
*** 3412,3416 ****
 	if (callargs == NULL)
 		goto ext_call_fail;
! 	result = call_object(func, callargs, kwdict);
 ext_call_fail:
 	Py_XDECREF(callargs);
--- 3395,3399 ----
 	if (callargs == NULL)
 		goto ext_call_fail;
! 	result = PyObject_Call(func, callargs, kwdict);
 ext_call_fail:
 	Py_XDECREF(callargs);
***************
*** 3633,3693 ****
 build_class(PyObject *methods, PyObject *bases, PyObject *name)
 {
! 	int i, n;
! 	if (!PyTuple_Check(bases)) {
! 		PyErr_SetString(PyExc_SystemError,
! 				"build_class with non-tuple bases");
! 		return NULL;
! 	}
! 	if (!PyDict_Check(methods)) {
! 		PyErr_SetString(PyExc_SystemError,
! 				"build_class with non-dictionary");
! 		return NULL;
! 	}
! 	if (!PyString_Check(name)) {
! 		PyErr_SetString(PyExc_SystemError,
! 				"build_class with non-string name");
! 		return NULL;
! 	}
! 	n = PyTuple_Size(bases);
! 	for (i = 0; i < n; i++) {
! 		PyObject *base = PyTuple_GET_ITEM(bases, i);
! 		if (!PyClass_Check(base)) {
! 			/* Call the base's *type*, if it is callable.
! 			 This code is a hook for Donald Beaudry's
! 			 and Jim Fulton's type extensions. In
! 			 unextended Python it will never be triggered
! 			 since its types are not callable.
! 			 Ditto: call the bases's *class*, if it has
! 			 one. This makes the same thing possible
! 			 without writing C code. A true meta-object
! 			 protocol! */
! 			PyObject *basetype = (PyObject *)base->ob_type;
! 			PyObject *callable = NULL;
! 			if (PyCallable_Check(basetype))
! 				callable = basetype;
! 			else
! 				callable = PyObject_GetAttrString(
! 					base, "__class__");
! 			if (callable) {
! 				PyObject *args;
! 				PyObject *newclass = NULL;
! 				args = Py_BuildValue(
! 					"(OOO)", name, bases, methods);
! 				if (args != NULL) {
! 					newclass = PyEval_CallObject(
! 						callable, args);
! 					Py_DECREF(args);
! 				}
! 				if (callable != basetype) {
! 					Py_DECREF(callable);
! 				}
! 				return newclass;
! 			}
! 			PyErr_SetString(PyExc_TypeError,
! 				"base is not a class object");
! 			return NULL;
 		}
 	}
! 	return PyClass_New(bases, methods, name);
 }
 
--- 3616,3638 ----
 build_class(PyObject *methods, PyObject *bases, PyObject *name)
 {
! 	PyObject *metaclass = NULL;
! 
! 	if (PyDict_Check(methods))
! 		metaclass = PyDict_GetItemString(methods, "__metaclass__");
! 
! 	if (metaclass == NULL) {
! 		if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0)
! 			metaclass = (PyObject *)
! 				PyTuple_GET_ITEM(bases, 0)->ob_type;
! 		else {
! 			PyObject *g = PyEval_GetGlobals();
! 			if (g != NULL && PyDict_Check(g))
! 				metaclass = PyDict_GetItemString(
! 					g, "__metaclass__");
! 			if (metaclass == NULL)
! 				metaclass = (PyObject *) &PyClass_Type;
 		}
 	}
! 	return PyObject_CallFunction(metaclass, "OOO", name, bases, methods);
 }
 
Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** exceptions.c	2001年04月20日 19:13:02	1.24
--- exceptions.c	2001年08月02日 04:15:00	1.25
***************
*** 1057,1077 ****
 
 DL_EXPORT(void)
! init_exceptions(void)
 {
 char *modulename = "exceptions";
 int modnamesz = strlen(modulename);
 int i;
 
! PyObject *me = Py_InitModule(modulename, functions);
! PyObject *mydict = PyModule_GetDict(me);
! PyObject *bltinmod = PyImport_ImportModule("__builtin__");
! PyObject *bdict = PyModule_GetDict(bltinmod);
! PyObject *doc = PyString_FromString(module__doc__);
! PyObject *args;
 
! PyDict_SetItemString(mydict, "__doc__", doc);
 Py_DECREF(doc);
! if (PyErr_Occurred())
 	Py_FatalError("exceptions bootstrapping error.");
 
 /* This is the base class of all exceptions, so make it first. */
--- 1057,1090 ----
 
 DL_EXPORT(void)
! _PyExc_Init(void)
 {
 char *modulename = "exceptions";
 int modnamesz = strlen(modulename);
 int i;
+ PyObject *me, *mydict, *bltinmod, *bdict, *doc, *args;
 
! me = Py_InitModule(modulename, functions);
! if (me == NULL)
! 	goto err;
! mydict = PyModule_GetDict(me);
! if (mydict == NULL)
! 	goto err;
! bltinmod = PyImport_ImportModule("__builtin__");
! if (bltinmod == NULL)
! 	goto err;
! bdict = PyModule_GetDict(bltinmod);
! if (bdict == NULL)
! 	goto err;
! doc = PyString_FromString(module__doc__);
! if (doc == NULL)
! 	goto err;
 
! i = PyDict_SetItemString(mydict, "__doc__", doc);
 Py_DECREF(doc);
! if (i < 0) {
! err:
 	Py_FatalError("exceptions bootstrapping error.");
+ 	return;
+ }
 
 /* This is the base class of all exceptions, so make it first. */
***************
*** 1140,1144 ****
 
 DL_EXPORT(void)
! fini_exceptions(void)
 {
 int i;
--- 1153,1157 ----
 
 DL_EXPORT(void)
! _PyExc_Fini(void)
 {
 int i;
Index: import.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/import.c,v
retrieving revision 2.180
retrieving revision 2.181
diff -C2 -d -r2.180 -r2.181
*** import.c	2001年07月23日 16:30:27	2.180
--- import.c	2001年08月02日 04:15:00	2.181
***************
*** 44,48 ****
 added to the .pyc file header? */
 /* New way to come up with the magic number: (YEAR-1995), MONTH, DAY */
! #define MAGIC (60420 | ((long)'\r'<<16) | ((long)'\n'<<24))
 
 /* Magic word as global; note that _PyImport_Init() can change the
--- 44,48 ----
 added to the .pyc file header? */
 /* New way to come up with the magic number: (YEAR-1995), MONTH, DAY */
! #define MAGIC (60717 | ((long)'\r'<<16) | ((long)'\n'<<24))
 
 /* Magic word as global; note that _PyImport_Init() can change the
***************
*** 1969,1974 ****
 
 	/* Get the __import__ function from the builtins */
! 	if (PyDict_Check(builtins))
 		import = PyObject_GetItem(builtins, import_str);
 	else
 		import = PyObject_GetAttr(builtins, import_str);
--- 1969,1977 ----
 
 	/* Get the __import__ function from the builtins */
! 	if (PyDict_Check(builtins)) {
 		import = PyObject_GetItem(builtins, import_str);
+ 		if (import == NULL)
+ 			PyErr_SetObject(PyExc_KeyError, import_str);
+ 	}
 	else
 		import = PyObject_GetAttr(builtins, import_str);
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.139
retrieving revision 2.140
diff -C2 -d -r2.139 -r2.140
*** pythonrun.c	2001年07月23日 16:30:27	2.139
--- pythonrun.c	2001年08月02日 04:15:00	2.140
***************
*** 116,119 ****
--- 116,122 ----
 	(void) PyThreadState_Swap(tstate);
 
+ 	if (PyType_InitDict(&PyType_Type) < 0)
+ 		Py_FatalError("Py_Initialize: can't initialize 'type'");
+ 
 	interp->modules = PyDict_New();
 	if (interp->modules == NULL)
***************
*** 145,149 ****
 
 	/* initialize builtin exceptions */
! 	init_exceptions();
 
 	/* phase 2 of builtins */
--- 148,152 ----
 
 	/* initialize builtin exceptions */
! 	_PyExc_Init();
 
 	/* phase 2 of builtins */
***************
*** 239,243 ****
 	 raised.
 	*/
! 	fini_exceptions();
 
 	/* Delete current thread */
--- 242,246 ----
 	 raised.
 	*/
! 	_PyExc_Fini();
 
 	/* Delete current thread */
***************
*** 1346,1350 ****
 	char buf[256];
 	
! 	printf("%s [ny] ", prompt);
 	if (fgets(buf, sizeof buf, stdin) == NULL)
 		return 0;
--- 1349,1353 ----
 	char buf[256];
 	
! 	fprintf(stderr, "%s [ny] ", prompt);
 	if (fgets(buf, sizeof buf, stdin) == NULL)
 		return 0;

AltStyle によって変換されたページ (->オリジナル) /