Merge part of the trunk changes into the p3yk branch. This merges from 43030

(branch-creation time) up to 43067. 43068 and 43069 contain a little
swapping action between re.py and sre.py, and this mightily confuses svn
merge, so later changes are going in separately.

This merge should break no additional tests.

The last-merged revision is going in a 'last_merge' property on '.' (the
branch directory.) Arbitrarily chosen, really; if there's a BCP for this, I
couldn't find it, but we can easily change it afterwards ;)
This commit is contained in:
Thomas Wouters 2006-04-21 09:43:23 +00:00
parent d858f70617
commit a977329b6f
116 changed files with 3409 additions and 709 deletions

View file

@ -3674,7 +3674,11 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
if (cache == NULL)
return NULL;
}
#if (PY_VERSION_HEX < 0x02050000)
key = Py_BuildValue("(Oi)", itemtype, length);
#else
key = Py_BuildValue("(On)", itemtype, length);
#endif
if (!key)
return NULL;
result = PyDict_GetItem(cache, key);
@ -3698,7 +3702,11 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
#endif
result = PyObject_CallFunction((PyObject *)&ArrayType_Type,
#if (PY_VERSION_HEX < 0x02050000)
"s(O){s:i,s:O}",
#else
"s(O){s:n,s:O}",
#endif
name,
&Array_Type,
"_length_",

View file

@ -250,11 +250,21 @@ CField_repr(CFieldObject *self)
name = ((PyTypeObject *)self->proto)->tp_name;
if (bits)
result = PyString_FromFormat("<Field type=%s, ofs=%d:%d, bits=%d>",
name, (int)self->offset, size, bits);
result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d:%d, bits=%d>",
#else
"<Field type=%s, ofs=%zd:%d, bits=%d>",
#endif
name, self->offset, size, bits);
else
result = PyString_FromFormat("<Field type=%s, ofs=%d, size=%d>",
name, (int)self->offset, size);
result = PyString_FromFormat(
#if (PY_VERSION_HEX < 0x02050000)
"<Field type=%s, ofs=%d, size=%d>",
#else
"<Field type=%s, ofs=%zd, size=%d>",
#endif
name, self->offset, size);
return result;
}

View file

@ -1,5 +1,18 @@
/******************************************************************/
#if (PY_VERSION_HEX < 0x02050000)
typedef int Py_ssize_t;
#define lenfunc inquiry
#define readbufferproc getreadbufferproc
#define writebufferproc getwritebufferproc
#define segcountproc getsegcountproc
#define charbufferproc getcharbufferproc
#define ssizeargfunc intargfunc
#define ssizessizeargfunc intintargfunc
#define ssizeobjargproc intobjargproc
#define ssizessizeobjargproc intintobjargproc
#endif
#ifndef MS_WIN32
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

View file

@ -522,6 +522,18 @@ test_long_numbits(PyObject *self)
return Py_None;
}
/* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
static PyObject *
test_null_strings(PyObject *self)
{
PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL);
PyObject *tuple = PyTuple_Pack(2, o1, o2);
Py_XDECREF(o1);
Py_XDECREF(o2);
return tuple;
}
static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
@ -597,6 +609,7 @@ static PyMethodDef TestMethods[] = {
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
{"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
{"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
{"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
{"getargs_b", (PyCFunction)getargs_b, METH_VARARGS},
{"getargs_B", (PyCFunction)getargs_B, METH_VARARGS},

View file

@ -144,7 +144,8 @@ PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0");
static PyObject *
IO_isatty(IOobject *self, PyObject *unused) {
Py_INCREF(Py_False);
if (!IO__opencheck(self)) return NULL;
Py_INCREF(Py_False);
return Py_False;
}

View file

@ -130,27 +130,42 @@ static void RunStartupFile(PyCompilerFlags *cf)
}
}
/* Get the path to a top-level module */
static struct filedescr * FindModule(const char *module,
FILE **fp, char **filename)
static int RunModule(char *module)
{
struct filedescr *fdescr = NULL;
*fp = NULL;
*filename = malloc(MAXPATHLEN);
if (*filename == NULL)
return NULL;
/* Find the actual module source code */
fdescr = _PyImport_FindModule(module, NULL,
*filename, MAXPATHLEN, fp, NULL);
if (fdescr == NULL) {
free(*filename);
*filename = NULL;
PyObject *runpy, *runmodule, *runargs, *result;
runpy = PyImport_ImportModule("runpy");
if (runpy == NULL) {
fprintf(stderr, "Could not import runpy module\n");
return -1;
}
return fdescr;
runmodule = PyObject_GetAttrString(runpy, "run_module");
if (runmodule == NULL) {
fprintf(stderr, "Could not access runpy.run_module\n");
Py_DECREF(runpy);
return -1;
}
runargs = Py_BuildValue("sOsO", module,
Py_None, "__main__", Py_True);
if (runargs == NULL) {
fprintf(stderr,
"Could not create arguments for runpy.run_module\n");
Py_DECREF(runpy);
Py_DECREF(runmodule);
return -1;
}
result = PyObject_Call(runmodule, runargs, NULL);
if (result == NULL) {
PyErr_Print();
}
Py_DECREF(runpy);
Py_DECREF(runmodule);
Py_DECREF(runargs);
if (result == NULL) {
return -1;
}
Py_DECREF(result);
return 0;
}
/* Main program */
@ -410,28 +425,9 @@ Py_Main(int argc, char **argv)
}
if (module != NULL) {
/* Backup _PyOS_optind and find the real file */
struct filedescr *fdescr = NULL;
/* Backup _PyOS_optind and force sys.arv[0] = module */
_PyOS_optind--;
if ((fdescr = FindModule(module, &fp, &filename))) {
argv[_PyOS_optind] = filename;
} else {
fprintf(stderr, "%s: module %s not found\n",
argv[0], module);
return 2;
}
if (!fp) {
fprintf(stderr,
"%s: module %s has no associated file\n",
argv[0], module);
return 2;
}
if (!_PyImport_IsScript(fdescr)) {
fprintf(stderr,
"%s: module %s not usable as script\n (%s)\n",
argv[0], module, filename);
return 2;
}
argv[_PyOS_optind] = module;
}
PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
@ -450,9 +446,8 @@ Py_Main(int argc, char **argv)
sts = PyRun_SimpleStringFlags(command, &cf) != 0;
free(command);
} else if (module) {
sts = PyRun_AnyFileExFlags(fp, filename, 1, &cf) != 0;
sts = RunModule(module);
free(module);
free(filename);
}
else {
if (filename == NULL && stdin_is_interactive) {

View file

@ -197,18 +197,6 @@ xx_bug(PyObject *self, PyObject *args)
return Py_None;
}
/* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */
static PyObject *
xx_null(PyObject *self, PyObject *noargs)
{
PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL);
PyObject *tuple = PyTuple_Pack(2, o1, o2);
Py_XDECREF(o1);
Py_XDECREF(o2);
return tuple;
}
/* Test bad format character */
static PyObject *
@ -343,8 +331,6 @@ static PyMethodDef xx_methods[] = {
PyDoc_STR("new() -> new Xx object")},
{"bug", xx_bug, METH_VARARGS,
PyDoc_STR("bug(o) -> None")},
{"null", xx_null, METH_NOARGS,
PyDoc_STR("null(o) -> ('NULL', u'NULL')")},
{NULL, NULL} /* sentinel */
};