summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/Setup.dist13
-rw-r--r--Modules/_bsddb.c54
-rw-r--r--Modules/_codecsmodule.c15
-rw-r--r--Modules/_ctypes/_ctypes.c172
-rw-r--r--Modules/_ctypes/_ctypes_test.c5
-rw-r--r--Modules/_ctypes/callbacks.c21
-rw-r--r--Modules/_ctypes/callproc.c109
-rw-r--r--Modules/_ctypes/cfield.c37
-rw-r--r--Modules/_ctypes/ctypes.h11
-rw-r--r--Modules/_ctypes/ctypes_dlfcn.h4
-rwxr-xr-xModules/_ctypes/libffi/configure136
-rw-r--r--Modules/_ctypes/libffi/configure.ac6
-rw-r--r--Modules/_ctypes/libffi/src/x86/darwin.S56
-rw-r--r--Modules/_ctypes/libffi/src/x86/ffi_darwin.c144
-rw-r--r--Modules/_ctypes/libffi_msvc/ffi.c23
-rw-r--r--Modules/_ctypes/libffi_msvc/fficonfig.h4
-rw-r--r--Modules/_ctypes/libffi_msvc/ffitarget.h6
-rw-r--r--Modules/_ctypes/libffi_msvc/mingwin32.S228
-rw-r--r--Modules/_ctypes/malloc_closure.c4
-rw-r--r--Modules/_ctypes/stgdict.c154
-rw-r--r--Modules/_cursesmodule.c76
-rw-r--r--Modules/_elementtree.c15
-rw-r--r--Modules/_hotshot.c4
-rw-r--r--Modules/_localemodule.c2
-rw-r--r--Modules/_sqlite/connection.c134
-rw-r--r--Modules/_sqlite/cursor.c56
-rw-r--r--Modules/_sqlite/module.c150
-rw-r--r--Modules/_sqlite/module.h4
-rw-r--r--Modules/_sqlite/util.c2
-rw-r--r--Modules/_sqlite/util.h2
-rw-r--r--Modules/_sre.c191
-rw-r--r--Modules/_ssl.c29
-rw-r--r--Modules/_struct.c95
-rw-r--r--Modules/_testcapimodule.c20
-rw-r--r--Modules/_tkinter.c9
-rw-r--r--Modules/_typesmodule.c94
-rw-r--r--Modules/_weakref.c6
-rw-r--r--Modules/arraymodule.c5
-rw-r--r--Modules/binascii.c2
-rw-r--r--Modules/bz2module.c42
-rw-r--r--Modules/cPickle.c27
-rw-r--r--Modules/collectionsmodule.c21
-rw-r--r--Modules/config.c.in4
-rw-r--r--Modules/cryptmodule.c5
-rw-r--r--Modules/dlmodule.c26
-rw-r--r--Modules/expat/Makefile.in158
-rw-r--r--Modules/expat/amigaconfig.h96
-rw-r--r--Modules/expat/expat.h35
-rw-r--r--Modules/expat/expat_external.h27
-rw-r--r--Modules/expat/pyexpatns.h124
-rw-r--r--Modules/expat/xmlparse.c333
-rw-r--r--Modules/expat/xmlrole.c4
-rw-r--r--Modules/expat/xmltok.c6
-rw-r--r--Modules/expat/xmltok.h4
-rw-r--r--Modules/expat/xmltok_impl.c6
-rw-r--r--Modules/expat/xmltok_ns.c2
-rw-r--r--Modules/fcntlmodule.c4
-rw-r--r--Modules/fpectlmodule.c25
-rw-r--r--Modules/getpath.c10
-rw-r--r--Modules/itertoolsmodule.c10
-rw-r--r--Modules/main.c12
-rw-r--r--Modules/mmapmodule.c3
-rw-r--r--Modules/posixmodule.c73
-rw-r--r--Modules/pyexpat.c32
-rw-r--r--Modules/readline.c20
-rw-r--r--Modules/selectmodule.c20
-rw-r--r--Modules/socketmodule.c224
-rw-r--r--Modules/spwdmodule.c2
-rw-r--r--Modules/sre.h24
-rw-r--r--Modules/threadmodule.c57
-rw-r--r--Modules/timemodule.c42
-rw-r--r--Modules/unicodedata.c11
-rw-r--r--Modules/zlibmodule.c6
73 files changed, 2370 insertions, 1223 deletions
diff --git a/Modules/Setup.dist b/Modules/Setup.dist
index 1b2502d..46f4253 100644
--- a/Modules/Setup.dist
+++ b/Modules/Setup.dist
@@ -59,7 +59,7 @@
#
# In addition, *static* explicitly declares the following modules to
# be static. Lines containing "*static*" and "*shared*" may thus
-# alternate thoughout this file.
+# alternate throughout this file.
# NOTE: As a standard policy, as many modules as can be supported by a
# platform should be present. The distribution comes with all modules
@@ -234,16 +234,19 @@ GLHACK=-Dclear=__GLclear
#rgbimg rgbimgmodule.c # Read SGI RGB image files (but coded portably)
-# The md5 module implements the RSA Data Security, Inc. MD5
+# Note that the _md5 and _sha modules are normally only built if the
+# system does not have the OpenSSL libs containing an optimized version.
+
+# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321. The necessary files
# md5.c and md5.h are included here.
-#md5 md5module.c md5.c
+#_md5 md5module.c md5.c
-# The sha module implements the SHA checksum algorithm.
+# The _sha module implements the SHA checksum algorithm.
# (NIST's Secure Hash Algorithm.)
-#sha shamodule.c
+#_sha shamodule.c
# SGI IRIX specific modules -- off by default.
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index 9220866..2a3ac5c 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -98,12 +98,12 @@
#error "eek! DBVER can't handle minor versions > 9"
#endif
-#define PY_BSDDB_VERSION "4.4.4"
+#define PY_BSDDB_VERSION "4.4.5"
static char *rcs_id = "$Id$";
#if (PY_VERSION_HEX < 0x02050000)
-#define Py_ssize_t int
+typedef int Py_ssize_t;
#endif
#ifdef WITH_THREAD
@@ -528,6 +528,7 @@ static int makeDBError(int err)
PyObject *errObj = NULL;
PyObject *errTuple = NULL;
int exceptionRaised = 0;
+ unsigned int bytes_left;
switch (err) {
case 0: /* successful, no error */ break;
@@ -535,12 +536,15 @@ static int makeDBError(int err)
#if (DBVER < 41)
case DB_INCOMPLETE:
#if INCOMPLETE_IS_WARNING
- our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt));
- if (_db_errmsg[0]) {
+ bytes_left = our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt));
+ /* Ensure that bytes_left never goes negative */
+ if (_db_errmsg[0] && bytes_left < (sizeof(errTxt) - 4)) {
+ bytes_left = sizeof(errTxt) - bytes_left - 4 - 1;
+ assert(bytes_left >= 0);
strcat(errTxt, " -- ");
- strcat(errTxt, _db_errmsg);
- _db_errmsg[0] = 0;
+ strncat(errTxt, _db_errmsg, bytes_left);
}
+ _db_errmsg[0] = 0;
#ifdef HAVE_WARNINGS
exceptionRaised = PyErr_Warn(PyExc_RuntimeWarning, errTxt);
#else
@@ -588,12 +592,15 @@ static int makeDBError(int err)
}
if (errObj != NULL) {
- our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt));
- if (_db_errmsg[0]) {
+ bytes_left = our_strlcpy(errTxt, db_strerror(err), sizeof(errTxt));
+ /* Ensure that bytes_left never goes negative */
+ if (_db_errmsg[0] && bytes_left < (sizeof(errTxt) - 4)) {
+ bytes_left = sizeof(errTxt) - bytes_left - 4 - 1;
+ assert(bytes_left >= 0);
strcat(errTxt, " -- ");
- strcat(errTxt, _db_errmsg);
- _db_errmsg[0] = 0;
+ strncat(errTxt, _db_errmsg, bytes_left);
}
+ _db_errmsg[0] = 0;
errTuple = Py_BuildValue("(is)", err, errTxt);
PyErr_SetObject(errObj, errTuple);
@@ -798,10 +805,12 @@ newDBObject(DBEnvObject* arg, int flags)
MYDB_BEGIN_ALLOW_THREADS;
err = db_create(&self->db, db_env, flags);
- self->db->set_errcall(self->db, _db_errorCallback);
+ if (self->db != NULL) {
+ self->db->set_errcall(self->db, _db_errorCallback);
#if (DBVER >= 33)
- self->db->app_private = (void*)self;
+ self->db->app_private = (void*)self;
#endif
+ }
MYDB_END_ALLOW_THREADS;
/* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs
* list so that a DBEnv can refuse to close without aborting any open
@@ -2681,12 +2690,13 @@ DB_set_encrypt(DBObject* self, PyObject* args, PyObject* kwargs)
/*-------------------------------------------------------------- */
/* Mapping and Dictionary-like access routines */
-Py_ssize_t DB_length(DBObject* self)
+Py_ssize_t DB_length(PyObject* _self)
{
int err;
Py_ssize_t size = 0;
int flags = 0;
void* sp;
+ DBObject* self = (DBObject*)_self;
if (self->db == NULL) {
PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed");
@@ -2720,6 +2730,8 @@ redo_stat_for_length:
*/
if (size == 0 && (flags & DB_FAST_STAT)) {
flags = 0;
+ if (!err)
+ free(sp);
goto redo_stat_for_length;
}
@@ -3864,7 +3876,7 @@ DBEnv_dbremove(DBEnvObject* self, PyObject* args, PyObject* kwargs)
static char* kwnames[] = { "file", "database", "txn", "flags",
NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss|Oi:dbremove", kwnames,
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zOi:dbremove", kwnames,
&file, &database, &txnobj, &flags)) {
return NULL;
}
@@ -3892,7 +3904,7 @@ DBEnv_dbrename(DBEnvObject* self, PyObject* args, PyObject* kwargs)
static char* kwnames[] = { "file", "database", "newname", "txn",
"flags", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|Oi:dbrename", kwnames,
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "szs|Oi:dbrename", kwnames,
&file, &database, &newname, &txnobj, &flags)) {
return NULL;
}
@@ -5153,11 +5165,7 @@ static PyMethodDef DB_methods[] = {
static PyMappingMethods DB_mapping = {
-#if (PY_VERSION_HEX < 0x02050000)
- (inquiry)DB_length, /*mp_length*/
-#else
- (lenfunc)DB_length, /*mp_length*/
-#endif
+ DB_length, /*mp_length*/
(binaryfunc)DB_subscript, /*mp_subscript*/
(objobjargproc)DB_ass_sub, /*mp_ass_subscript*/
};
@@ -5560,15 +5568,13 @@ DBEnv_construct(PyObject* self, PyObject* args)
static PyObject*
DBSequence_construct(PyObject* self, PyObject* args, PyObject* kwargs)
{
- PyObject* dbobj = NULL;
+ PyObject* dbobj;
int flags = 0;
static char* kwnames[] = { "db", "flags", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:DBSequence", kwnames, &dbobj, &flags))
return NULL;
- if (dbobj == Py_None)
- dbobj = NULL;
- else if (dbobj && !DBObject_Check(dbobj)) {
+ if (!DBObject_Check(dbobj)) {
makeTypeError("DB", dbobj);
return NULL;
}
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 32fa82f..405fd7a 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -479,15 +479,20 @@ mbcs_decode(PyObject *self,
PyObject *args)
{
const char *data;
- Py_ssize_t size;
+ Py_ssize_t size, consumed;
const char *errors = NULL;
+ int final = 0;
+ PyObject *decoded;
- if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "t#|zi:mbcs_decode",
+ &data, &size, &errors, &final))
return NULL;
- return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
- size);
+ decoded = PyUnicode_DecodeMBCSStateful(
+ data, size, errors, final ? NULL : &consumed);
+ if (!decoded)
+ return NULL;
+ return codec_tuple(decoded, final ? size : consumed);
}
#endif /* MS_WINDOWS */
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index a0744ff..76d88de 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1,3 +1,8 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
+
/*
ToDo:
@@ -342,6 +347,14 @@ static PyMethodDef CDataType_methods[] = {
static PyObject *
CDataType_repeat(PyObject *self, Py_ssize_t length)
{
+ if (length < 0)
+ return PyErr_Format(PyExc_ValueError,
+#if (PY_VERSION_HEX < 0x02050000)
+ "Array length must be >= 0, not %d",
+#else
+ "Array length must be >= 0, not %zd",
+#endif
+ length);
return CreateArrayType(self, length);
}
@@ -1371,13 +1384,20 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(result);
return NULL;
}
+ fmt = getentry(PyString_AS_STRING(proto));
+ if (fmt == NULL) {
+ Py_DECREF(result);
+ PyErr_Format(PyExc_ValueError,
+ "_type_ '%s' not supported",
+ PyString_AS_STRING(proto));
+ return NULL;
+ }
+
stgdict = (StgDictObject *)PyObject_CallObject(
(PyObject *)&StgDict_Type, NULL);
if (!stgdict)
return NULL;
- fmt = getentry(PyString_AS_STRING(proto));
-
stgdict->ffi_type_pointer = *fmt->pffi_type;
stgdict->align = fmt->pffi_type->alignment;
stgdict->length = 0;
@@ -1620,9 +1640,8 @@ converters_from_argtypes(PyObject *ob)
for (i = 0; i < nArgs; ++i) {
PyObject *tp = PyTuple_GET_ITEM(ob, i);
- StgDictObject *dict = PyType_stgdict(tp);
PyObject *cnv = PyObject_GetAttrString(tp, "from_param");
- if (!dict || !cnv)
+ if (!cnv)
goto argtypes_error_1;
PyTuple_SET_ITEM(converters, i, cnv);
}
@@ -1633,7 +1652,7 @@ converters_from_argtypes(PyObject *ob)
Py_XDECREF(converters);
Py_DECREF(ob);
PyErr_Format(PyExc_TypeError,
- "item %d in _argtypes_ is not a valid C type", i+1);
+ "item %d in _argtypes_ has no from_param method", i+1);
return NULL;
}
@@ -1809,23 +1828,53 @@ GetKeepedObjects(CDataObject *target)
}
static PyObject *
-unique_key(CDataObject *target, int index)
+unique_key(CDataObject *target, Py_ssize_t index)
{
- char string[256]; /* XXX is that enough? */
+ char string[256];
char *cp = string;
- *cp++ = index + '0';
+ size_t bytes_left;
+
+ assert(sizeof(string) - 1 > sizeof(Py_ssize_t) * 2);
+#if (PY_VERSION_HEX < 0x02050000)
+ cp += sprintf(cp, "%x", index);
+#else
+ cp += sprintf(cp, "%x", Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
+#endif
while (target->b_base) {
- *cp++ = target->b_index + '0';
+ bytes_left = sizeof(string) - (cp - string) - 1;
+ /* Hex format needs 2 characters per byte */
+ if (bytes_left < sizeof(Py_ssize_t) * 2) {
+ PyErr_SetString(PyExc_ValueError,
+ "ctypes object structure too deep");
+ return NULL;
+ }
+#if (PY_VERSION_HEX < 0x02050000)
+ cp += sprintf(cp, ":%x", (int)target->b_index);
+#else
+ cp += sprintf(cp, ":%x", Py_SAFE_DOWNCAST(target->b_index, Py_ssize_t, int));
+#endif
target = target->b_base;
}
return PyString_FromStringAndSize(string, cp-string);
}
-/* Keep a reference to 'keep' in the 'target', at index 'index' */
+
/*
- * KeepRef travels the target's b_base pointer down to the root,
- * building a sequence of indexes during the path. The indexes, which are a
- * couple of small integers, are used to build a byte string usable as
- * key int the root object's _objects dict.
+ * Keep a reference to 'keep' in the 'target', at index 'index'.
+ *
+ * If 'keep' is None, do nothing.
+ *
+ * Otherwise create a dictionary (if it does not yet exist) id the root
+ * objects 'b_objects' item, which will store the 'keep' object under a unique
+ * key.
+ *
+ * The unique_key helper travels the target's b_base pointer down to the root,
+ * building a string containing hex-formatted indexes found during traversal,
+ * separated by colons.
+ *
+ * The index tuple is used as a key into the root object's b_objects dict.
+ *
+ * Note: This function steals a refcount of the third argument, even if it
+ * fails!
*/
static int
KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
@@ -1846,6 +1895,10 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
return 0;
}
key = unique_key(target, index);
+ if (key == NULL) {
+ Py_DECREF(keep);
+ return -1;
+ }
result = PyDict_SetItem(ob->b_objects, key, keep);
Py_DECREF(key);
Py_DECREF(keep);
@@ -2134,7 +2187,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
Py_DECREF(ob);
return result;
} else if (value == Py_None && PointerTypeObject_Check(type)) {
- *(void **)dst->b_ptr = NULL;
+ *(void **)ptr = NULL;
Py_INCREF(Py_None);
return Py_None;
} else {
@@ -2611,11 +2664,11 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
*(void **)self->b_ptr = address;
+ Py_INCREF((PyObject *)dll); /* for KeepRef */
if (-1 == KeepRef((CDataObject *)self, 0, dll)) {
Py_DECREF((PyObject *)self);
return NULL;
}
- Py_INCREF((PyObject *)dll); /* for KeepRef above */
Py_INCREF(self);
self->callable = (PyObject *)self;
@@ -2751,11 +2804,11 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
correctly...
*/
+ Py_INCREF((PyObject *)self); /* for KeepRef */
if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)self)) {
Py_DECREF((PyObject *)self);
return NULL;
}
- Py_INCREF((PyObject *)self); /* for KeepRef above */
return (PyObject *)self;
}
@@ -3520,6 +3573,7 @@ Array_item(PyObject *_self, Py_ssize_t index)
int offset, size;
StgDictObject *stgdict;
+
if (index < 0 || index >= self->b_length) {
PyErr_SetString(PyExc_IndexError,
"invalid index");
@@ -4019,7 +4073,8 @@ static PyObject *
Pointer_item(PyObject *_self, Py_ssize_t index)
{
CDataObject *self = (CDataObject *)_self;
- int size, offset;
+ int size;
+ Py_ssize_t offset;
StgDictObject *stgdict, *itemdict;
PyObject *proto;
@@ -4029,9 +4084,9 @@ Pointer_item(PyObject *_self, Py_ssize_t index)
return NULL;
}
-
stgdict = PyObject_stgdict((PyObject *)self);
assert(stgdict);
+ assert(stgdict->proto);
proto = stgdict->proto;
/* XXXXXX MAKE SURE PROTO IS NOT NULL! */
@@ -4039,7 +4094,7 @@ Pointer_item(PyObject *_self, Py_ssize_t index)
size = itemdict->size;
offset = index * itemdict->size;
- return CData_get(stgdict->proto, stgdict->getfunc, (PyObject *)self,
+ return CData_get(proto, stgdict->getfunc, (PyObject *)self,
index, size, (*(char **)self->b_ptr) + offset);
}
@@ -4048,7 +4103,9 @@ Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
{
CDataObject *self = (CDataObject *)_self;
int size;
- StgDictObject *stgdict;
+ Py_ssize_t offset;
+ StgDictObject *stgdict, *itemdict;
+ PyObject *proto;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
@@ -4063,16 +4120,17 @@ Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
}
stgdict = PyObject_stgdict((PyObject *)self);
- if (index != 0) {
- PyErr_SetString(PyExc_IndexError,
- "invalid index");
- return -1;
- }
- size = stgdict->size / stgdict->length;
+ assert(stgdict);
+ assert(stgdict->proto);
- /* XXXXX Make sure proto is NOT NULL! */
- return CData_set((PyObject *)self, stgdict->proto, stgdict->setfunc, value,
- index, size, *(void **)self->b_ptr);
+ proto = stgdict->proto;
+ /* XXXXXX MAKE SURE PROTO IS NOT NULL! */
+ itemdict = PyType_stgdict(proto);
+ size = itemdict->size;
+ offset = index * itemdict->size;
+
+ return CData_set((PyObject *)self, proto, stgdict->setfunc, value,
+ index, size, (*(char **)self->b_ptr) + offset);
}
static PyObject *
@@ -4089,8 +4147,8 @@ Pointer_get_contents(CDataObject *self, void *closure)
stgdict = PyObject_stgdict((PyObject *)self);
assert(stgdict);
return CData_FromBaseObj(stgdict->proto,
- (PyObject *)self, 0,
- *(void **)self->b_ptr);
+ (PyObject *)self, 0,
+ *(void **)self->b_ptr);
}
static int
@@ -4437,7 +4495,7 @@ cast_check_pointertype(PyObject *arg)
}
static PyObject *
-cast(void *ptr, PyObject *ctype)
+cast(void *ptr, PyObject *src, PyObject *ctype)
{
CDataObject *result;
if (0 == cast_check_pointertype(ctype))
@@ -4445,9 +4503,46 @@ cast(void *ptr, PyObject *ctype)
result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL);
if (result == NULL)
return NULL;
+
+ /*
+ The casted objects '_objects' member:
+
+ It must certainly contain the source objects one.
+ It must contain the source object itself.
+ */
+ if (CDataObject_Check(src)) {
+ CDataObject *obj = (CDataObject *)src;
+ /* CData_GetContainer will initialize src.b_objects, we need
+ this so it can be shared */
+ CData_GetContainer(obj);
+ /* But we need a dictionary! */
+ if (obj->b_objects == Py_None) {
+ Py_DECREF(Py_None);
+ obj->b_objects = PyDict_New();
+ if (obj->b_objects == NULL)
+ goto failed;
+ }
+ result->b_objects = obj->b_objects;
+ if (result->b_objects) {
+ PyObject *index;
+ int rc;
+ Py_INCREF(obj->b_objects);
+ index = PyLong_FromVoidPtr((void *)src);
+ if (index == NULL)
+ goto failed;
+ rc = PyDict_SetItem(result->b_objects, index, src);
+ Py_DECREF(index);
+ if (rc == -1)
+ goto failed;
+ }
+ }
/* Should we assert that result is a pointer type? */
memcpy(result->b_ptr, &ptr, sizeof(void *));
return (PyObject *)result;
+
+ failed:
+ Py_DECREF(result);
+ return NULL;
}
#ifdef CTYPES_UNICODE
@@ -4469,7 +4564,9 @@ init_ctypes(void)
ob_type is the metatype (the 'type'), defaults to PyType_Type,
tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
*/
+#ifdef WITH_THREAD
PyEval_InitThreads();
+#endif
m = Py_InitModule3("_ctypes", module_methods, module_docs);
if (!m)
return;
@@ -4579,7 +4676,7 @@ init_ctypes(void)
#endif
PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL));
PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI));
- PyModule_AddStringConstant(m, "__version__", "0.9.9.6");
+ PyModule_AddStringConstant(m, "__version__", "1.0.0");
PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove));
PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset));
@@ -4617,13 +4714,14 @@ init_ctypes(void)
}
/*****************************************************************
- * replacements for broken Python api functions
+ * replacements for broken Python api functions (in Python 2.3).
+ * See #1047269 Buffer overwrite in PyUnicode_AsWideChar
*/
#ifdef HAVE_WCHAR_H
PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
- int size)
+ Py_ssize_t size)
{
PyUnicodeObject *unicode;
@@ -4655,7 +4753,7 @@ PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
int My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
register wchar_t *w,
- int size)
+ Py_ssize_t size)
{
if (unicode == NULL) {
PyErr_BadInternalCall();
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
index b10d6fe..99cc7a9 100644
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -1,3 +1,8 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
+
#include <Python.h>
/*
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 4baf3aa..c091d88 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -1,3 +1,7 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
#include "Python.h"
#include "compile.h" /* required only for 2.3, as it seems */
#include "frameobject.h"
@@ -123,7 +127,9 @@ static void _CallPythonObject(void *mem,
PyObject *result;
PyObject *arglist = NULL;
int nArgs;
+#ifdef WITH_THREAD
PyGILState_STATE state = PyGILState_Ensure();
+#endif
nArgs = PySequence_Length(converters);
/* Hm. What to return in case of error?
@@ -231,8 +237,9 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print()
Py_XDECREF(result);
Done:
Py_XDECREF(arglist);
-
+#ifdef WITH_THREAD
PyGILState_Release(state);
+#endif
}
static void closure_fcn(ffi_cif *cif,
@@ -341,7 +348,9 @@ void init_callbacks_in_module(PyObject *m)
static void LoadPython(void)
{
if (!Py_IsInitialized()) {
+#ifdef WITH_THREAD
PyEval_InitThreads();
+#endif
Py_Initialize();
}
}
@@ -393,12 +402,18 @@ STDAPI DllGetClassObject(REFCLSID rclsid,
LPVOID *ppv)
{
long result;
+#ifdef WITH_THREAD
PyGILState_STATE state;
+#endif
LoadPython();
+#ifdef WITH_THREAD
state = PyGILState_Ensure();
+#endif
result = Call_GetClassObject(rclsid, riid, ppv);
+#ifdef WITH_THREAD
PyGILState_Release(state);
+#endif
return result;
}
@@ -450,9 +465,13 @@ long Call_CanUnloadNow(void)
STDAPI DllCanUnloadNow(void)
{
long result;
+#ifdef WITH_THREAD
PyGILState_STATE state = PyGILState_Ensure();
+#endif
result = Call_CanUnloadNow();
+#ifdef WITH_THREAD
PyGILState_Release(state);
+#endif
return result;
}
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 8108498..d6f875b 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1,3 +1,8 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
+
/*
* History: First version dated from 3/97, derived from my SCMLIB version
* for win16.
@@ -612,7 +617,9 @@ static int _call_function_pointer(int flags,
void *resmem,
int argcount)
{
+#ifdef WITH_THREAD
PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */
+#endif
ffi_cif cif;
int cc;
#ifdef MS_WIN32
@@ -644,8 +651,10 @@ static int _call_function_pointer(int flags,
return -1;
}
+#ifdef WITH_THREAD
if ((flags & FUNCFLAG_PYTHONAPI) == 0)
Py_UNBLOCK_THREADS
+#endif
#ifdef MS_WIN32
#ifndef DONT_USE_SEH
__try {
@@ -662,8 +671,10 @@ static int _call_function_pointer(int flags,
}
#endif
#endif
+#ifdef WITH_THREAD
if ((flags & FUNCFLAG_PYTHONAPI) == 0)
Py_BLOCK_THREADS
+#endif
#ifdef MS_WIN32
#ifndef DONT_USE_SEH
if (dwExceptionCode) {
@@ -804,14 +815,22 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
PyObject *obj;
TCHAR *text;
+ /* We absolutely have to release the GIL during COM method calls,
+ otherwise we may get a deadlock!
+ */
+#ifdef WITH_THREAD
+ Py_BEGIN_ALLOW_THREADS
+#endif
+
hr = pIunk->lpVtbl->QueryInterface(pIunk, &IID_ISupportErrorInfo, (void **)&psei);
if (FAILED(hr))
goto failed;
+
hr = psei->lpVtbl->InterfaceSupportsErrorInfo(psei, riid);
psei->lpVtbl->Release(psei);
-
if (FAILED(hr))
goto failed;
+
hr = GetErrorInfo(0, &pei);
if (hr != S_OK)
goto failed;
@@ -822,24 +841,27 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
pei->lpVtbl->GetHelpFile(pei, &helpfile);
pei->lpVtbl->GetSource(pei, &source);
+ pei->lpVtbl->Release(pei);
+
failed:
- if (pei)
- pei->lpVtbl->Release(pei);
+#ifdef WITH_THREAD
+ Py_END_ALLOW_THREADS
+#endif
progid = NULL;
ProgIDFromCLSID(&guid, &progid);
-/* XXX Is COMError derived from WindowsError or not? */
text = FormatError(errcode);
+ obj = Py_BuildValue(
#ifdef _UNICODE
- obj = Py_BuildValue("iu(uuuiu)",
+ "iu(uuuiu)",
#else
- obj = Py_BuildValue("is(uuuiu)",
+ "is(uuuiu)",
#endif
- errcode,
- text,
- descr, source, helpfile, helpcontext,
- progid);
+ errcode,
+ text,
+ descr, source, helpfile, helpcontext,
+ progid);
if (obj) {
PyErr_SetObject(ComError, obj);
Py_DECREF(obj);
@@ -1138,7 +1160,7 @@ call_commethod(PyObject *self, PyObject *args)
}
static char copy_com_pointer_doc[] =
-"CopyComPointer(a, b) -> integer\n";
+"CopyComPointer(src, dst) -> HRESULT value\n";
static PyObject *
copy_com_pointer(PyObject *self, PyObject *args)
@@ -1444,7 +1466,72 @@ set_conversion_mode(PyObject *self, PyObject *args)
}
#endif
+static PyObject *
+resize(PyObject *self, PyObject *args)
+{
+ CDataObject *obj;
+ StgDictObject *dict;
+ Py_ssize_t size;
+
+ if (!PyArg_ParseTuple(args,
+#if (PY_VERSION_HEX < 0x02050000)
+ "Oi:resize",
+#else
+ "On:resize",
+#endif
+ (PyObject *)&obj, &size))
+ return NULL;
+
+ dict = PyObject_stgdict((PyObject *)obj);
+ if (dict == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "excepted ctypes instance");
+ return NULL;
+ }
+ if (size < dict->size) {
+ PyErr_Format(PyExc_ValueError,
+#if PY_VERSION_HEX < 0x02050000
+ "minimum size is %d",
+#else
+ "minimum size is %zd",
+#endif
+ dict->size);
+ return NULL;
+ }
+ if (obj->b_needsfree == 0) {
+ PyErr_Format(PyExc_ValueError,
+ "Memory cannot be resized because this object doesn't own it");
+ return NULL;
+ }
+ if (size <= sizeof(obj->b_value)) {
+ /* internal default buffer is large enough */
+ obj->b_size = size;
+ goto done;
+ }
+ if (obj->b_size <= sizeof(obj->b_value)) {
+ /* We are currently using the objects default buffer, but it
+ isn't large enough any more. */
+ void *ptr = PyMem_Malloc(size);
+ if (ptr == NULL)
+ return PyErr_NoMemory();
+ memset(ptr, 0, size);
+ memmove(ptr, obj->b_ptr, obj->b_size);
+ obj->b_ptr = ptr;
+ obj->b_size = size;
+ } else {
+ void * ptr = PyMem_Realloc(obj->b_ptr, size);
+ if (ptr == NULL)
+ return PyErr_NoMemory();
+ obj->b_ptr = ptr;
+ obj->b_size = size;
+ }
+ done:
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
PyMethodDef module_methods[] = {
+ {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
#ifdef CTYPES_UNICODE
{"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},
#endif
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index ae0290f..3595b05 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1,3 +1,7 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
#include "Python.h"
#include <ffi.h>
@@ -61,10 +65,10 @@ CField_FromDesc(PyObject *desc, int index,
}
if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
-#ifdef MS_WIN32
+#if defined(MS_WIN32) && !defined(__MINGW32__)
&& dict->size * 8 == *pfield_size /* MSVC */
#else
- && dict->size * 8 <= *pfield_size /* GCC */
+ && dict->size * 8 <= *pfield_size /* GCC, MINGW */
#endif
&& (*pbitofs + bitsize) <= *pfield_size) {
/* continue bit field */
@@ -120,7 +124,7 @@ CField_FromDesc(PyObject *desc, int index,
self->getfunc = getfunc;
self->index = index;
- Py_XINCREF(proto);
+ Py_INCREF(proto);
self->proto = proto;
switch (fieldtype) {
@@ -1482,16 +1486,27 @@ P_set(void *ptr, PyObject *value, unsigned size)
*(void **)ptr = NULL;
_RET(value);
}
-
- v = PyLong_AsVoidPtr(value);
- if (PyErr_Occurred()) {
- /* prevent the SystemError: bad argument to internal function */
- if (!PyInt_Check(value) && !PyLong_Check(value)) {
- PyErr_SetString(PyExc_TypeError,
- "cannot be converted to pointer");
- }
+
+ if (!PyInt_Check(value) && !PyLong_Check(value)) {
+ PyErr_SetString(PyExc_TypeError,
+ "cannot be converted to pointer");
return NULL;
}
+
+#if SIZEOF_VOID_P <= SIZEOF_LONG
+ v = (void *)PyInt_AsUnsignedLongMask(value);
+#else
+#ifndef HAVE_LONG_LONG
+# error "PyLong_AsVoidPtr: sizeof(void*) > sizeof(long), but no long long"
+#elif SIZEOF_LONG_LONG < SIZEOF_VOID_P
+# error "PyLong_AsVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)"
+#endif
+ v = (void *)PyInt_AsUnsignedLongLongMask(value);
+#endif
+
+ if (PyErr_Occurred())
+ return NULL;
+
*(void **)ptr = v;
_RET(value);
}
diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h
index 7988595..303eda3 100644
--- a/Modules/_ctypes/ctypes.h
+++ b/Modules/_ctypes/ctypes.h
@@ -1,4 +1,6 @@
-/******************************************************************/
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
#if (PY_VERSION_HEX < 0x02050000)
typedef int Py_ssize_t;
@@ -59,7 +61,7 @@ struct tagCDataObject {
Py_ssize_t b_length; /* number of references we need */
Py_ssize_t b_index; /* index of this object into base's
b_object list */
- PyObject *b_objects; /* list of references we need to keep */
+ PyObject *b_objects; /* dictionary of references we need to keep, or Py_None */
union value b_value;
};
@@ -181,6 +183,7 @@ typedef struct {
PyObject *proto; /* a type or NULL */
GETFUNC getfunc; /* getter function if proto is NULL */
SETFUNC setfunc; /* setter function if proto is NULL */
+ int anonymous;
} CFieldObject;
/* A subclass of PyDictObject, used as the instance dictionary of ctypes
@@ -374,8 +377,8 @@ extern char *conversion_mode_errors;
# undef PyUnicode_AsWideChar
# define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
-extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, int);
-extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, int);
+extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t);
+extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
#endif
diff --git a/Modules/_ctypes/ctypes_dlfcn.h b/Modules/_ctypes/ctypes_dlfcn.h
index 7f632c5..d8bf904 100644
--- a/Modules/_ctypes/ctypes_dlfcn.h
+++ b/Modules/_ctypes/ctypes_dlfcn.h
@@ -1,4 +1,6 @@
-/******************************************************************/
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
#ifndef _CTYPES_DLFCN_H_
#define _CTYPES_DLFCN_H_
diff --git a/Modules/_ctypes/libffi/configure b/Modules/_ctypes/libffi/configure
index 9fdd654..9eded5a 100755
--- a/Modules/_ctypes/libffi/configure
+++ b/Modules/_ctypes/libffi/configure
@@ -934,7 +934,7 @@ esac
else
echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
fi
- cd $ac_popdir
+ cd "$ac_popdir"
done
fi
@@ -1973,8 +1973,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2032,8 +2031,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2149,8 +2147,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2204,8 +2201,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2250,8 +2246,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2295,8 +2290,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2623,8 +2617,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2794,8 +2787,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -2862,8 +2854,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3047,8 +3038,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3111,8 +3101,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3290,8 +3279,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3408,8 +3396,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3483,6 +3470,12 @@ fi
TARGETDIR="unknown"
case "$host" in
+mips*-*-openbsd*) TARGET=MIPS; TARGETDIR=mips;;
+sparc-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
+sparc64-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
+alpha*-*-openbsd*) TARGET=ALPHA; TARGETDIR=alpha;;
+m68k-*-openbsd*) TARGET=M68K; TARGETDIR=m68k;;
+powerpc-*-openbsd*) TARGET=POWERPC; TARGETDIR=powerpc;;
i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
@@ -3575,8 +3568,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3777,8 +3769,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3841,8 +3832,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -3923,8 +3913,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4065,8 +4054,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4202,8 +4190,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4265,8 +4252,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4306,8 +4292,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4363,8 +4348,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4404,8 +4388,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4469,8 +4452,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4501,10 +4483,8 @@ See \`config.log' for more details." >&2;}
esac
else
if test "$cross_compiling" = yes; then
- { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
+ { { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
+echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
{ (exit 1); exit 1; }; }
else
cat >conftest.$ac_ext <<_ACEOF
@@ -4616,8 +4596,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4679,8 +4658,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4720,8 +4698,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4777,8 +4754,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4818,8 +4794,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4883,8 +4858,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -4915,10 +4889,8 @@ See \`config.log' for more details." >&2;}
esac
else
if test "$cross_compiling" = yes; then
- { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
+ { { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
+echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
{ (exit 1); exit 1; }; }
else
cat >conftest.$ac_ext <<_ACEOF
@@ -5048,8 +5020,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -5091,8 +5062,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -5149,8 +5119,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -5282,8 +5251,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -5349,8 +5317,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
- { ac_try='test -z "$ac_c_werror_flag"
- || test ! -s conftest.err'
+ { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
@@ -6309,11 +6276,6 @@ esac
- if test x"$ac_file" != x-; then
- { echo "$as_me:$LINENO: creating $ac_file" >&5
-echo "$as_me: creating $ac_file" >&6;}
- rm -f "$ac_file"
- fi
# Let's still pretend it is `configure' which instantiates (i.e., don't
# use $as_me), people would be surprised to read:
# /* config.h. Generated by config.status. */
@@ -6352,6 +6314,12 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
fi;;
esac
done` || { (exit 1); exit 1; }
+
+ if test x"$ac_file" != x-; then
+ { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+ rm -f "$ac_file"
+ fi
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
sed "$ac_vpsub
diff --git a/Modules/_ctypes/libffi/configure.ac b/Modules/_ctypes/libffi/configure.ac
index a0d7513..384959e 100644
--- a/Modules/_ctypes/libffi/configure.ac
+++ b/Modules/_ctypes/libffi/configure.ac
@@ -21,6 +21,12 @@ AC_FUNC_MMAP_BLACKLIST
TARGETDIR="unknown"
case "$host" in
+mips*-*-openbsd*) TARGET=MIPS; TARGETDIR=mips;;
+sparc-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
+sparc64-*-openbsd*) TARGET=SPARC; TARGETDIR=sparc;;
+alpha*-*-openbsd*) TARGET=ALPHA; TARGETDIR=alpha;;
+m68k-*-openbsd*) TARGET=M68K; TARGETDIR=m68k;;
+powerpc-*-openbsd*) TARGET=POWERPC; TARGETDIR=powerpc;;
i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
diff --git a/Modules/_ctypes/libffi/src/x86/darwin.S b/Modules/_ctypes/libffi/src/x86/darwin.S
index c5e55b5..d91bdc0 100644
--- a/Modules/_ctypes/libffi/src/x86/darwin.S
+++ b/Modules/_ctypes/libffi/src/x86/darwin.S
@@ -35,6 +35,13 @@
#include <fficonfig.h>
#include <ffi.h>
+#ifdef PyObjC_STRICT_DEBUGGING
+ /* XXX: Debugging of stack alignment, to be removed */
+#define ASSERT_STACK_ALIGNED movdqa -16(%esp), %xmm0
+#else
+#define ASSERT_STACK_ALIGNED
+#endif
+
.text
.globl _ffi_prep_args
@@ -47,30 +54,41 @@ _ffi_call_SYSV:
pushl %ebp
.LCFI0:
movl %esp,%ebp
+ subl $8,%esp
+ ASSERT_STACK_ALIGNED
.LCFI1:
/* Make room for all of the new args. */
movl 16(%ebp),%ecx
subl %ecx,%esp
+ ASSERT_STACK_ALIGNED
+
movl %esp,%eax
/* Place all of the ffi_prep_args in position */
+ subl $8,%esp
pushl 12(%ebp)
pushl %eax
call *8(%ebp)
+ ASSERT_STACK_ALIGNED
+
/* Return stack to previous state and call the function */
- addl $8,%esp
+ addl $16,%esp
- call *28(%ebp)
+ ASSERT_STACK_ALIGNED
- /* Remove the space we pushed for the args */
+ call *28(%ebp)
+
+ /* XXX: return returns return with 'ret $4', that upsets the stack! */
movl 16(%ebp),%ecx
addl %ecx,%esp
+
/* Load %ecx with the return type code */
movl 20(%ebp),%ecx
+
/* If the return value pointer is NULL, assume no return value. */
cmpl $0,24(%ebp)
jne retint
@@ -117,17 +135,47 @@ retlongdouble:
retint64:
cmpl $FFI_TYPE_SINT64,%ecx
- jne retstruct
+ jne retstruct1b
/* Load %ecx with the pointer to storage for the return value */
movl 24(%ebp),%ecx
movl %eax,0(%ecx)
movl %edx,4(%ecx)
+ jmp epilogue
+
+retstruct1b:
+ cmpl $FFI_TYPE_SINT8,%ecx
+ jne retstruct2b
+ movl 24(%ebp),%ecx
+ movb %al,0(%ecx)
+ jmp epilogue
+
+retstruct2b:
+ cmpl $FFI_TYPE_SINT16,%ecx
+ jne retstruct
+ movl 24(%ebp),%ecx
+ movw %ax,0(%ecx)
+ jmp epilogue
retstruct:
+ cmpl $FFI_TYPE_STRUCT,%ecx
+ jne noretval
/* Nothing to do! */
+ subl $4,%esp
+
+ ASSERT_STACK_ALIGNED
+
+ addl $8,%esp
+ movl %ebp, %esp
+ popl %ebp
+ ret
+
noretval:
epilogue:
+ ASSERT_STACK_ALIGNED
+ addl $8, %esp
+
+
movl %ebp,%esp
popl %ebp
ret
diff --git a/Modules/_ctypes/libffi/src/x86/ffi_darwin.c b/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
index 4f82b3a..c9742d8 100644
--- a/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
+++ b/Modules/_ctypes/libffi/src/x86/ffi_darwin.c
@@ -140,7 +140,7 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
-#if !defined(X86_WIN32)
+#if !defined(X86_WIN32) && !defined(X86_DARWIN)
case FFI_TYPE_STRUCT:
#endif
case FFI_TYPE_SINT64:
@@ -154,7 +154,7 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
cif->flags = FFI_TYPE_SINT64;
break;
-#if defined X86_WIN32
+#if defined(X86_WIN32) || defined(X86_DARWIN)
case FFI_TYPE_STRUCT:
if (cif->rtype->size == 1)
@@ -186,10 +186,11 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
}
/* Darwin: The stack needs to be aligned to a multiple of 16 bytes */
-#if 0
+#if 1
cif->bytes = (cif->bytes + 15) & ~0xF;
#endif
+
return FFI_OK;
}
@@ -221,7 +222,6 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
/*@dependent@*/ void **avalue)
{
extended_cif ecif;
- int flags;
ecif.cif = cif;
ecif.avalue = avalue;
@@ -238,20 +238,6 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
else
ecif.rvalue = rvalue;
- flags = cif->flags;
- if (flags == FFI_TYPE_STRUCT) {
- if (cif->rtype->size == 8) {
- flags = FFI_TYPE_SINT64;
- } else if (cif->rtype->size == 4) {
- flags = FFI_TYPE_INT;
- } else if (cif->rtype->size == 2) {
- flags = FFI_TYPE_INT;
- } else if (cif->rtype->size == 1) {
- flags = FFI_TYPE_INT;
- }
- }
-
-
switch (cif->abi)
{
case FFI_SYSV:
@@ -260,8 +246,8 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
* block is a multiple of 16. Then add 8 to compensate for local variables
* in ffi_call_SYSV.
*/
- ffi_call_SYSV(ffi_prep_args, &ecif, ALIGN(cif->bytes, 16) +8,
- flags, ecif.rvalue, fn);
+ ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes,
+ cif->flags, ecif.rvalue, fn);
/*@=usedef@*/
break;
#ifdef X86_WIN32
@@ -281,8 +267,6 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
/** private members **/
-static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
- void** args, ffi_cif* cif);
static void ffi_closure_SYSV (ffi_closure *)
__attribute__ ((regparm(1)));
#if !FFI_NO_RAW_API
@@ -290,6 +274,48 @@ static void ffi_closure_raw_SYSV (ffi_raw_closure *)
__attribute__ ((regparm(1)));
#endif
+/*@-exportheader@*/
+static inline void
+ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
+ void **avalue, ffi_cif *cif)
+/*@=exportheader@*/
+{
+ register unsigned int i;
+ register void **p_argv;
+ register char *argp;
+ register ffi_type **p_arg;
+
+ argp = stack;
+
+ if (retval_on_stack(cif->rtype)) {
+ *rvalue = *(void **) argp;
+ argp += 4;
+ }
+
+ p_argv = avalue;
+
+ for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
+ {
+ size_t z;
+
+ /* Align if necessary */
+ if ((sizeof(int) - 1) & (unsigned) argp) {
+ argp = (char *) ALIGN(argp, sizeof(int));
+ }
+
+ z = (*p_arg)->size;
+
+ /* because we're little endian, this is what it turns into. */
+
+ *p_argv = (void*) argp;
+
+ p_argv++;
+ argp += z;
+ }
+
+ return;
+}
+
/* This function is jumped to by the trampoline */
static void
@@ -302,10 +328,10 @@ ffi_closure_SYSV (closure)
// our various things...
ffi_cif *cif;
void **arg_area;
- unsigned short rtype;
void *resp = (void*)&res;
void *args = __builtin_dwarf_cfa ();
+
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
@@ -319,94 +345,52 @@ ffi_closure_SYSV (closure)
(closure->fun) (cif, resp, arg_area, closure->user_data);
- rtype = cif->flags;
-
- if (!retval_on_stack(cif->rtype) && cif->flags == FFI_TYPE_STRUCT) {
- if (cif->rtype->size == 8) {
- rtype = FFI_TYPE_SINT64;
- } else {
- rtype = FFI_TYPE_INT;
- }
- }
-
/* now, do a generic return based on the value of rtype */
- if (rtype == FFI_TYPE_INT)
+ if (cif->flags == FFI_TYPE_INT)
{
asm ("movl (%0),%%eax" : : "r" (resp) : "eax");
}
- else if (rtype == FFI_TYPE_FLOAT)
+ else if (cif->flags == FFI_TYPE_FLOAT)
{
asm ("flds (%0)" : : "r" (resp) : "st" );
}
- else if (rtype == FFI_TYPE_DOUBLE)
+ else if (cif->flags == FFI_TYPE_DOUBLE)
{
asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" );
}
- else if (rtype == FFI_TYPE_LONGDOUBLE)
+ else if (cif->flags == FFI_TYPE_LONGDOUBLE)
{
asm ("fldt (%0)" : : "r" (resp) : "st", "st(1)" );
}
- else if (rtype == FFI_TYPE_SINT64)
+ else if (cif->flags == FFI_TYPE_SINT64)
{
asm ("movl 0(%0),%%eax;"
"movl 4(%0),%%edx"
: : "r"(resp)
: "eax", "edx");
}
-#ifdef X86_WIN32
- else if (rtype == FFI_TYPE_SINT8) /* 1-byte struct */
+#if defined(X86_WIN32) || defined(X86_DARWIN)
+ else if (cif->flags == FFI_TYPE_SINT8) /* 1-byte struct */
{
asm ("movsbl (%0),%%eax" : : "r" (resp) : "eax");
}
- else if (rtype == FFI_TYPE_SINT16) /* 2-bytes struct */
+ else if (cif->flags == FFI_TYPE_SINT16) /* 2-bytes struct */
{
asm ("movswl (%0),%%eax" : : "r" (resp) : "eax");
}
#endif
-}
-/*@-exportheader@*/
-static void
-ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
- void **avalue, ffi_cif *cif)
-/*@=exportheader@*/
-{
- register unsigned int i;
- register void **p_argv;
- register char *argp;
- register ffi_type **p_arg;
-
- argp = stack;
-
- if (retval_on_stack(cif->rtype)) {
- *rvalue = *(void **) argp;
- argp += 4;
- }
-
- p_argv = avalue;
-
- for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
+ else if (cif->flags == FFI_TYPE_STRUCT)
{
- size_t z;
-
- /* Align if necessary */
- if ((sizeof(int) - 1) & (unsigned) argp) {
- argp = (char *) ALIGN(argp, sizeof(int));
- }
-
- z = (*p_arg)->size;
-
- /* because we're little endian, this is what it turns into. */
-
- *p_argv = (void*) argp;
-
- p_argv++;
- argp += z;
+ asm ("lea -8(%ebp),%esp;"
+ "pop %esi;"
+ "pop %edi;"
+ "pop %ebp;"
+ "ret $4");
}
-
- return;
}
+
/* How to make a trampoline. Derived from gcc/config/i386/i386.c. */
#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
diff --git a/Modules/_ctypes/libffi_msvc/ffi.c b/Modules/_ctypes/libffi_msvc/ffi.c
index e5600b2..9af6b71 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.c
+++ b/Modules/_ctypes/libffi_msvc/ffi.c
@@ -227,11 +227,7 @@ ffi_closure_SYSV (ffi_closure *closure, int *argp)
void **arg_area;
unsigned short rtype;
void *resp = (void*)&res;
-//#ifdef _MSC_VER
void *args = &argp[1];
-//#else
-// void *args = __builtin_dwarf_cfa ();
-//#endif
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
@@ -353,10 +349,6 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
/* How to make a trampoline. Derived from gcc/config/i386/i386.c. */
-/* MOV EDX, ESP is 0x8b 0xd4 */
-
-//#ifdef _MSC_VER
-
#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX,BYTES) \
{ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
@@ -365,26 +357,13 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
*(unsigned char*) &__tramp[0] = 0xb9; \
*(unsigned int*) &__tramp[1] = __ctx; /* mov ecx, __ctx */ \
*(unsigned char*) &__tramp[5] = 0x8b; \
- *(unsigned char*) &__tramp[6] = 0xd4; \
+ *(unsigned char*) &__tramp[6] = 0xd4; /* mov edx, esp */ \
*(unsigned char*) &__tramp[7] = 0xe8; \
*(unsigned int*) &__tramp[8] = __dis; /* call __fun */ \
*(unsigned char*) &__tramp[12] = 0xC2; /* ret BYTES */ \
*(unsigned short*) &__tramp[13] = BYTES; \
}
-//#else
-//#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX,BYTES) \
-//({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
-// unsigned int __fun = (unsigned int)(FUN); \
-// unsigned int __ctx = (unsigned int)(CTX); \
-// unsigned int __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \
-// *(unsigned char*) &__tramp[0] = 0xb8; \
-// *(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
-// *(unsigned char *) &__tramp[5] = 0xe9; \
-// *(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \
-// })
-//#endif
-
/* the cif must already be prep'ed */
ffi_status
diff --git a/Modules/_ctypes/libffi_msvc/fficonfig.h b/Modules/_ctypes/libffi_msvc/fficonfig.h
index 25b6305..c14f653 100644
--- a/Modules/_ctypes/libffi_msvc/fficonfig.h
+++ b/Modules/_ctypes/libffi_msvc/fficonfig.h
@@ -3,8 +3,10 @@
/* fficonfig.h. Generated automatically by configure. */
/* fficonfig.h.in. Generated automatically from configure.in by autoheader. */
-/* Defines for MSVC */
+/* Define this for MSVC, but not for mingw32! */
+#ifdef _MSC_VER
#define __attribute__(x) /* */
+#endif
#define alloca _alloca
/*----------------------------------------------------------------*/
diff --git a/Modules/_ctypes/libffi_msvc/ffitarget.h b/Modules/_ctypes/libffi_msvc/ffitarget.h
index 57d275b..78c0c37 100644
--- a/Modules/_ctypes/libffi_msvc/ffitarget.h
+++ b/Modules/_ctypes/libffi_msvc/ffitarget.h
@@ -71,11 +71,7 @@ typedef enum ffi_abi {
#define FFI_TRAMPOLINE_SIZE 24
#define FFI_NATIVE_RAW_API 0
#else
-#ifdef _MSC_VER
-# define FFI_TRAMPOLINE_SIZE 15
-#else
-# define FFI_TRAMPOLINE_SIZE 10
-#endif
+#define FFI_TRAMPOLINE_SIZE 15
#define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
#endif
diff --git a/Modules/_ctypes/libffi_msvc/mingwin32.S b/Modules/_ctypes/libffi_msvc/mingwin32.S
deleted file mode 100644
index e71f2b2..0000000
--- a/Modules/_ctypes/libffi_msvc/mingwin32.S
+++ /dev/null
@@ -1,228 +0,0 @@
-/* -----------------------------------------------------------------------
- win32.S - Copyright (c) 1996, 1998, 2001, 2002 Red Hat, Inc.
- Copyright (c) 2001 John Beniton
- Copyright (c) 2002 Ranjit Mathew
-
-
- X86 Foreign Function Interface
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- ``Software''), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- ----------------------------------------------------------------------- */
-
-#define LIBFFI_ASM
-#include <fficonfig.h>
-#include <ffi.h>
-
-.text
-
-.globl ffi_prep_args
-
- # This assumes we are using gas.
- .balign 16
-.globl _ffi_call_SYSV
-
-_ffi_call_SYSV:
- pushl %ebp
- movl %esp,%ebp
-
- # Make room for all of the new args.
- movl 16(%ebp),%ecx
- subl %ecx,%esp
-
- movl %esp,%eax
-
- # Place all of the ffi_prep_args in position
- pushl 12(%ebp)
- pushl %eax
- call *8(%ebp)
-
- # Return stack to previous state and call the function
- addl $8,%esp
-
- # FIXME: Align the stack to a 128-bit boundary to avoid
- # potential performance hits.
-
- call *28(%ebp)
-
- # Remove the space we pushed for the args
- movl 16(%ebp),%ecx
- addl %ecx,%esp
-
- # Load %ecx with the return type code
- movl 20(%ebp),%ecx
-
- # If the return value pointer is NULL, assume no return value.
- cmpl $0,24(%ebp)
- jne retint
-
- # Even if there is no space for the return value, we are
- # obliged to handle floating-point values.
- cmpl $2,%ecx # Float_type
- jne noretval
- fstp %st(0)
-
- jmp epilogue
-
-retint:
- cmpl $1,%ecx # Int_type
- jne retfloat
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- movl %eax,0(%ecx)
- jmp epilogue
-
-retfloat:
- cmpl $2,%ecx # Float_type
- jne retdouble
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstps (%ecx)
- jmp epilogue
-
-retdouble:
- cmpl $3,%ecx # Double_type
- jne retlongdouble
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstpl (%ecx)
- jmp epilogue
-
-retlongdouble:
- cmpl $4,%ecx # Longdouble_type
- jne retint64
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstpt (%ecx)
- jmp epilogue
-
-retint64:
- cmpl $12,%ecx # SINT64_type
- jne retstruct
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- movl %eax,0(%ecx)
- movl %edx,4(%ecx)
-
-retstruct:
- # Nothing to do!
-
-noretval:
-epilogue:
- movl %ebp,%esp
- popl %ebp
- ret
-
-.ffi_call_SYSV_end:
-
- # This assumes we are using gas.
- .balign 16
-.globl _ffi_call_STDCALL
-
-_ffi_call_STDCALL:
- pushl %ebp
- movl %esp,%ebp
-
- # Make room for all of the new args.
- movl 16(%ebp),%ecx
- subl %ecx,%esp
-
- movl %esp,%eax
-
- # Place all of the ffi_prep_args in position
- pushl 12(%ebp)
- pushl %eax
- call *8(%ebp)
-
- # Return stack to previous state and call the function
- addl $8,%esp
-
- # FIXME: Align the stack to a 128-bit boundary to avoid
- # potential performance hits.
-
- call *28(%ebp)
-
- # stdcall functions pop arguments off the stack themselves
-
- # Load %ecx with the return type code
- movl 20(%ebp),%ecx
-
- # If the return value pointer is NULL, assume no return value.
- cmpl $0,24(%ebp)
- jne sc_retint
-
- # Even if there is no space for the return value, we are
- # obliged to handle floating-point values.
- cmpl $2,%ecx # Float_type
- jne sc_noretval
- fstp %st(0)
-
- jmp sc_epilogue
-
-sc_retint:
- cmpl $1,%ecx # Int_type
- jne sc_retfloat
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- movl %eax,0(%ecx)
- jmp sc_epilogue
-
-sc_retfloat:
- cmpl $2,%ecx # Float_type
- jne sc_retdouble
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstps (%ecx)
- jmp sc_epilogue
-
-sc_retdouble:
- cmpl $2,%ecx # Double_type
- jne sc_retlongdouble
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstpl (%ecx)
- jmp sc_epilogue
-
-sc_retlongdouble:
- cmpl $4,%ecx # Longdouble_type
- jne sc_retint64
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- fstpt (%ecx)
- jmp sc_epilogue
-
-sc_retint64:
- cmpl $12,%ecx # SINT64_Type
- jne sc_retstruct
- # Load %ecx with the pointer to storage for the return value
- movl 24(%ebp),%ecx
- movl %eax,0(%ecx)
- movl %edx,4(%ecx)
-
-sc_retstruct:
- # Nothing to do!
-
-sc_noretval:
-sc_epilogue:
- movl %ebp,%esp
- popl %ebp
- ret
-
-.ffi_call_STDCALL_end:
-
diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c
index 29e9f4c..4cd5dd6 100644
--- a/Modules/_ctypes/malloc_closure.c
+++ b/Modules/_ctypes/malloc_closure.c
@@ -1,3 +1,7 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
#include <Python.h>
#include <ffi.h>
#ifdef MS_WIN32
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index c1c30f1..b4d8196 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -1,3 +1,7 @@
+/*****************************************************************
+ This file should be kept compatible with Python 2.3, see PEP 291.
+ *****************************************************************/
+
#include "Python.h"
#include <ffi.h>
#ifdef MS_WIN32
@@ -128,42 +132,148 @@ PyType_stgdict(PyObject *obj)
if (!PyType_Check(obj))
return NULL;
type = (PyTypeObject *)obj;
- if (!type->tp_dict || !StgDict_Check(type->tp_dict))
+ if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict))
return NULL;
return (StgDictObject *)type->tp_dict;
}
/* May return NULL, but does not set an exception! */
+/*
+ This function should be as fast as possible, so we don't call PyType_stgdict
+ above but inline the code, and avoid the PyType_Check().
+*/
StgDictObject *
PyObject_stgdict(PyObject *self)
{
- return PyType_stgdict((PyObject *)self->ob_type);
+ PyTypeObject *type = self->ob_type;
+ if (!type->tp_dict || !StgDict_CheckExact(type->tp_dict))
+ return NULL;
+ return (StgDictObject *)type->tp_dict;
}
-#if 0
-/* work in progress: anonymous structure fields */
-int
-GetFields(PyObject *desc, int *pindex, int *psize, int *poffset, int *palign, int pack);
+/* descr is the descriptor for a field marked as anonymous. Get all the
+ _fields_ descriptors from descr->proto, create new descriptors with offset
+ and index adjusted, and stuff them into type.
+ */
+static int
+MakeFields(PyObject *type, CFieldObject *descr,
+ Py_ssize_t index, Py_ssize_t offset)
+{
+ Py_ssize_t i;
+ PyObject *fields;
+ PyObject *fieldlist;
+ fields = PyObject_GetAttrString(descr->proto, "_fields_");
+ if (fields == NULL)
+ return -1;
+ fieldlist = PySequence_Fast(fields, "_fields_ must be a sequence");
+ Py_DECREF(fields);
+ if (fieldlist == NULL)
+ return -1;
+
+ for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) {
+ PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */
+ PyObject *fname, *ftype;
+ CFieldObject *fdescr;
+ CFieldObject *new_descr;
+ /* Convert to PyArg_UnpackTuple... */
+ if (!PyArg_ParseTuple(pair, "OO", &fname, &ftype)) {
+ Py_DECREF(fieldlist);
+ return -1;
+ }
+ fdescr = (CFieldObject *)PyObject_GetAttr(descr->proto, fname);
+ if (fdescr == NULL) {
+ Py_DECREF(fieldlist);
+ return -1;
+ }
+ if (fdescr->ob_type != &CField_Type) {
+ PyErr_SetString(PyExc_TypeError, "unexpected type");
+ Py_DECREF(fdescr);
+ Py_DECREF(fieldlist);
+ return -1;
+ }
+ if (fdescr->anonymous) {
+ int rc = MakeFields(type, fdescr,
+ index + fdescr->index,
+ offset + fdescr->offset);
+ Py_DECREF(fdescr);
+ if (rc == -1) {
+ Py_DECREF(fieldlist);
+ return -1;
+ }
+ continue;
+ }
+ new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, NULL);
+ assert(new_descr->ob_type == &CField_Type);
+ if (new_descr == NULL) {
+ Py_DECREF(fdescr);
+ Py_DECREF(fieldlist);
+ return -1;
+ }
+ new_descr->size = fdescr->size;
+ new_descr->offset = fdescr->offset + offset;
+ new_descr->index = fdescr->index + index;
+ new_descr->proto = fdescr->proto;
+ Py_XINCREF(new_descr->proto);
+ new_descr->getfunc = fdescr->getfunc;
+ new_descr->setfunc = fdescr->setfunc;
+
+ Py_DECREF(fdescr);
+
+ if (-1 == PyObject_SetAttr(type, fname, (PyObject *)new_descr)) {
+ Py_DECREF(fieldlist);
+ Py_DECREF(new_descr);
+ return -1;
+ }
+ Py_DECREF(new_descr);
+ }
+ Py_DECREF(fieldlist);
+ return 0;
+}
+
+/* Iterate over the names in the type's _anonymous_ attribute, if present,
+ */
+static int
+MakeAnonFields(PyObject *type)
{
- int i;
- PyObject *tuples = PyObject_GetAttrString(desc, "_fields_");
- if (tuples == NULL)
+ PyObject *anon;
+ PyObject *anon_names;
+ Py_ssize_t i;
+
+ anon = PyObject_GetAttrString(type, "_anonymous_");
+ if (anon == NULL) {
+ PyErr_Clear();
+ return 0;
+ }
+ anon_names = PySequence_Fast(anon, "_anonymous_ must be a sequence");
+ Py_DECREF(anon);
+ if (anon_names == NULL)
return -1;
- if (!PyTuple_Check(tuples))
- return -1; /* leak */
- for (i = 0; i < PyTuple_GET_SIZE(tuples); ++i) {
- char *fname;
- PyObject *dummy;
- CFieldObject *field;
- PyObject *pair = PyTuple_GET_ITEM(tuples, i);
- if (!PyArg_ParseTuple(pair, "sO", &fname, &dummy))
- return -1; /* leak */
- field = PyObject_GetAttrString(desc, fname);
- Py_DECREF(field);
+
+ for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) {
+ PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */
+ CFieldObject *descr = (CFieldObject *)PyObject_GetAttr(type, fname);
+ if (descr == NULL) {
+ Py_DECREF(anon_names);
+ return -1;
+ }
+ assert(descr->ob_type == &CField_Type);
+ descr->anonymous = 1;
+
+ /* descr is in the field descriptor. */
+ if (-1 == MakeFields(type, (CFieldObject *)descr,
+ ((CFieldObject *)descr)->index,
+ ((CFieldObject *)descr)->offset)) {
+ Py_DECREF(descr);
+ Py_DECREF(anon_names);
+ return -1;
+ }
+ Py_DECREF(descr);
}
+
+ Py_DECREF(anon_names);
+ return 0;
}
-#endif
/*
Retrive the (optional) _pack_ attribute from a type, the _fields_ attribute,
@@ -366,5 +476,5 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
stgdict->size = size;
stgdict->align = total_align;
stgdict->length = len; /* ADD ffi_ofs? */
- return 0;
+ return MakeAnonFields(type);
}
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 71d7a69..ec55c8e 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -43,8 +43,8 @@ unsupported functions:
del_curterm delscreen dupwin inchnstr inchstr innstr keyok
mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
- mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
- resizeterm restartterm ripoffline scr_dump
+ mvwinchnstr mvwinchstr mvwinnstr newterm
+ restartterm ripoffline scr_dump
scr_init scr_restore scr_set scrl set_curterm set_term setterm
tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
vidattr vidputs waddchnstr waddchstr wchgat
@@ -819,14 +819,17 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
+#ifdef STRICT_SYSV_CURSES
+ rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
+#else
rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
+#endif
Py_END_ALLOW_THREADS
break;
case 3:
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
return NULL;
#ifdef STRICT_SYSV_CURSES
- /* Untested */
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
wgetnstr(self->win, rtn, MIN(n, 1023));
@@ -838,7 +841,7 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
#endif
break;
default:
- PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
+ PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
return NULL;
}
if (rtn2 == ERR)
@@ -1950,6 +1953,29 @@ PyCurses_IntrFlush(PyObject *self, PyObject *args)
return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
}
+#ifdef HAVE_CURSES_IS_TERM_RESIZED
+static PyObject *
+PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
+{
+ int lines;
+ int columns;
+ int result;
+
+ PyCursesInitialised
+
+ if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
+ return NULL;
+ result = is_term_resized(lines, columns);
+ if (result == TRUE) {
+ Py_INCREF(Py_True);
+ return Py_True;
+ } else {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+}
+#endif /* HAVE_CURSES_IS_TERM_RESIZED */
+
#if !defined(__NetBSD__)
static PyObject *
PyCurses_KeyName(PyObject *self, PyObject *args)
@@ -2170,6 +2196,39 @@ PyCurses_QiFlush(PyObject *self, PyObject *args)
}
}
+#ifdef HAVE_CURSES_RESIZETERM
+static PyObject *
+PyCurses_ResizeTerm(PyObject *self, PyObject *args)
+{
+ int lines;
+ int columns;
+
+ PyCursesInitialised
+
+ if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
+ return NULL;
+
+ return PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
+}
+
+#endif
+
+#ifdef HAVE_CURSES_RESIZE_TERM
+static PyObject *
+PyCurses_Resize_Term(PyObject *self, PyObject *args)
+{
+ int lines;
+ int columns;
+
+ PyCursesInitialised
+
+ if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
+ return NULL;
+
+ return PyCursesCheckERR(resize_term(lines, columns), "resize_term");
+}
+#endif /* HAVE_CURSES_RESIZE_TERM */
+
static PyObject *
PyCurses_setsyx(PyObject *self, PyObject *args)
{
@@ -2414,6 +2473,9 @@ static PyMethodDef PyCurses_methods[] = {
{"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
{"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
{"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
+#ifdef HAVE_CURSES_IS_TERM_RESIZED
+ {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
+#endif
#if !defined(__NetBSD__)
{"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
#endif
@@ -2441,6 +2503,12 @@ static PyMethodDef PyCurses_methods[] = {
{"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
{"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
{"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
+#ifdef HAVE_CURSES_RESIZETERM
+ {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
+#endif
+#ifdef HAVE_CURSES_RESIZE_TERM
+ {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
+#endif
{"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
{"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
{"setupterm", (PyCFunction)PyCurses_setupterm,
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index dda5042..fe30f30 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -717,7 +717,8 @@ element_deepcopy(ElementObject* self, PyObject* args)
LOCAL(int)
checkpath(PyObject* tag)
{
- int i, check = 1;
+ Py_ssize_t i;
+ int check = 1;
/* check if a tag contains an xpath character */
@@ -1180,7 +1181,7 @@ static int
element_setslice(PyObject* self_, Py_ssize_t start, Py_ssize_t end, PyObject* item)
{
ElementObject* self = (ElementObject*) self_;
- int i, new, old;
+ Py_ssize_t i, new, old;
PyObject* recycle = NULL;
if (!self->extra)
@@ -1426,7 +1427,7 @@ typedef struct {
PyObject* data; /* data collector (string or list), or NULL */
PyObject* stack; /* element stack */
- int index; /* current stack size (0=empty) */
+ Py_ssize_t index; /* current stack size (0=empty) */
/* element tracing */
PyObject* events; /* list of events, or NULL if not collecting */
@@ -1606,7 +1607,7 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
/* expat often generates single character data sections; handle
the most common case by resizing the existing string... */
- int size = PyString_GET_SIZE(self->data);
+ Py_ssize_t size = PyString_GET_SIZE(self->data);
if (_PyString_Resize(&self->data, size + 1) < 0)
return NULL;
PyString_AS_STRING(self->data)[size] = PyString_AS_STRING(data)[0];
@@ -1988,7 +1989,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
Py_XDECREF(res);
} else {
PyErr_Format(
- PyExc_SyntaxError, "undefined entity &%s;: line %d, column %d",
+ PyExc_SyntaxError, "undefined entity &%s;: line %ld, column %ld",
PyString_AS_STRING(key),
EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser)
@@ -2349,7 +2350,7 @@ expat_parse(XMLParserObject* self, char* data, int data_len, int final)
if (!ok) {
PyErr_Format(
- PyExc_SyntaxError, "%s: line %d, column %d",
+ PyExc_SyntaxError, "%s: line %ld, column %ld",
EXPAT(ErrorString)(EXPAT(GetErrorCode)(self->parser)),
EXPAT(GetErrorLineNumber)(self->parser),
EXPAT(GetErrorColumnNumber)(self->parser)
@@ -2456,7 +2457,7 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
{
/* activate element event reporting */
- int i;
+ Py_ssize_t i;
TreeBuilderObject* target;
PyObject* events; /* event collector */
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 5a81bfb..6d9776f 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -14,7 +14,11 @@
*/
#ifdef MS_WINDOWS
#include <windows.h>
+
+#ifdef HAVE_DIRECT_H
#include <direct.h> /* for getcwd() */
+#endif
+
typedef __int64 hs_time;
#define GETTIMEOFDAY(P_HS_TIME) \
{ LARGE_INTEGER _temp; \
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index c016cd7..abfca4e 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -16,7 +16,7 @@ This software comes with no warranty. Use at your own risk.
#include <string.h>
#include <ctype.h>
-#ifndef DONT_HAVE_ERRNO_H
+#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 64e43eb..703af15 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -34,6 +34,19 @@
static int connection_set_isolation_level(Connection* self, PyObject* isolation_level);
+
+void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len)
+{
+ /* in older SQLite versions, calling sqlite3_result_error in callbacks
+ * triggers a bug in SQLite that leads either to irritating results or
+ * segfaults, depending on the SQLite version */
+#if SQLITE_VERSION_NUMBER >= 3003003
+ sqlite3_result_error(ctx, errmsg, len);
+#else
+ PyErr_SetString(OperationalError, errmsg);
+#endif
+}
+
int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
{
static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
@@ -405,8 +418,6 @@ void _set_result(sqlite3_context* context, PyObject* py_val)
PyObject* stringval;
if ((!py_val) || PyErr_Occurred()) {
- /* Errors in callbacks are ignored, and we return NULL */
- PyErr_Clear();
sqlite3_result_null(context);
} else if (py_val == Py_None) {
sqlite3_result_null(context);
@@ -519,8 +530,17 @@ void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
Py_DECREF(args);
}
- _set_result(context, py_retval);
- Py_XDECREF(py_retval);
+ if (py_retval) {
+ _set_result(context, py_retval);
+ Py_DECREF(py_retval);
+ } else {
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+ _sqlite3_result_error(context, "user-defined function raised exception", -1);
+ }
PyGILState_Release(threadstate);
}
@@ -545,8 +565,13 @@ static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** p
*aggregate_instance = PyObject_CallFunction(aggregate_class, "");
if (PyErr_Occurred()) {
- PyErr_Clear();
*aggregate_instance = 0;
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+ _sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1);
goto error;
}
}
@@ -565,7 +590,12 @@ static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** p
Py_DECREF(args);
if (!function_result) {
- PyErr_Clear();
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+ _sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1);
}
error:
@@ -597,13 +627,16 @@ void _final_callback(sqlite3_context* context)
function_result = PyObject_CallMethod(*aggregate_instance, "finalize", "");
if (!function_result) {
- PyErr_Clear();
- Py_INCREF(Py_None);
- function_result = Py_None;
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+ _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
+ } else {
+ _set_result(context, function_result);
}
- _set_result(context, function_result);
-
error:
Py_XDECREF(*aggregate_instance);
Py_XDECREF(function_result);
@@ -631,7 +664,7 @@ void _drop_unused_statement_references(Connection* self)
for (i = 0; i < PyList_Size(self->statements); i++) {
weakref = PyList_GetItem(self->statements, i);
- if (weakref != Py_None) {
+ if (PyWeakref_GetObject(weakref) != Py_None) {
if (PyList_Append(new_list, weakref) != 0) {
Py_DECREF(new_list);
return;
@@ -699,6 +732,61 @@ PyObject* connection_create_aggregate(Connection* self, PyObject* args, PyObject
}
}
+int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
+{
+ PyObject *ret;
+ int rc;
+ PyGILState_STATE gilstate;
+
+ gilstate = PyGILState_Ensure();
+ ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
+
+ if (!ret) {
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+
+ rc = SQLITE_DENY;
+ } else {
+ if (PyInt_Check(ret)) {
+ rc = (int)PyInt_AsLong(ret);
+ } else {
+ rc = SQLITE_DENY;
+ }
+ Py_DECREF(ret);
+ }
+
+ PyGILState_Release(gilstate);
+ return rc;
+}
+
+PyObject* connection_set_authorizer(Connection* self, PyObject* args, PyObject* kwargs)
+{
+ PyObject* authorizer_cb;
+
+ static char *kwlist[] = { "authorizer_callback", NULL };
+ int rc;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_authorizer",
+ kwlist, &authorizer_cb)) {
+ return NULL;
+ }
+
+ rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb);
+
+ if (rc != SQLITE_OK) {
+ PyErr_SetString(OperationalError, "Error setting authorizer callback");
+ return NULL;
+ } else {
+ PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+}
+
int check_thread(Connection* self)
{
if (self->check_same_thread) {
@@ -975,6 +1063,24 @@ finally:
}
static PyObject *
+connection_interrupt(Connection* self, PyObject* args)
+{
+ PyObject* retval = NULL;
+
+ if (!check_connection(self)) {
+ goto finally;
+ }
+
+ sqlite3_interrupt(self->db);
+
+ Py_INCREF(Py_None);
+ retval = Py_None;
+
+finally:
+ return retval;
+}
+
+static PyObject *
connection_create_collation(Connection* self, PyObject* args)
{
PyObject* callable;
@@ -1067,6 +1173,8 @@ static PyMethodDef connection_methods[] = {
PyDoc_STR("Creates a new function. Non-standard.")},
{"create_aggregate", (PyCFunction)connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
PyDoc_STR("Creates a new aggregate. Non-standard.")},
+ {"set_authorizer", (PyCFunction)connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
+ PyDoc_STR("Sets authorizer callback. Non-standard.")},
{"execute", (PyCFunction)connection_execute, METH_VARARGS,
PyDoc_STR("Executes a SQL statement. Non-standard.")},
{"executemany", (PyCFunction)connection_executemany, METH_VARARGS,
@@ -1075,6 +1183,8 @@ static PyMethodDef connection_methods[] = {
PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
{"create_collation", (PyCFunction)connection_create_collation, METH_VARARGS,
PyDoc_STR("Creates a collation function. Non-standard.")},
+ {"interrupt", (PyCFunction)connection_interrupt, METH_NOARGS,
+ PyDoc_STR("Abort any pending database operation. Non-standard.")},
{NULL, NULL}
};
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 95a4931..a2d3cf2 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -137,6 +137,22 @@ void cursor_dealloc(Cursor* self)
self->ob_type->tp_free((PyObject*)self);
}
+PyObject* _get_converter(PyObject* key)
+{
+ PyObject* upcase_key;
+ PyObject* retval;
+
+ upcase_key = PyObject_CallMethod(key, "upper", "");
+ if (!upcase_key) {
+ return NULL;
+ }
+
+ retval = PyDict_GetItem(converters, upcase_key);
+ Py_DECREF(upcase_key);
+
+ return retval;
+}
+
int build_row_cast_map(Cursor* self)
{
int i;
@@ -174,7 +190,7 @@ int build_row_cast_map(Cursor* self)
break;
}
- converter = PyDict_GetItem(converters, key);
+ converter = _get_converter(key);
Py_DECREF(key);
break;
}
@@ -195,7 +211,7 @@ int build_row_cast_map(Cursor* self)
}
}
- converter = PyDict_GetItem(converters, py_decltype);
+ converter = _get_converter(py_decltype);
Py_DECREF(py_decltype);
}
}
@@ -228,7 +244,10 @@ PyObject* _build_column_name(const char* colname)
}
for (pos = colname;; pos++) {
- if (*pos == 0 || *pos == ' ') {
+ if (*pos == 0 || *pos == '[') {
+ if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
+ pos--;
+ }
return PyString_FromStringAndSize(colname, pos - colname);
}
}
@@ -302,23 +321,21 @@ PyObject* _fetch_one_row(Cursor* self)
}
if (converter != Py_None) {
- val_str = (const char*)sqlite3_column_text(self->statement->st, i);
+ nbytes = sqlite3_column_bytes(self->statement->st, i);
+ val_str = (const char*)sqlite3_column_blob(self->statement->st, i);
if (!val_str) {
Py_INCREF(Py_None);
converted = Py_None;
} else {
- item = PyString_FromString(val_str);
+ item = PyString_FromStringAndSize(val_str, nbytes);
if (!item) {
return NULL;
}
converted = PyObject_CallFunction(converter, "O", item);
+ Py_DECREF(item);
if (!converted) {
- /* TODO: have a way to log these errors */
- Py_INCREF(Py_None);
- converted = Py_None;
- PyErr_Clear();
+ break;
}
- Py_DECREF(item);
}
} else {
Py_BEGIN_ALLOW_THREADS
@@ -346,10 +363,10 @@ PyObject* _fetch_one_row(Cursor* self)
if (!converted) {
colname = sqlite3_column_name(self->statement->st, i);
- if (colname) {
+ if (!colname) {
colname = "<unknown column name>";
}
- PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column %s with text %s",
+ PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
colname , val_str);
PyErr_SetString(OperationalError, buf);
}
@@ -373,7 +390,12 @@ PyObject* _fetch_one_row(Cursor* self)
}
}
- PyTuple_SetItem(row, i, converted);
+ if (converted) {
+ PyTuple_SetItem(row, i, converted);
+ } else {
+ Py_INCREF(Py_None);
+ PyTuple_SetItem(row, i, Py_None);
+ }
}
if (PyErr_Occurred()) {
@@ -598,6 +620,14 @@ PyObject* _query_execute(Cursor* self, int multiple, PyObject* args)
goto error;
}
} else {
+ if (PyErr_Occurred()) {
+ /* there was an error that occurred in a user-defined callback */
+ if (_enable_callback_tracebacks) {
+ PyErr_Print();
+ } else {
+ PyErr_Clear();
+ }
+ }
_seterror(self->connection->db);
goto error;
}
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 71d0aaa..606454c 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -1,25 +1,25 @@
-/* module.c - the module itself
- *
- * Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
+ /* module.c - the module itself
+ *
+ * Copyright (C) 2004-2006 Gerhard Häring <gh@ghaering.de>
+ *
+ * This file is part of pysqlite.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
#include "connection.h"
#include "statement.h"
@@ -40,6 +40,7 @@ PyObject* Error, *Warning, *InterfaceError, *DatabaseError, *InternalError,
*NotSupportedError, *OptimizedUnicode;
PyObject* converters;
+int _enable_callback_tracebacks;
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
kwargs)
@@ -140,14 +141,42 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
static PyObject* module_register_converter(PyObject* self, PyObject* args, PyObject* kwargs)
{
- PyObject* name;
+ char* orig_name;
+ char* name = NULL;
+ char* c;
PyObject* callable;
+ PyObject* retval = NULL;
- if (!PyArg_ParseTuple(args, "OO", &name, &callable)) {
+ if (!PyArg_ParseTuple(args, "sO", &orig_name, &callable)) {
return NULL;
}
- if (PyDict_SetItem(converters, name, callable) != 0) {
+ /* convert the name to lowercase */
+ name = PyMem_Malloc(strlen(orig_name) + 2);
+ if (!name) {
+ goto error;
+ }
+ strcpy(name, orig_name);
+ for (c = name; *c != (char)0; c++) {
+ *c = (*c) & 0xDF;
+ }
+
+ if (PyDict_SetItemString(converters, name, callable) != 0) {
+ goto error;
+ }
+
+ Py_INCREF(Py_None);
+ retval = Py_None;
+error:
+ if (name) {
+ PyMem_Free(name);
+ }
+ return retval;
+}
+
+static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args, PyObject* kwargs)
+{
+ if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) {
return NULL;
}
@@ -174,13 +203,64 @@ static PyMethodDef module_methods[] = {
{"register_adapter", (PyCFunction)module_register_adapter, METH_VARARGS, PyDoc_STR("Registers an adapter with pysqlite's adapter registry. Non-standard.")},
{"register_converter", (PyCFunction)module_register_converter, METH_VARARGS, PyDoc_STR("Registers a converter with pysqlite. Non-standard.")},
{"adapt", (PyCFunction)psyco_microprotocols_adapt, METH_VARARGS, psyco_microprotocols_adapt_doc},
+ {"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks, METH_VARARGS, PyDoc_STR("Enable or disable callback functions throwing errors to stderr.")},
{NULL, NULL}
};
+struct _IntConstantPair {
+ char* constant_name;
+ int constant_value;
+};
+
+typedef struct _IntConstantPair IntConstantPair;
+
+static IntConstantPair _int_constants[] = {
+ {"PARSE_DECLTYPES", PARSE_DECLTYPES},
+ {"PARSE_COLNAMES", PARSE_COLNAMES},
+
+ {"SQLITE_OK", SQLITE_OK},
+ {"SQLITE_DENY", SQLITE_DENY},
+ {"SQLITE_IGNORE", SQLITE_IGNORE},
+ {"SQLITE_CREATE_INDEX", SQLITE_CREATE_INDEX},
+ {"SQLITE_CREATE_TABLE", SQLITE_CREATE_TABLE},
+ {"SQLITE_CREATE_TEMP_INDEX", SQLITE_CREATE_TEMP_INDEX},
+ {"SQLITE_CREATE_TEMP_TABLE", SQLITE_CREATE_TEMP_TABLE},
+ {"SQLITE_CREATE_TEMP_TRIGGER", SQLITE_CREATE_TEMP_TRIGGER},
+ {"SQLITE_CREATE_TEMP_VIEW", SQLITE_CREATE_TEMP_VIEW},
+ {"SQLITE_CREATE_TRIGGER", SQLITE_CREATE_TRIGGER},
+ {"SQLITE_CREATE_VIEW", SQLITE_CREATE_VIEW},
+ {"SQLITE_DELETE", SQLITE_DELETE},
+ {"SQLITE_DROP_INDEX", SQLITE_DROP_INDEX},
+ {"SQLITE_DROP_TABLE", SQLITE_DROP_TABLE},
+ {"SQLITE_DROP_TEMP_INDEX", SQLITE_DROP_TEMP_INDEX},
+ {"SQLITE_DROP_TEMP_TABLE", SQLITE_DROP_TEMP_TABLE},
+ {"SQLITE_DROP_TEMP_TRIGGER", SQLITE_DROP_TEMP_TRIGGER},
+ {"SQLITE_DROP_TEMP_VIEW", SQLITE_DROP_TEMP_VIEW},
+ {"SQLITE_DROP_TRIGGER", SQLITE_DROP_TRIGGER},
+ {"SQLITE_DROP_VIEW", SQLITE_DROP_VIEW},
+ {"SQLITE_INSERT", SQLITE_INSERT},
+ {"SQLITE_PRAGMA", SQLITE_PRAGMA},
+ {"SQLITE_READ", SQLITE_READ},
+ {"SQLITE_SELECT", SQLITE_SELECT},
+ {"SQLITE_TRANSACTION", SQLITE_TRANSACTION},
+ {"SQLITE_UPDATE", SQLITE_UPDATE},
+ {"SQLITE_ATTACH", SQLITE_ATTACH},
+ {"SQLITE_DETACH", SQLITE_DETACH},
+#if SQLITE_VERSION_NUMBER >= 3002001
+ {"SQLITE_ALTER_TABLE", SQLITE_ALTER_TABLE},
+ {"SQLITE_REINDEX", SQLITE_REINDEX},
+#endif
+#if SQLITE_VERSION_NUMBER >= 3003000
+ {"SQLITE_ANALYZE", SQLITE_ANALYZE},
+#endif
+ {(char*)NULL, 0}
+};
+
PyMODINIT_FUNC init_sqlite3(void)
{
PyObject *module, *dict;
PyObject *tmp_obj;
+ int i;
module = Py_InitModule("_sqlite3", module_methods);
@@ -276,17 +356,15 @@ PyMODINIT_FUNC init_sqlite3(void)
OptimizedUnicode = (PyObject*)&PyCell_Type;
PyDict_SetItemString(dict, "OptimizedUnicode", OptimizedUnicode);
- if (!(tmp_obj = PyInt_FromLong(PARSE_DECLTYPES))) {
- goto error;
+ /* Set integer constants */
+ for (i = 0; _int_constants[i].constant_name != 0; i++) {
+ tmp_obj = PyInt_FromLong(_int_constants[i].constant_value);
+ if (!tmp_obj) {
+ goto error;
+ }
+ PyDict_SetItemString(dict, _int_constants[i].constant_name, tmp_obj);
+ Py_DECREF(tmp_obj);
}
- PyDict_SetItemString(dict, "PARSE_DECLTYPES", tmp_obj);
- Py_DECREF(tmp_obj);
-
- if (!(tmp_obj = PyInt_FromLong(PARSE_COLNAMES))) {
- goto error;
- }
- PyDict_SetItemString(dict, "PARSE_COLNAMES", tmp_obj);
- Py_DECREF(tmp_obj);
if (!(tmp_obj = PyString_FromString(PYSQLITE_VERSION))) {
goto error;
@@ -306,6 +384,8 @@ PyMODINIT_FUNC init_sqlite3(void)
/* initialize the default converters */
converters_init(dict);
+ _enable_callback_tracebacks = 0;
+
/* Original comment form _bsddb.c in the Python core. This is also still
* needed nowadays for Python 2.3/2.4.
*
diff --git a/Modules/_sqlite/module.h b/Modules/_sqlite/module.h
index f3e2aa1..e514bd1 100644
--- a/Modules/_sqlite/module.h
+++ b/Modules/_sqlite/module.h
@@ -25,7 +25,7 @@
#define PYSQLITE_MODULE_H
#include "Python.h"
-#define PYSQLITE_VERSION "2.2.2"
+#define PYSQLITE_VERSION "2.3.2"
extern PyObject* Error;
extern PyObject* Warning;
@@ -50,6 +50,8 @@ extern PyObject* time_sleep;
*/
extern PyObject* converters;
+extern int _enable_callback_tracebacks;
+
#define PARSE_DECLTYPES 1
#define PARSE_COLNAMES 2
#endif
diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c
index 33748a6..f5a7233 100644
--- a/Modules/_sqlite/util.c
+++ b/Modules/_sqlite/util.c
@@ -38,7 +38,7 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connectio
/**
* Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occured).
+ * Returns the error code (0 means no error occurred).
*/
int _seterror(sqlite3* db)
{
diff --git a/Modules/_sqlite/util.h b/Modules/_sqlite/util.h
index e99a4dd..7ce3d40 100644
--- a/Modules/_sqlite/util.h
+++ b/Modules/_sqlite/util.h
@@ -32,7 +32,7 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connectio
/**
* Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occured).
+ * Returns the error code (0 means no error occurred).
*/
int _seterror(sqlite3* db);
#endif
diff --git a/Modules/_sre.c b/Modules/_sre.c
index d4e6051..68d511e 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -39,6 +39,8 @@
static char copyright[] =
" SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB ";
+#define PY_SSIZE_T_CLEAN
+
#include "Python.h"
#include "structmember.h" /* offsetof */
@@ -261,9 +263,9 @@ data_stack_dealloc(SRE_STATE* state)
}
static int
-data_stack_grow(SRE_STATE* state, int size)
+data_stack_grow(SRE_STATE* state, Py_ssize_t size)
{
- int minsize, cursize;
+ Py_ssize_t minsize, cursize;
minsize = state->data_stack_base+size;
cursize = state->data_stack_size;
if (cursize < minsize) {
@@ -335,7 +337,7 @@ SRE_AT(SRE_STATE* state, SRE_CHAR* ptr, SRE_CODE at)
{
/* check if pointer is at given position */
- int thisp, thatp;
+ Py_ssize_t thisp, thatp;
switch (at) {
@@ -476,7 +478,7 @@ SRE_CHARSET(SRE_CODE* set, SRE_CODE ch)
case SRE_OP_BIGCHARSET:
/* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */
{
- int count, block;
+ Py_ssize_t count, block;
count = *(set++);
if (sizeof(SRE_CODE) == 2) {
@@ -510,15 +512,15 @@ SRE_CHARSET(SRE_CODE* set, SRE_CODE ch)
}
}
-LOCAL(int) SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern);
+LOCAL(Py_ssize_t) SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern);
-LOCAL(int)
-SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, int maxcount)
+LOCAL(Py_ssize_t)
+SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, Py_ssize_t maxcount)
{
SRE_CODE chr;
SRE_CHAR* ptr = (SRE_CHAR *)state->ptr;
SRE_CHAR* end = (SRE_CHAR *)state->end;
- int i;
+ Py_ssize_t i;
/* adjust end */
if (maxcount < end - ptr && maxcount != 65535)
@@ -608,7 +610,7 @@ SRE_INFO(SRE_STATE* state, SRE_CODE* pattern)
SRE_CHAR* end = state->end;
SRE_CHAR* ptr = state->ptr;
- int i;
+ Py_ssize_t i;
/* check minimal length */
if (pattern[3] && (end - ptr) < pattern[3])
@@ -785,13 +787,13 @@ do { \
while (0) /* gcc doesn't like labels at end of scopes */ \
typedef struct {
- int last_ctx_pos;
- int jump;
+ Py_ssize_t last_ctx_pos;
+ Py_ssize_t jump;
SRE_CHAR* ptr;
SRE_CODE* pattern;
- int count;
- int lastmark;
- int lastindex;
+ Py_ssize_t count;
+ Py_ssize_t lastmark;
+ Py_ssize_t lastindex;
union {
SRE_CODE chr;
SRE_REPEAT* rep;
@@ -800,13 +802,13 @@ typedef struct {
/* check if string matches the given pattern. returns <0 for
error, 0 for failure, and 1 for success */
-LOCAL(int)
+LOCAL(Py_ssize_t)
SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
{
SRE_CHAR* end = (SRE_CHAR *)state->end;
- int alloc_pos, ctx_pos = -1;
- int i, ret = 0;
- int jump;
+ Py_ssize_t alloc_pos, ctx_pos = -1;
+ Py_ssize_t i, ret = 0;
+ Py_ssize_t jump;
SRE_MATCH_CONTEXT* ctx;
SRE_MATCH_CONTEXT* nextctx;
@@ -851,7 +853,7 @@ entrance:
state->mark array. If it is increased by more than 1,
the intervening marks must be set to NULL to signal
that these marks have not been encountered. */
- int j = state->lastmark + 1;
+ Py_ssize_t j = state->lastmark + 1;
while (j < i)
state->mark[j++] = NULL;
state->lastmark = i;
@@ -1037,7 +1039,7 @@ entrance:
string. check if the rest of the pattern matches,
and backtrack if not. */
- if (ctx->count < (int) ctx->pattern[1])
+ if (ctx->count < (Py_ssize_t) ctx->pattern[1])
RETURN_FAILURE;
if (ctx->pattern[ctx->pattern[0]] == SRE_OP_SUCCESS) {
@@ -1053,12 +1055,12 @@ entrance:
the rest of the pattern cannot possibly match */
ctx->u.chr = ctx->pattern[ctx->pattern[0]+1];
for (;;) {
- while (ctx->count >= (int) ctx->pattern[1] &&
+ while (ctx->count >= (Py_ssize_t) ctx->pattern[1] &&
(ctx->ptr >= end || *ctx->ptr != ctx->u.chr)) {
ctx->ptr--;
ctx->count--;
}
- if (ctx->count < (int) ctx->pattern[1])
+ if (ctx->count < (Py_ssize_t) ctx->pattern[1])
break;
state->ptr = ctx->ptr;
DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1,
@@ -1076,7 +1078,7 @@ entrance:
} else {
/* general case */
- while (ctx->count >= (int) ctx->pattern[1]) {
+ while (ctx->count >= (Py_ssize_t) ctx->pattern[1]) {
state->ptr = ctx->ptr;
DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2,
ctx->pattern+ctx->pattern[0]);
@@ -1116,7 +1118,7 @@ entrance:
ret = SRE_COUNT(state, ctx->pattern+3, ctx->pattern[1]);
RETURN_ON_ERROR(ret);
DATA_LOOKUP_AT(SRE_MATCH_CONTEXT, ctx, ctx_pos);
- if (ret < (int) ctx->pattern[1])
+ if (ret < (Py_ssize_t) ctx->pattern[1])
/* didn't match minimum number of times */
RETURN_FAILURE;
/* advance past minimum matches of repeat */
@@ -1132,8 +1134,8 @@ entrance:
} else {
/* general case */
LASTMARK_SAVE();
- while ((int)ctx->pattern[2] == 65535
- || ctx->count <= (int)ctx->pattern[2]) {
+ while ((Py_ssize_t)ctx->pattern[2] == 65535
+ || ctx->count <= (Py_ssize_t)ctx->pattern[2]) {
state->ptr = ctx->ptr;
DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one,
ctx->pattern+ctx->pattern[0]);
@@ -1312,7 +1314,7 @@ entrance:
ctx->ptr, ctx->pattern[0]));
i = ctx->pattern[0];
{
- int groupref = i+i;
+ Py_ssize_t groupref = i+i;
if (groupref >= state->lastmark) {
RETURN_FAILURE;
} else {
@@ -1336,7 +1338,7 @@ entrance:
ctx->ptr, ctx->pattern[0]));
i = ctx->pattern[0];
{
- int groupref = i+i;
+ Py_ssize_t groupref = i+i;
if (groupref >= state->lastmark) {
RETURN_FAILURE;
} else {
@@ -1361,7 +1363,7 @@ entrance:
/* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */
i = ctx->pattern[0];
{
- int groupref = i+i;
+ Py_ssize_t groupref = i+i;
if (groupref >= state->lastmark) {
ctx->pattern += ctx->pattern[1];
break;
@@ -1474,14 +1476,14 @@ exit:
return ret; /* should never get here */
}
-LOCAL(int)
+LOCAL(Py_ssize_t)
SRE_SEARCH(SRE_STATE* state, SRE_CODE* pattern)
{
SRE_CHAR* ptr = (SRE_CHAR *)state->start;
SRE_CHAR* end = (SRE_CHAR *)state->end;
- int status = 0;
- int prefix_len = 0;
- int prefix_skip = 0;
+ Py_ssize_t status = 0;
+ Py_ssize_t prefix_len = 0;
+ Py_ssize_t prefix_skip = 0;
SRE_CODE* prefix = NULL;
SRE_CODE* charset = NULL;
SRE_CODE* overlap = NULL;
@@ -1523,7 +1525,7 @@ SRE_SEARCH(SRE_STATE* state, SRE_CODE* pattern)
if (prefix_len > 1) {
/* pattern starts with a known prefix. use the overlap
table to skip forward as fast as we possibly can */
- int i = 0;
+ Py_ssize_t i = 0;
end = (SRE_CHAR *)state->end;
while (ptr < end) {
for (;;) {
@@ -1604,7 +1606,7 @@ SRE_SEARCH(SRE_STATE* state, SRE_CODE* pattern)
}
LOCAL(int)
-SRE_LITERAL_TEMPLATE(SRE_CHAR* ptr, int len)
+SRE_LITERAL_TEMPLATE(SRE_CHAR* ptr, Py_ssize_t len)
{
/* check if given string is a literal template (i.e. no escapes) */
while (len-- > 0)
@@ -1625,7 +1627,7 @@ static PyObject*pattern_scanner(PatternObject*, PyObject*);
static PyObject *
sre_codesize(PyObject* self, PyObject *unused)
{
- return Py_BuildValue("i", sizeof(SRE_CODE));
+ return Py_BuildValue("l", sizeof(SRE_CODE));
}
static PyObject *
@@ -1660,14 +1662,15 @@ state_reset(SRE_STATE* state)
}
static void*
-getstring(PyObject* string, int* p_length, int* p_charsize)
+getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
{
/* given a python object, return a data pointer, a length (in
characters), and a character size. return NULL if the object
is not a string (or not compatible) */
PyBufferProcs *buffer;
- int size, bytes, charsize;
+ Py_ssize_t size, bytes;
+ int charsize;
void* ptr;
#if defined(HAVE_UNICODE)
@@ -1706,7 +1709,7 @@ getstring(PyObject* string, int* p_length, int* p_charsize)
if (PyString_Check(string) || bytes == size)
charsize = 1;
#if defined(HAVE_UNICODE)
- else if (bytes == (int) (size * sizeof(Py_UNICODE)))
+ else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE)))
charsize = sizeof(Py_UNICODE);
#endif
else {
@@ -1726,11 +1729,11 @@ getstring(PyObject* string, int* p_length, int* p_charsize)
LOCAL(PyObject*)
state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
- int start, int end)
+ Py_ssize_t start, Py_ssize_t end)
{
/* prepare state object */
- int length;
+ Py_ssize_t length;
int charsize;
void* ptr;
@@ -1792,9 +1795,9 @@ state_fini(SRE_STATE* state)
(((char*)(member) - (char*)(state)->beginning) / (state)->charsize)
LOCAL(PyObject*)
-state_getslice(SRE_STATE* state, int index, PyObject* string, int empty)
+state_getslice(SRE_STATE* state, Py_ssize_t index, PyObject* string, int empty)
{
- int i, j;
+ Py_ssize_t i, j;
index = (index - 1) * 2;
@@ -1854,10 +1857,10 @@ pattern_match(PatternObject* self, PyObject* args, PyObject* kw)
int status;
PyObject* string;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
static char* kwlist[] = { "pattern", "pos", "endpos", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:match", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O|nn:match", kwlist,
&string, &start, &end))
return NULL;
@@ -1891,10 +1894,10 @@ pattern_search(PatternObject* self, PyObject* args, PyObject* kw)
int status;
PyObject* string;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
static char* kwlist[] = { "pattern", "pos", "endpos", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:search", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O|nn:search", kwlist,
&string, &start, &end))
return NULL;
@@ -2029,13 +2032,13 @@ pattern_findall(PatternObject* self, PyObject* args, PyObject* kw)
SRE_STATE state;
PyObject* list;
int status;
- int i, b, e;
+ Py_ssize_t i, b, e;
PyObject* string;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
static char* kwlist[] = { "source", "pos", "endpos", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii:findall", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O|nn:findall", kwlist,
&string, &start, &end))
return NULL;
@@ -2154,18 +2157,18 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
PyObject* list;
PyObject* item;
int status;
- int n;
- int i;
+ Py_ssize_t n;
+ Py_ssize_t i;
void* last;
PyObject* string;
- int maxsplit = 0;
+ Py_ssize_t maxsplit = 0;
static char* kwlist[] = { "source", "maxsplit", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O|i:split", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O|n:split", kwlist,
&string, &maxsplit))
return NULL;
- string = state_init(&state, self, string, 0, INT_MAX);
+ string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
if (!string)
return NULL;
@@ -2259,7 +2262,7 @@ error:
static PyObject*
pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
- int count, int subn)
+ Py_ssize_t count, Py_ssize_t subn)
{
SRE_STATE state;
PyObject* list;
@@ -2269,8 +2272,9 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
PyObject* match;
void* ptr;
int status;
- int n;
- int i, b, e;
+ Py_ssize_t n;
+ Py_ssize_t i, b, e;
+ int bint;
int filter_is_callable;
if (PyCallable_Check(ptemplate)) {
@@ -2281,7 +2285,8 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
} else {
/* if not callable, check if it's a literal string */
int literal;
- ptr = getstring(ptemplate, &n, &b);
+ ptr = getstring(ptemplate, &n, &bint);
+ b = bint;
if (ptr) {
if (b == 1) {
literal = sre_literal_template((unsigned char *)ptr, n);
@@ -2310,7 +2315,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
}
}
- string = state_init(&state, self, string, 0, INT_MAX);
+ string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
if (!string) {
Py_DECREF(filter);
return NULL;
@@ -2443,9 +2448,9 @@ pattern_sub(PatternObject* self, PyObject* args, PyObject* kw)
{
PyObject* ptemplate;
PyObject* string;
- int count = 0;
+ Py_ssize_t count = 0;
static char* kwlist[] = { "repl", "string", "count", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|i:sub", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:sub", kwlist,
&ptemplate, &string, &count))
return NULL;
@@ -2457,9 +2462,9 @@ pattern_subn(PatternObject* self, PyObject* args, PyObject* kw)
{
PyObject* ptemplate;
PyObject* string;
- int count = 0;
+ Py_ssize_t count = 0;
static char* kwlist[] = { "repl", "string", "count", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|i:subn", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:subn", kwlist,
&ptemplate, &string, &count))
return NULL;
@@ -2642,15 +2647,15 @@ _compile(PyObject* self_, PyObject* args)
/* "compile" pattern descriptor to pattern object */
PatternObject* self;
- int i, n;
+ Py_ssize_t i, n;
PyObject* pattern;
int flags = 0;
PyObject* code;
- int groups = 0;
+ Py_ssize_t groups = 0;
PyObject* groupindex = NULL;
PyObject* indexgroup = NULL;
- if (!PyArg_ParseTuple(args, "OiO!|iOO", &pattern, &flags,
+ if (!PyArg_ParseTuple(args, "OiO!|nOO", &pattern, &flags,
&PyList_Type, &code, &groups,
&groupindex, &indexgroup))
return NULL;
@@ -2711,7 +2716,7 @@ match_dealloc(MatchObject* self)
}
static PyObject*
-match_getslice_by_index(MatchObject* self, int index, PyObject* def)
+match_getslice_by_index(MatchObject* self, Py_ssize_t index, PyObject* def)
{
if (index < 0 || index >= self->groups) {
/* raise IndexError if we were given a bad group number */
@@ -2735,21 +2740,21 @@ match_getslice_by_index(MatchObject* self, int index, PyObject* def)
);
}
-static int
+static Py_ssize_t
match_getindex(MatchObject* self, PyObject* index)
{
- int i;
+ Py_ssize_t i;
if (PyInt_Check(index))
- return (int) PyInt_AS_LONG(index);
+ return PyInt_AsSsize_t(index);
i = -1;
if (self->pattern->groupindex) {
index = PyObject_GetItem(self->pattern->groupindex, index);
if (index) {
- if (PyInt_Check(index))
- i = (int) PyInt_AS_LONG(index);
+ if (PyInt_Check(index) || PyLong_Check(index))
+ i = PyInt_AsSsize_t(index);
Py_DECREF(index);
} else
PyErr_Clear();
@@ -2778,7 +2783,7 @@ static PyObject*
match_group(MatchObject* self, PyObject* args)
{
PyObject* result;
- int i, size;
+ Py_ssize_t i, size;
size = PyTuple_GET_SIZE(args);
@@ -2813,7 +2818,7 @@ static PyObject*
match_groups(MatchObject* self, PyObject* args, PyObject* kw)
{
PyObject* result;
- int index;
+ Py_ssize_t index;
PyObject* def = Py_None;
static char* kwlist[] = { "default", NULL };
@@ -2842,7 +2847,7 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
{
PyObject* result;
PyObject* keys;
- int index;
+ Py_ssize_t index;
PyObject* def = Py_None;
static char* kwlist[] = { "default", NULL };
@@ -2888,7 +2893,7 @@ failed:
static PyObject*
match_start(MatchObject* self, PyObject* args)
{
- int index;
+ Py_ssize_t index;
PyObject* index_ = Py_False; /* zero */
if (!PyArg_UnpackTuple(args, "start", 0, 1, &index_))
@@ -2911,7 +2916,7 @@ match_start(MatchObject* self, PyObject* args)
static PyObject*
match_end(MatchObject* self, PyObject* args)
{
- int index;
+ Py_ssize_t index;
PyObject* index_ = Py_False; /* zero */
if (!PyArg_UnpackTuple(args, "end", 0, 1, &index_))
@@ -2932,7 +2937,7 @@ match_end(MatchObject* self, PyObject* args)
}
LOCAL(PyObject*)
-_pair(int i1, int i2)
+_pair(Py_ssize_t i1, Py_ssize_t i2)
{
PyObject* pair;
PyObject* item;
@@ -2941,12 +2946,12 @@ _pair(int i1, int i2)
if (!pair)
return NULL;
- item = PyInt_FromLong(i1);
+ item = PyInt_FromSsize_t(i1);
if (!item)
goto error;
PyTuple_SET_ITEM(pair, 0, item);
- item = PyInt_FromLong(i2);
+ item = PyInt_FromSsize_t(i2);
if (!item)
goto error;
PyTuple_SET_ITEM(pair, 1, item);
@@ -2961,7 +2966,7 @@ _pair(int i1, int i2)
static PyObject*
match_span(MatchObject* self, PyObject* args)
{
- int index;
+ Py_ssize_t index;
PyObject* index_ = Py_False; /* zero */
if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_))
@@ -2986,7 +2991,7 @@ match_regs(MatchObject* self)
{
PyObject* regs;
PyObject* item;
- int index;
+ Py_ssize_t index;
regs = PyTuple_New(self->groups);
if (!regs)
@@ -3012,7 +3017,7 @@ match_copy(MatchObject* self, PyObject *unused)
{
#ifdef USE_BUILTIN_COPY
MatchObject* copy;
- int slots, offset;
+ Py_ssize_t slots, offset;
slots = 2 * (self->pattern->groups+1);
@@ -3029,7 +3034,7 @@ match_copy(MatchObject* self, PyObject *unused)
Py_XINCREF(self->regs);
memcpy((char*) copy + offset, (char*) self + offset,
- sizeof(MatchObject) + slots * sizeof(int) - offset);
+ sizeof(MatchObject) + slots * sizeof(Py_ssize_t) - offset);
return (PyObject*) copy;
#else
@@ -3144,7 +3149,7 @@ match_getattr(MatchObject* self, char* name)
static PyTypeObject Match_Type = {
PyObject_HEAD_INIT(NULL)
0, "_" SRE_MODULE ".SRE_Match",
- sizeof(MatchObject), sizeof(int),
+ sizeof(MatchObject), sizeof(Py_ssize_t),
(destructor)match_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)match_getattr /*tp_getattr*/
@@ -3156,7 +3161,7 @@ pattern_new_match(PatternObject* pattern, SRE_STATE* state, int status)
/* create match object (from state object) */
MatchObject* match;
- int i, j;
+ Py_ssize_t i, j;
char* base;
int n;
@@ -3329,9 +3334,9 @@ pattern_scanner(PatternObject* pattern, PyObject* args)
ScannerObject* self;
PyObject* string;
- int start = 0;
- int end = INT_MAX;
- if (!PyArg_ParseTuple(args, "O|ii:scanner", &string, &start, &end))
+ Py_ssize_t start = 0;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
+ if (!PyArg_ParseTuple(args, "O|nn:scanner", &string, &start, &end))
return NULL;
/* create scanner object */
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index f49391d..3b91b24 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -26,6 +26,12 @@ enum py_ssl_error {
/* Include symbols from _socket module */
#include "socketmodule.h"
+#if defined(HAVE_POLL_H)
+#include <poll.h>
+#elif defined(HAVE_SYS_POLL_H)
+#include <sys/poll.h>
+#endif
+
/* Include OpenSSL header files */
#include "openssl/rsa.h"
#include "openssl/crypto.h"
@@ -351,7 +357,7 @@ static void PySSL_dealloc(PySSLObject *self)
PyObject_Del(self);
}
-/* If the socket has a timeout, do a select() on the socket.
+/* If the socket has a timeout, do a select()/poll() on the socket.
The argument writing indicates the direction.
Returns one of the possibilities in the timeout_state enum (above).
*/
@@ -373,6 +379,26 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
if (s->sock_fd < 0)
return SOCKET_HAS_BEEN_CLOSED;
+ /* Prefer poll, if available, since you can poll() any fd
+ * which can't be done with select(). */
+#ifdef HAVE_POLL
+ {
+ struct pollfd pollfd;
+ int timeout;
+
+ pollfd.fd = s->sock_fd;
+ pollfd.events = writing ? POLLOUT : POLLIN;
+
+ /* s->sock_timeout is in seconds, timeout in ms */
+ timeout = (int)(s->sock_timeout * 1000 + 0.5);
+ Py_BEGIN_ALLOW_THREADS
+ rc = poll(&pollfd, 1, timeout);
+ Py_END_ALLOW_THREADS
+
+ goto normal_return;
+ }
+#endif
+
/* Guard against socket too large for select*/
#ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
if (s->sock_fd >= FD_SETSIZE)
@@ -393,6 +419,7 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
Py_END_ALLOW_THREADS
+normal_return:
/* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise
(when we are able to write or when there's something to read) */
return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK;
diff --git a/Modules/_struct.c b/Modules/_struct.c
index df243ec..8d0a3bc 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -31,6 +31,17 @@ static PyObject *pylong_ulong_mask = NULL;
static PyObject *pyint_zero = NULL;
#endif
+/* If PY_STRUCT_FLOAT_COERCE is defined, the struct module will allow float
+ arguments for integer formats with a warning for backwards
+ compatibility. */
+
+#define PY_STRUCT_FLOAT_COERCE 1
+
+#ifdef PY_STRUCT_FLOAT_COERCE
+#define FLOAT_COERCE "integer argument expected, got float"
+#endif
+
+
/* The translation function for each format character is table driven */
typedef struct _formatdef {
char format;
@@ -135,6 +146,21 @@ get_long(PyObject *v, long *p)
{
long x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred()) {
+#ifdef PY_STRUCT_FLOAT_COERCE
+ if (PyFloat_Check(v)) {
+ PyObject *o;
+ int res;
+ PyErr_Clear();
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0)
+ return -1;
+ o = PyNumber_Int(v);
+ if (o == NULL)
+ return -1;
+ res = get_long(o, p);
+ Py_DECREF(o);
+ return res;
+ }
+#endif
if (PyErr_ExceptionMatches(PyExc_TypeError))
PyErr_SetString(StructError,
"required argument is not an integer");
@@ -214,15 +240,33 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
/* Helper routine to get a Python integer and raise the appropriate error
if it isn't one */
+#define INT_OVERFLOW "struct integer overflow masking is deprecated"
+
static int
get_wrapped_long(PyObject *v, long *p)
{
if (get_long(v, p) < 0) {
- if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError)) {
+ if (PyLong_Check(v) &&
+ PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyObject *wrapped;
long x;
PyErr_Clear();
- if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0)
+#ifdef PY_STRUCT_FLOAT_COERCE
+ if (PyFloat_Check(v)) {
+ PyObject *o;
+ int res;
+ PyErr_Clear();
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0)
+ return -1;
+ o = PyNumber_Int(v);
+ if (o == NULL)
+ return -1;
+ res = get_wrapped_long(o, p);
+ Py_DECREF(o);
+ return res;
+ }
+#endif
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0)
return -1;
wrapped = PyNumber_And(v, pylong_ulong_mask);
if (wrapped == NULL)
@@ -246,10 +290,25 @@ get_wrapped_ulong(PyObject *v, unsigned long *p)
if (x == -1 && PyErr_Occurred()) {
PyObject *wrapped;
PyErr_Clear();
+#ifdef PY_STRUCT_FLOAT_COERCE
+ if (PyFloat_Check(v)) {
+ PyObject *o;
+ int res;
+ PyErr_Clear();
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, FLOAT_COERCE, 2) < 0)
+ return -1;
+ o = PyNumber_Int(v);
+ if (o == NULL)
+ return -1;
+ res = get_wrapped_ulong(o, p);
+ Py_DECREF(o);
+ return res;
+ }
+#endif
wrapped = PyNumber_And(v, pylong_ulong_mask);
if (wrapped == NULL)
return -1;
- if (PyErr_Warn(PyExc_DeprecationWarning, "struct integer overflow masking is deprecated") < 0) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, INT_OVERFLOW, 2) < 0) {
Py_DECREF(wrapped);
return -1;
}
@@ -344,8 +403,8 @@ _range_error(const formatdef *f, int is_unsigned)
Py_XDECREF(ptraceback);
if (msg == NULL)
return -1;
- rval = PyErr_Warn(PyExc_DeprecationWarning,
- PyString_AS_STRING(msg));
+ rval = PyErr_WarnEx(PyExc_DeprecationWarning,
+ PyString_AS_STRING(msg), 2);
Py_DECREF(msg);
if (rval == 0)
return 0;
@@ -1396,23 +1455,17 @@ s_unpack_internal(PyStructObject *soself, char *startfrom) {
const char *res = startfrom + code->offset;
if (e->format == 's') {
v = PyString_FromStringAndSize(res, code->size);
- if (v == NULL)
- goto fail;
- PyTuple_SET_ITEM(result, i++, v);
} else if (e->format == 'p') {
Py_ssize_t n = *(unsigned char*)res;
if (n >= code->size)
n = code->size - 1;
v = PyString_FromStringAndSize(res + 1, n);
- if (v == NULL)
- goto fail;
- PyTuple_SET_ITEM(result, i++, v);
} else {
v = e->unpack(res, e);
- if (v == NULL)
- goto fail;
- PyTuple_SET_ITEM(result, i++, v);
}
+ if (v == NULL)
+ goto fail;
+ PyTuple_SET_ITEM(result, i++, v);
}
return result;
@@ -1438,7 +1491,8 @@ s_unpack(PyObject *self, PyObject *inputstr)
if (inputstr == NULL || !PyString_Check(inputstr) ||
PyString_GET_SIZE(inputstr) != soself->s_size) {
PyErr_Format(StructError,
- "unpack requires a string argument of length %zd", soself->s_size);
+ "unpack requires a string argument of length %zd",
+ soself->s_size);
return NULL;
}
return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
@@ -1504,17 +1558,18 @@ static int
s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
{
formatcode *code;
+ /* XXX(nnorwitz): why does i need to be a local? can we use
+ the offset parameter or do we need the wider width? */
Py_ssize_t i;
memset(buf, '\0', soself->s_size);
i = offset;
for (code = soself->s_codes; code->fmtdef != NULL; code++) {
Py_ssize_t n;
- PyObject *v;
+ PyObject *v = PyTuple_GET_ITEM(args, i++);
const formatdef *e = code->fmtdef;
char *res = buf + code->offset;
if (e->format == 's') {
- v = PyTuple_GET_ITEM(args, i++);
if (!PyString_Check(v)) {
PyErr_SetString(StructError,
"argument for 's' must be a string");
@@ -1526,7 +1581,6 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
if (n > 0)
memcpy(res, PyString_AS_STRING(v), n);
} else if (e->format == 'p') {
- v = PyTuple_GET_ITEM(args, i++);
if (!PyString_Check(v)) {
PyErr_SetString(StructError,
"argument for 'p' must be a string");
@@ -1541,7 +1595,6 @@ s_pack_internal(PyStructObject *soself, PyObject *args, int offset, char* buf)
n = 255;
*res = Py_SAFE_DOWNCAST(n, Py_ssize_t, unsigned char);
} else {
- v = PyTuple_GET_ITEM(args, i++);
if (e->pack(res, v, e) < 0) {
if (PyLong_Check(v) && PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_SetString(StructError,
@@ -1818,4 +1871,8 @@ init_struct(void)
#ifdef PY_STRUCT_OVERFLOW_MASKING
PyModule_AddIntConstant(m, "_PY_STRUCT_OVERFLOW_MASKING", 1);
#endif
+#ifdef PY_STRUCT_FLOAT_COERCE
+ PyModule_AddIntConstant(m, "_PY_STRUCT_FLOAT_COERCE", 1);
+#endif
+
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 6b9dffd..f5f3ab2 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -294,6 +294,16 @@ test_L_code(PyObject *self)
#endif /* ifdef HAVE_LONG_LONG */
+/* Test tuple argument processing */
+static PyObject *
+getargs_tuple(PyObject *self, PyObject *args)
+{
+ int a, b, c;
+ if (!PyArg_ParseTuple(args, "i(ii)", &a, &b, &c))
+ return NULL;
+ return Py_BuildValue("iii", a, b, c);
+}
+
/* Functions to call PyArg_ParseTuple with integer format codes,
and return the result.
*/
@@ -696,6 +706,13 @@ test_string_from_format(PyObject *self, PyObject *args)
#undef CHECK_1_FORMAT
}
+/* This is here to provide a docstring for test_descr. */
+static PyObject *
+test_with_docstring(PyObject *self)
+{
+ Py_RETURN_NONE;
+}
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
@@ -706,7 +723,10 @@ static PyMethodDef TestMethods[] = {
{"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
{"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS},
{"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS},
+ {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS,
+ PyDoc_STR("This is a pretty normal docstring.")},
+ {"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_b", getargs_b, METH_VARARGS},
{"getargs_B", getargs_B, METH_VARARGS},
{"getargs_H", getargs_H, METH_VARARGS},
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index cec83f5..088fbb9 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -932,12 +932,13 @@ AsObj(PyObject *value)
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
Py_UNICODE *inbuf = PyUnicode_AS_UNICODE(value);
- int size = PyUnicode_GET_SIZE(value);
+ Py_ssize_t size = PyUnicode_GET_SIZE(value);
/* This #ifdef assumes that Tcl uses UCS-2.
See TCL_UTF_MAX test above. */
#if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3
Tcl_UniChar *outbuf;
- int i;
+ Py_ssize_t i;
+ assert(size < size * sizeof(Tcl_UniChar));
outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
if (!outbuf) {
PyErr_NoMemory();
@@ -2103,8 +2104,8 @@ Tkapp_CreateCommand(PyObject *selfptr, PyObject *args)
data = PyMem_NEW(PythonCmd_ClientData, 1);
if (!data)
return PyErr_NoMemory();
- Py_XINCREF(self);
- Py_XINCREF(func);
+ Py_INCREF(self);
+ Py_INCREF(func);
data->self = selfptr;
data->func = func;
diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c
new file mode 100644
index 0000000..5a6f2b9
--- /dev/null
+++ b/Modules/_typesmodule.c
@@ -0,0 +1,94 @@
+/* This extension module exposes some types that are only available at the
+ * C level. It should not be used directly, but instead through the Python
+ * level types modules, which imports this.
+ */
+
+#include "Python.h"
+#include "structmember.h"
+
+typedef struct
+{
+ PyObject_HEAD
+ int member;
+} Helper;
+
+static PyMemberDef helper_members[] = {
+ { "member", T_INT, offsetof(Helper, member), READONLY,
+ PyDoc_STR("A member descriptor")
+ },
+ { NULL }
+};
+
+static PyObject *
+helper_getter(Helper *self, void *unused)
+{
+ Py_RETURN_NONE;
+}
+
+static PyGetSetDef helper_getset[] = {
+ { "getter", (getter)helper_getter, NULL,
+ PyDoc_STR("A getset descriptor"),
+ },
+ { NULL }
+};
+
+static PyTypeObject HelperType = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "_types.Helper", /* tp_name */
+ sizeof(Helper), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ helper_members, /* tp_members */
+ helper_getset, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+};
+
+PyMODINIT_FUNC
+init_types(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("_types", NULL, "A types module helper");
+ if (!m)
+ return;
+
+ if (PyType_Ready(&HelperType) < 0)
+ return;
+
+ Py_INCREF(&HelperType);
+ PyModule_AddObject(m, "Helper", (PyObject *)&HelperType);
+}
+
+
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index 2dfdc14..1712f12 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -17,7 +17,7 @@ weakref_getweakrefcount(PyObject *self, PyObject *object)
if (PyType_SUPPORTS_WEAKREFS(object->ob_type)) {
PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
- result = PyInt_FromLong(_PyWeakref_GetWeakrefCount(*list));
+ result = PyInt_FromSsize_t(_PyWeakref_GetWeakrefCount(*list));
}
else
result = PyInt_FromLong(0);
@@ -37,12 +37,12 @@ weakref_getweakrefs(PyObject *self, PyObject *object)
if (PyType_SUPPORTS_WEAKREFS(object->ob_type)) {
PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
- long count = _PyWeakref_GetWeakrefCount(*list);
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount(*list);
result = PyList_New(count);
if (result != NULL) {
PyWeakReference *current = *list;
- long i;
+ Py_ssize_t i;
for (i = 0; i < count; ++i) {
PyList_SET_ITEM(result, i, (PyObject *) current);
Py_INCREF(current);
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 100b341..b739cc8 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -10,9 +10,9 @@
#ifdef STDC_HEADERS
#include <stddef.h>
#else /* !STDC_HEADERS */
-#ifndef DONT_HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> /* For size_t */
-#endif /* DONT_HAVE_SYS_TYPES_H */
+#endif /* HAVE_SYS_TYPES_H */
#endif /* !STDC_HEADERS */
struct arrayobject; /* Forward */
@@ -1785,6 +1785,7 @@ static PyBufferProcs array_as_buffer = {
(readbufferproc)array_buffer_getreadbuf,
(writebufferproc)array_buffer_getwritebuf,
(segcountproc)array_buffer_getsegcount,
+ NULL,
};
static PyObject *
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 71a9624..3b2c8b2 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -909,7 +909,7 @@ binascii_hexlify(PyObject *self, PyObject *args)
char* retbuf;
Py_ssize_t i, j;
- if (!PyArg_ParseTuple(args, "t#:b2a_hex", &argbuf, &arglen))
+ if (!PyArg_ParseTuple(args, "s#:b2a_hex", &argbuf, &arglen))
return NULL;
retval = PyString_FromStringAndSize(NULL, arglen*2);
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 9576895..b0075a0 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -1303,7 +1303,11 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
break;
case 'U':
+#ifdef __VMS
+ self->f_univ_newline = 0;
+#else
self->f_univ_newline = 1;
+#endif
break;
default:
@@ -1336,8 +1340,10 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
if (mode_char == 'r')
@@ -1359,10 +1365,12 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
return 0;
error:
- Py_DECREF(self->file);
+ Py_CLEAR(self->file);
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
return -1;
}
@@ -1562,7 +1570,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
}
}
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1628,7 +1636,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1670,8 +1678,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
memset(&self->bzs, 0, sizeof(bz_stream));
@@ -1686,8 +1696,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
return 0;
error:
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
return -1;
}
@@ -1852,7 +1864,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1882,8 +1894,10 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
self->unused_data = PyString_FromString("");
@@ -1903,10 +1917,12 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
error:
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
- Py_XDECREF(self->unused_data);
+ Py_CLEAR(self->unused_data);
return -1;
}
@@ -2061,7 +2077,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzCompressEnd(bzs);
return ret;
@@ -2140,7 +2156,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzDecompressEnd(bzs);
return ret;
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 0d29362..24c98cc 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -196,7 +196,7 @@ Pdata_clear(Pdata *self, int clearto)
for (i = self->length, p = self->data + clearto;
--i >= clearto;
p++) {
- Py_DECREF(*p);
+ Py_CLEAR(*p);
}
self->length = clearto;
@@ -208,6 +208,7 @@ Pdata_grow(Pdata *self)
{
int bigger;
size_t nbytes;
+ PyObject **tmp;
bigger = self->size << 1;
if (bigger <= 0) /* was 0, or new value overflows */
@@ -217,14 +218,14 @@ Pdata_grow(Pdata *self)
nbytes = (size_t)bigger * sizeof(PyObject *);
if (nbytes / sizeof(PyObject *) != (size_t)bigger)
goto nomemory;
- self->data = realloc(self->data, nbytes);
- if (self->data == NULL)
+ tmp = realloc(self->data, nbytes);
+ if (tmp == NULL)
goto nomemory;
+ self->data = tmp;
self->size = bigger;
return 0;
nomemory:
- self->size = 0;
PyErr_NoMemory();
return -1;
}
@@ -2636,7 +2637,7 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
if (ik >= lm || ik == 0) {
PyErr_SetString(PicklingError,
"Invalid get data");
- return NULL;
+ goto err;
}
if (have_get[ik]) /* with matching get */
rsize += ik < 256 ? 2 : 5;
@@ -2648,7 +2649,7 @@ Pickle_getvalue(Picklerobject *self, PyObject *args)
) {
PyErr_SetString(PicklingError,
"Unexpected data in internal list");
- return NULL;
+ goto err;
}
else { /* put */
@@ -3400,11 +3401,11 @@ load_string(Unpicklerobject *self)
/********************************************/
str = PyString_DecodeEscape(p, len, NULL, 0, NULL);
+ free(s);
if (str) {
PDATA_PUSH(self->stack, str, -1);
res = 0;
}
- free(s);
return res;
insecure:
@@ -3628,10 +3629,14 @@ Instance_New(PyObject *cls, PyObject *args)
err:
{
- PyObject *tp, *v, *tb;
+ PyObject *tp, *v, *tb, *tmp_value;
PyErr_Fetch(&tp, &v, &tb);
- if ((r=PyTuple_Pack(3,v,cls,args))) {
+ tmp_value = v;
+ /* NULL occurs when there was a KeyboardInterrupt */
+ if (tmp_value == NULL)
+ tmp_value = Py_None;
+ if ((r = PyTuple_Pack(3, tmp_value, cls, args))) {
Py_XDECREF(v);
v=r;
}
@@ -4159,6 +4164,7 @@ do_append(Unpicklerobject *self, int x)
int list_len;
slice=Pdata_popList(self->stack, x);
+ if (! slice) return -1;
list_len = PyList_GET_SIZE(list);
i=PyList_SetSlice(list, list_len, list_len, slice);
Py_DECREF(slice);
@@ -5163,6 +5169,9 @@ newUnpicklerobject(PyObject *f)
if (!( self->memo = PyDict_New()))
goto err;
+ if (!self->stack)
+ goto err;
+
Py_INCREF(f);
self->file = f;
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c
index 0c7dca6..d761dce 100644
--- a/Modules/collectionsmodule.c
+++ b/Modules/collectionsmodule.c
@@ -10,7 +10,7 @@
/* The block length may be set to any number over 1. Larger numbers
* reduce the number of calls to the memory allocator but take more
* memory. Ideally, BLOCKLEN should be set with an eye to the
- * length of a cache line.
+ * length of a cache line.
*/
#define BLOCKLEN 62
@@ -22,9 +22,9 @@
* element is at d.leftblock[leftindex] and its last element is at
* d.rightblock[rightindex]; note that, unlike as for Python slice
* indices, these indices are inclusive on both ends. By being inclusive
- * on both ends, algorithms for left and right operations become
+ * on both ends, algorithms for left and right operations become
* symmetrical which simplifies the design.
- *
+ *
* The list of blocks is never empty, so d.leftblock and d.rightblock
* are never equal to NULL.
*
@@ -37,11 +37,11 @@
* d.leftindex == CENTER+1; and d.rightindex == CENTER.
* Checking for d.len == 0 is the intended way to see whether d is empty.
*
- * Whenever d.leftblock == d.rightblock,
+ * Whenever d.leftblock == d.rightblock,
* d.leftindex + d.len - 1 == d.rightindex.
- *
+ *
* However, when d.leftblock != d.rightblock, d.leftindex and d.rightindex
- * become indices into distinct blocks and either may be larger than the
+ * become indices into distinct blocks and either may be larger than the
* other.
*/
@@ -381,7 +381,7 @@ deque_remove(dequeobject *deque, PyObject *value)
int cmp = PyObject_RichCompareBool(item, value, Py_EQ);
if (deque->len != n) {
- PyErr_SetString(PyExc_IndexError,
+ PyErr_SetString(PyExc_IndexError,
"deque mutated during remove().");
return NULL;
}
@@ -920,7 +920,7 @@ dequeiter_next(dequeiterobject *it)
"deque mutated during iteration");
return NULL;
}
- assert (!(it->b == it->deque->rightblock &&
+ assert (!(it->b == it->deque->rightblock &&
it->index > it->deque->rightindex));
item = it->b->data[it->index];
@@ -1016,7 +1016,7 @@ dequereviter_next(dequeiterobject *it)
"deque mutated during iteration");
return NULL;
}
- assert (!(it->b == it->deque->leftblock &&
+ assert (!(it->b == it->deque->leftblock &&
it->index < it->deque->leftindex));
item = it->b->data[it->index];
@@ -1117,7 +1117,7 @@ defdict_copy(defdictobject *dd)
static PyObject *
defdict_reduce(defdictobject *dd)
{
- /* __reduce__ must returns a 5-tuple as follows:
+ /* __reduce__ must return a 5-tuple as follows:
- factory function
- tuple of args for the factory function
@@ -1155,6 +1155,7 @@ defdict_reduce(defdictobject *dd)
}
result = PyTuple_Pack(5, dd->dict.ob_type, args,
Py_None, Py_None, items);
+ Py_DECREF(items);
Py_DECREF(args);
return result;
}
diff --git a/Modules/config.c.in b/Modules/config.c.in
index f811991..8c25eea 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -28,6 +28,7 @@ extern void PyMarshal_Init(void);
extern void initimp(void);
extern void initgc(void);
extern void init_ast(void);
+extern void init_types(void);
struct _inittab _PyImport_Inittab[] = {
@@ -42,6 +43,9 @@ struct _inittab _PyImport_Inittab[] = {
/* This lives in Python/Python-ast.c */
{"_ast", init_ast},
+ /* This lives in Python/_types.c */
+ {"_types", init_types},
+
/* These entries are here for sys.builtin_module_names */
{"__main__", NULL},
{"__builtin__", NULL},
diff --git a/Modules/cryptmodule.c b/Modules/cryptmodule.c
index 050a356..6377f84 100644
--- a/Modules/cryptmodule.c
+++ b/Modules/cryptmodule.c
@@ -5,6 +5,9 @@
#include <sys/types.h>
+#ifdef __VMS
+#include <openssl/des.h>
+#endif
/* Module crypt */
@@ -12,7 +15,9 @@
static PyObject *crypt_crypt(PyObject *self, PyObject *args)
{
char *word, *salt;
+#ifndef __VMS
extern char * crypt(const char *, const char *);
+#endif
if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
return NULL;
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index 0955681..5622ed9 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -5,6 +5,10 @@
#include <dlfcn.h>
+#ifdef __VMS
+#include <unistd.h>
+#endif
+
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif
@@ -77,8 +81,8 @@ dl_call(dlobject *xp, PyObject *args)
long, long, long, long, long);
long alist[10];
long res;
- int i;
- int n = PyTuple_Size(args);
+ Py_ssize_t i;
+ Py_ssize_t n = PyTuple_Size(args);
if (n < 1) {
PyErr_SetString(PyExc_TypeError, "at least a name is needed");
return NULL;
@@ -186,6 +190,24 @@ dl_open(PyObject *self, PyObject *args)
PyErr_SetString(Dlerror, dlerror());
return NULL;
}
+#ifdef __VMS
+ /* Under OpenVMS dlopen doesn't do any check, just save the name
+ * for later use, so we have to check if the file is readable,
+ * the name can be a logical or a file from SYS$SHARE.
+ */
+ if (access(name, R_OK)) {
+ char fname[strlen(name) + 20];
+ strcpy(fname, "SYS$SHARE:");
+ strcat(fname, name);
+ strcat(fname, ".EXE");
+ if (access(fname, R_OK)) {
+ dlclose(handle);
+ PyErr_SetString(Dlerror,
+ "File not found or protection violation");
+ return NULL;
+ }
+ }
+#endif
return newdlobject(handle);
}
diff --git a/Modules/expat/Makefile.in b/Modules/expat/Makefile.in
deleted file mode 100644
index 9790739..0000000
--- a/Modules/expat/Makefile.in
+++ /dev/null
@@ -1,158 +0,0 @@
-################################################################
-# Process this file with top-level configure script to produce Makefile
-#
-# Copyright 2000 Clark Cooper
-#
-# This file is part of EXPAT.
-#
-# EXPAT is free software; you can redistribute it and/or modify it
-# under the terms of the License (based on the MIT/X license) contained
-# in the file COPYING that comes with this distribution.
-#
-# EXPAT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-# SOFTWARE OR THE USE OR OTHER DEALINGS IN EXPAT.
-#
-
-
-SHELL = @SHELL@
-
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-datadir = @datadir@
-sysconfdir = @sysconfdir@
-sharedstatedir = @sharedstatedir@
-localstatedir = @localstatedir@
-libdir = @libdir@
-infodir = @infodir@
-mandir = @mandir@
-includedir = @includedir@
-oldincludedir = /usr/include
-
-subdir = lib
-
-top_builddir = ..
-
-INSTALL = @INSTALL@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_DATA = @INSTALL_DATA@
-
-host_alias = @host_alias@
-host_triplet = @host@
-AS = @AS@
-CC = @CC@
-DLLTOOL = @DLLTOOL@
-LIBTOOL = @LIBTOOL@
-LN_S = @LN_S@
-OBJDUMP = @OBJDUMP@
-PACKAGE = @PACKAGE@
-RANLIB = @RANLIB@
-VERSION = @VERSION@
-
-LIBRARY = libexpat.la
-SOURCES = xmlparse.c xmltok.c xmlrole.c
-OBJECTS = $(SOURCES:.c=.o)
-LTOBJECTS = $(SOURCES:.c=.lo)
-
-TEMPLATES = xmltok_impl.c xmltok_ns.c
-APIHEADER = expat.h
-HEADERS = ascii.h iasciitab.h utf8tab.h xmltok.h asciitab.h latin1tab.h \
- nametab.h xmldef.h xmlrole.h xmltok_impl.h
-
-mkinstalldirs = $(SHELL) $(top_srcdir)/conftools/mkinstalldirs
-CONFIG_HEADER = ../config.h
-CONFIG_CLEAN_FILES =
-
-INCLUDES = -I$(srcdir) -I. -I..
-DEFS = @DEFS@ -DPACKAGE='"$(PACKAGE)"' -DVERSION='"$(PACKAGE)_$(VERSION)"'
-
-CPPFLAGS = @CPPFLAGS@
-LDFLAGS = @LDFLAGS@
-LIBS = @LIBS@
-CFLAGS = @CFLAGS@
-
-LIBREVISION = @LIBREVISION@
-LIBCURRENT = @LIBCURRENT@
-LIBAGE = @LIBAGE@
-
-COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(LIBTOOL) --mode=link $(CCLD) -version-info $(LIBCURRENT):$(LIBREVISION):$(LIBAGE) $(CFLAGS) $(LDFLAGS) -o $@
-DIST_COMMON = Makefile.in
-
-
-DISTFILES = $(DIST_COMMON) $(SOURCES) $(TEMPLATES) $(APIHEADER) $(HEADERS)
-
-TAR = gtar
-GZIP_ENV = --best
-
-all: $(LIBRARY)
-
-.SUFFIXES: .c .lo .o
-.PHONY: all clean distclean maintainer-clean
-
-.c.o:
- $(COMPILE) -c $<
-
-.c.lo:
- $(LTCOMPILE) -c $<
-
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- cd $(top_builddir) \
- && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-$(top_builddir)/config.status: $(top_builddir)/configure
- cd $(top_builddir) && $(MAKE) config.status
-
-$(top_builddir)/config.h: $(top_builddir)/config.h.in
- cd $(top_builddir) && $(MAKE) config.h
-
-clean:
- rm -f $(LIBRARY) *.o *.lo *~
- rm -rf .libs _libs
-
-distclean: clean
- rm -f Makefile
-
-maintainer-clean: distclean
-
-check: $(SUBDIRS)
- @echo
- @echo This package does not yet have a regression test.
- @echo
-
-install: $(LIBRARY) $(APIHEADER)
- $(mkinstalldirs) $(libdir) $(includedir)
- $(LIBTOOL) --mode=install $(INSTALL) $(LIBRARY) $(libdir)/$(LIBRARY)
- $(INSTALL_DATA) $(APIHEADER) $(includedir)
-
-uninstall:
- $(LIBTOOL) --mode=uninstall rm -f $(libdir)/$(LIBRARY);
- rm -f $(libdir)/$(APIHEADER)
-
-$(LIBRARY): $(LTOBJECTS)
- $(LINK) -rpath $(libdir) $(LDFLAGS) $(LTOBJECTS)
-
-xmlparse.o \
-xmlparse.lo: xmlparse.c expat.h xmlrole.h xmltok.h $(top_builddir)/config.h
-
-xmlrole.o \
-xmlrole.lo: xmlrole.c ascii.h xmlrole.h $(top_builddir)/config.h
-
-xmltok.o \
-xmltok.lo: xmltok.c xmltok_impl.c xmltok_ns.c \
- ascii.h asciitab.h iasciitab.h latin1tab.h nametab.h utf8tab.h \
- xmltok.h xmltok_impl.h $(top_builddir)/config.h
diff --git a/Modules/expat/amigaconfig.h b/Modules/expat/amigaconfig.h
new file mode 100644
index 0000000..6781a71
--- /dev/null
+++ b/Modules/expat/amigaconfig.h
@@ -0,0 +1,96 @@
+#ifndef AMIGACONFIG_H
+#define AMIGACONFIG_H
+
+/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */
+#define BYTEORDER 4321
+
+/* Define to 1 if you have the `bcopy' function. */
+#define HAVE_BCOPY 1
+
+/* Define to 1 if you have the <check.h> header file. */
+#undef HAVE_CHECK_H
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `getpagesize' function. */
+#undef HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `memmove' function. */
+#define HAVE_MEMMOVE 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have a working `mmap' system call. */
+#undef HAVE_MMAP
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "expat-bugs@mail.libexpat.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "expat"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "expat 1.95.8"
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.95.8"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* whether byteorder is bigendian */
+#define WORDS_BIGENDIAN
+
+/* Define to specify how much context to retain around the current parse
+ point. */
+#define XML_CONTEXT_BYTES 1024
+
+/* Define to make parameter entity parsing functionality available. */
+#define XML_DTD
+
+/* Define to make XML Namespaces functionality available. */
+#define XML_NS
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to `long' if <sys/types.h> does not define. */
+#undef off_t
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+#undef size_t
+
+
+#endif /* AMIGACONFIG_H */
diff --git a/Modules/expat/expat.h b/Modules/expat/expat.h
index ecba92e..cf113ee 100644
--- a/Modules/expat/expat.h
+++ b/Modules/expat/expat.h
@@ -2,8 +2,8 @@
See the file COPYING for copying permission.
*/
-#ifndef XmlParse_INCLUDED
-#define XmlParse_INCLUDED 1
+#ifndef Expat_INCLUDED
+#define Expat_INCLUDED 1
#ifdef __VMS
/* 0 1 2 3 0 1 2 3
@@ -17,6 +17,10 @@
#include <stdlib.h>
#include "expat_external.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;
@@ -87,7 +91,11 @@ enum XML_Error {
XML_ERROR_NOT_SUSPENDED,
XML_ERROR_ABORTED,
XML_ERROR_FINISHED,
- XML_ERROR_SUSPEND_PE
+ XML_ERROR_SUSPEND_PE,
+ /* Added in 2.0. */
+ XML_ERROR_RESERVED_PREFIX_XML,
+ XML_ERROR_RESERVED_PREFIX_XMLNS,
+ XML_ERROR_RESERVED_NAMESPACE_URI
};
enum XML_Content_Type {
@@ -205,8 +213,8 @@ XML_ParserCreate(const XML_Char *encoding);
URI, the namespace separator character, and the local part of the
name. If the namespace separator is '\0' then the namespace URI
and the local part will be concatenated without any separator.
- When a namespace is not declared, the name and prefix will be
- passed through without expansion.
+ It is a programming error to use the separator '\0' with namespace
+ triplets (see XML_SetReturnNSTriplet).
*/
XMLPARSEAPI(XML_Parser)
XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
@@ -897,9 +905,9 @@ XML_GetErrorCode(XML_Parser parser);
was detected; otherwise the location is the location of the last
parse event, as described above.
*/
-XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser);
-XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser);
-XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser);
+XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
+XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
+XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
/* Return the number of bytes in the current event.
Returns 0 if the event is in an internal entity.
@@ -974,7 +982,8 @@ enum XML_FeatureEnum {
XML_FEATURE_CONTEXT_BYTES,
XML_FEATURE_MIN_SIZE,
XML_FEATURE_SIZEOF_XML_CHAR,
- XML_FEATURE_SIZEOF_XML_LCHAR
+ XML_FEATURE_SIZEOF_XML_LCHAR,
+ XML_FEATURE_NS
/* Additional features must be added to the end of this enum. */
};
@@ -993,12 +1002,12 @@ XML_GetFeatureList(void);
releases. Micro is bumped with each release, and set to 0 with each
change to major or minor version.
*/
-#define XML_MAJOR_VERSION 1
-#define XML_MINOR_VERSION 95
-#define XML_MICRO_VERSION 8
+#define XML_MAJOR_VERSION 2
+#define XML_MINOR_VERSION 0
+#define XML_MICRO_VERSION 0
#ifdef __cplusplus
}
#endif
-#endif /* not XmlParse_INCLUDED */
+#endif /* not Expat_INCLUDED */
diff --git a/Modules/expat/expat_external.h b/Modules/expat/expat_external.h
index 4145cac..f054014 100644
--- a/Modules/expat/expat_external.h
+++ b/Modules/expat/expat_external.h
@@ -2,8 +2,15 @@
See the file COPYING for copying permission.
*/
+#ifndef Expat_External_INCLUDED
+#define Expat_External_INCLUDED 1
+
/* External API definitions */
+/* Namespace external symbols to allow multiple libexpat version to
+ co-exist. */
+#include "pyexpatns.h"
+
#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__)
#define XML_USE_MSC_EXTENSIONS 1
#endif
@@ -62,6 +69,7 @@
#endif
#endif /* not defined XML_STATIC */
+
/* If we didn't define it above, define it away: */
#ifndef XMLIMPORT
#define XMLIMPORT
@@ -90,3 +98,22 @@ typedef char XML_LChar;
typedef char XML_Char;
typedef char XML_LChar;
#endif /* XML_UNICODE */
+
+#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */
+#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
+typedef __int64 XML_Index;
+typedef unsigned __int64 XML_Size;
+#else
+typedef long long XML_Index;
+typedef unsigned long long XML_Size;
+#endif
+#else
+typedef long XML_Index;
+typedef unsigned long XML_Size;
+#endif /* XML_LARGE_SIZE */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* not Expat_External_INCLUDED */
diff --git a/Modules/expat/pyexpatns.h b/Modules/expat/pyexpatns.h
new file mode 100644
index 0000000..7fbd341
--- /dev/null
+++ b/Modules/expat/pyexpatns.h
@@ -0,0 +1,124 @@
+/* Copyright (c) 2005-2006 ActiveState Software Inc.
+ *
+ * Namespace all expat exported symbols to avoid dynamic loading symbol
+ * collisions when embedding Python.
+ *
+ * The Problem:
+ * - you embed Python in some app
+ * - the app dynamically loads libexpat of version X
+ * - the embedded Python imports pyexpat (which was built against
+ * libexpat version X+n)
+ * --> pyexpat gets the expat symbols from the already loaded and *older*
+ * libexpat: crash (Specifically the crash we observed was in
+ * getting an old XML_ErrorString (from xmlparse.c) and then calling
+ * it with newer values in the XML_Error enum:
+ *
+ * // pyexpat.c, line 1970
+ * ...
+ * // Added in Expat 1.95.7.
+ * MYCONST(XML_ERROR_UNBOUND_PREFIX);
+ * ...
+ *
+ *
+ * The Solution:
+ * Prefix all a exported symbols with "PyExpat_". This is similar to
+ * what Mozilla does for some common libs:
+ * http://lxr.mozilla.org/seamonkey/source/modules/libimg/png/mozpngconf.h#115
+ *
+ * The list of relevant exported symbols can be had with this command:
+ *
+ nm pyexpat.so \
+ | grep -v " [a-zBUA] " \
+ | grep -v "_fini\|_init\|initpyexpat"
+ *
+ * If any of those symbols are NOT prefixed with "PyExpat_" then
+ * a #define should be added for it here.
+ */
+
+#ifndef PYEXPATNS_H
+#define PYEXPATNS_H
+
+#define XML_DefaultCurrent PyExpat_XML_DefaultCurrent
+#define XML_ErrorString PyExpat_XML_ErrorString
+#define XML_ExpatVersion PyExpat_XML_ExpatVersion
+#define XML_ExpatVersionInfo PyExpat_XML_ExpatVersionInfo
+#define XML_ExternalEntityParserCreate PyExpat_XML_ExternalEntityParserCreate
+#define XML_FreeContentModel PyExpat_XML_FreeContentModel
+#define XML_GetBase PyExpat_XML_GetBase
+#define XML_GetBuffer PyExpat_XML_GetBuffer
+#define XML_GetCurrentByteCount PyExpat_XML_GetCurrentByteCount
+#define XML_GetCurrentByteIndex PyExpat_XML_GetCurrentByteIndex
+#define XML_GetCurrentColumnNumber PyExpat_XML_GetCurrentColumnNumber
+#define XML_GetCurrentLineNumber PyExpat_XML_GetCurrentLineNumber
+#define XML_GetErrorCode PyExpat_XML_GetErrorCode
+#define XML_GetFeatureList PyExpat_XML_GetFeatureList
+#define XML_GetIdAttributeIndex PyExpat_XML_GetIdAttributeIndex
+#define XML_GetInputContext PyExpat_XML_GetInputContext
+#define XML_GetParsingStatus PyExpat_XML_GetParsingStatus
+#define XML_GetSpecifiedAttributeCount PyExpat_XML_GetSpecifiedAttributeCount
+#define XmlGetUtf16InternalEncoding PyExpat_XmlGetUtf16InternalEncoding
+#define XmlGetUtf16InternalEncodingNS PyExpat_XmlGetUtf16InternalEncodingNS
+#define XmlGetUtf8InternalEncoding PyExpat_XmlGetUtf8InternalEncoding
+#define XmlGetUtf8InternalEncodingNS PyExpat_XmlGetUtf8InternalEncodingNS
+#define XmlInitEncoding PyExpat_XmlInitEncoding
+#define XmlInitEncodingNS PyExpat_XmlInitEncodingNS
+#define XmlInitUnknownEncoding PyExpat_XmlInitUnknownEncoding
+#define XmlInitUnknownEncodingNS PyExpat_XmlInitUnknownEncodingNS
+#define XML_MemFree PyExpat_XML_MemFree
+#define XML_MemMalloc PyExpat_XML_MemMalloc
+#define XML_MemRealloc PyExpat_XML_MemRealloc
+#define XML_Parse PyExpat_XML_Parse
+#define XML_ParseBuffer PyExpat_XML_ParseBuffer
+#define XML_ParserCreate PyExpat_XML_ParserCreate
+#define XML_ParserCreate_MM PyExpat_XML_ParserCreate_MM
+#define XML_ParserCreateNS PyExpat_XML_ParserCreateNS
+#define XML_ParserFree PyExpat_XML_ParserFree
+#define XML_ParserReset PyExpat_XML_ParserReset
+#define XmlParseXmlDecl PyExpat_XmlParseXmlDecl
+#define XmlParseXmlDeclNS PyExpat_XmlParseXmlDeclNS
+#define XmlPrologStateInit PyExpat_XmlPrologStateInit
+#define XmlPrologStateInitExternalEntity PyExpat_XmlPrologStateInitExternalEntity
+#define XML_ResumeParser PyExpat_XML_ResumeParser
+#define XML_SetAttlistDeclHandler PyExpat_XML_SetAttlistDeclHandler
+#define XML_SetBase PyExpat_XML_SetBase
+#define XML_SetCdataSectionHandler PyExpat_XML_SetCdataSectionHandler
+#define XML_SetCharacterDataHandler PyExpat_XML_SetCharacterDataHandler
+#define XML_SetCommentHandler PyExpat_XML_SetCommentHandler
+#define XML_SetDefaultHandler PyExpat_XML_SetDefaultHandler
+#define XML_SetDefaultHandlerExpand PyExpat_XML_SetDefaultHandlerExpand
+#define XML_SetDoctypeDeclHandler PyExpat_XML_SetDoctypeDeclHandler
+#define XML_SetElementDeclHandler PyExpat_XML_SetElementDeclHandler
+#define XML_SetElementHandler PyExpat_XML_SetElementHandler
+#define XML_SetEncoding PyExpat_XML_SetEncoding
+#define XML_SetEndCdataSectionHandler PyExpat_XML_SetEndCdataSectionHandler
+#define XML_SetEndDoctypeDeclHandler PyExpat_XML_SetEndDoctypeDeclHandler
+#define XML_SetEndElementHandler PyExpat_XML_SetEndElementHandler
+#define XML_SetEndNamespaceDeclHandler PyExpat_XML_SetEndNamespaceDeclHandler
+#define XML_SetEntityDeclHandler PyExpat_XML_SetEntityDeclHandler
+#define XML_SetExternalEntityRefHandler PyExpat_XML_SetExternalEntityRefHandler
+#define XML_SetExternalEntityRefHandlerArg PyExpat_XML_SetExternalEntityRefHandlerArg
+#define XML_SetNamespaceDeclHandler PyExpat_XML_SetNamespaceDeclHandler
+#define XML_SetNotationDeclHandler PyExpat_XML_SetNotationDeclHandler
+#define XML_SetNotStandaloneHandler PyExpat_XML_SetNotStandaloneHandler
+#define XML_SetParamEntityParsing PyExpat_XML_SetParamEntityParsing
+#define XML_SetProcessingInstructionHandler PyExpat_XML_SetProcessingInstructionHandler
+#define XML_SetReturnNSTriplet PyExpat_XML_SetReturnNSTriplet
+#define XML_SetSkippedEntityHandler PyExpat_XML_SetSkippedEntityHandler
+#define XML_SetStartCdataSectionHandler PyExpat_XML_SetStartCdataSectionHandler
+#define XML_SetStartDoctypeDeclHandler PyExpat_XML_SetStartDoctypeDeclHandler
+#define XML_SetStartElementHandler PyExpat_XML_SetStartElementHandler
+#define XML_SetStartNamespaceDeclHandler PyExpat_XML_SetStartNamespaceDeclHandler
+#define XML_SetUnknownEncodingHandler PyExpat_XML_SetUnknownEncodingHandler
+#define XML_SetUnparsedEntityDeclHandler PyExpat_XML_SetUnparsedEntityDeclHandler
+#define XML_SetUserData PyExpat_XML_SetUserData
+#define XML_SetXmlDeclHandler PyExpat_XML_SetXmlDeclHandler
+#define XmlSizeOfUnknownEncoding PyExpat_XmlSizeOfUnknownEncoding
+#define XML_StopParser PyExpat_XML_StopParser
+#define XML_UseForeignDTD PyExpat_XML_UseForeignDTD
+#define XML_UseParserAsHandlerArg PyExpat_XML_UseParserAsHandlerArg
+#define XmlUtf16Encode PyExpat_XmlUtf16Encode
+#define XmlUtf8Encode PyExpat_XmlUtf8Encode
+
+
+#endif /* !PYEXPATNS_H */
+
diff --git a/Modules/expat/xmlparse.c b/Modules/expat/xmlparse.c
index 42d95b7..882470d 100644
--- a/Modules/expat/xmlparse.c
+++ b/Modules/expat/xmlparse.c
@@ -8,6 +8,8 @@
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
#include "macconfig.h"
+#elif defined(__amigaos4__)
+#include "amigaconfig.h"
#elif defined(HAVE_EXPAT_CONFIG_H)
#include <expat_config.h>
#endif /* ndef COMPILED_FROM_DSP */
@@ -456,7 +458,7 @@ struct XML_ParserStruct {
char *m_bufferEnd;
/* allocated end of buffer */
const char *m_bufferLim;
- long m_parseEndByteIndex;
+ XML_Index m_parseEndByteIndex;
const char *m_parseEndPtr;
XML_Char *m_dataBuf;
XML_Char *m_dataBufEnd;
@@ -640,8 +642,8 @@ struct XML_ParserStruct {
#define groupSize (parser->m_groupSize)
#define namespaceSeparator (parser->m_namespaceSeparator)
#define parentParser (parser->m_parentParser)
-#define parsing (parser->m_parsingStatus.parsing)
-#define finalBuffer (parser->m_parsingStatus.finalBuffer)
+#define ps_parsing (parser->m_parsingStatus.parsing)
+#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer)
#ifdef XML_DTD
#define isParamEntity (parser->m_isParamEntity)
#define useForeignDTD (parser->m_useForeignDTD)
@@ -852,7 +854,7 @@ parserInit(XML_Parser parser, const XML_Char *encodingName)
unknownEncodingRelease = NULL;
unknownEncodingData = NULL;
parentParser = NULL;
- parsing = XML_INITIALIZED;
+ ps_parsing = XML_INITIALIZED;
#ifdef XML_DTD
isParamEntity = XML_FALSE;
useForeignDTD = XML_FALSE;
@@ -915,7 +917,7 @@ XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName)
XXX There's no way for the caller to determine which of the
XXX possible error cases caused the XML_STATUS_ERROR return.
*/
- if (parsing == XML_PARSING || parsing == XML_SUSPENDED)
+ if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
return XML_STATUS_ERROR;
if (encodingName == NULL)
protocolEncodingName = NULL;
@@ -1143,7 +1145,7 @@ XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD)
{
#ifdef XML_DTD
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (parsing == XML_PARSING || parsing == XML_SUSPENDED)
+ if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING;
useForeignDTD = useDTD;
return XML_ERROR_NONE;
@@ -1156,7 +1158,7 @@ void XMLCALL
XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
{
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (parsing == XML_PARSING || parsing == XML_SUSPENDED)
+ if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
return;
ns_triplets = do_nst ? XML_TRUE : XML_FALSE;
}
@@ -1408,7 +1410,7 @@ XML_SetParamEntityParsing(XML_Parser parser,
enum XML_ParamEntityParsing peParsing)
{
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (parsing == XML_PARSING || parsing == XML_SUSPENDED)
+ if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
return 0;
#ifdef XML_DTD
paramEntityParsing = peParsing;
@@ -1421,7 +1423,7 @@ XML_SetParamEntityParsing(XML_Parser parser,
enum XML_Status XMLCALL
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
{
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
@@ -1429,11 +1431,11 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
default:
- parsing = XML_PARSING;
+ ps_parsing = XML_PARSING;
}
if (len == 0) {
- finalBuffer = (XML_Bool)isFinal;
+ ps_finalBuffer = (XML_Bool)isFinal;
if (!isFinal)
return XML_STATUS_OK;
positionPtr = bufferPtr;
@@ -1441,19 +1443,19 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
/* If data are left over from last buffer, and we now know that these
data are the final chunk of input, then we have to check them again
- to detect errors based on this information.
+ to detect errors based on that fact.
*/
errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
if (errorCode == XML_ERROR_NONE) {
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
positionPtr = bufferPtr;
return XML_STATUS_SUSPENDED;
case XML_INITIALIZED:
case XML_PARSING:
- parsing = XML_FINISHED;
+ ps_parsing = XML_FINISHED;
/* fall through */
default:
return XML_STATUS_OK;
@@ -1470,7 +1472,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
enum XML_Error result;
parseEndByteIndex += len;
positionPtr = s;
- finalBuffer = (XML_Bool)isFinal;
+ ps_finalBuffer = (XML_Bool)isFinal;
errorCode = processor(parser, s, parseEndPtr = s + len, &end);
@@ -1480,7 +1482,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
return XML_STATUS_ERROR;
}
else {
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
@@ -1488,14 +1490,13 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
case XML_PARSING:
result = XML_STATUS_OK;
if (isFinal) {
- parsing = XML_FINISHED;
+ ps_parsing = XML_FINISHED;
return result;
}
}
}
XmlUpdatePosition(encoding, positionPtr, end, &position);
- positionPtr = end;
nLeftOver = s + len - end;
if (nLeftOver) {
if (buffer == NULL || nLeftOver > bufferLim - buffer) {
@@ -1518,9 +1519,13 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
bufferLim = buffer + len * 2;
}
memcpy(buffer, end, nLeftOver);
- bufferPtr = buffer;
- bufferEnd = buffer + nLeftOver;
}
+ bufferPtr = buffer;
+ bufferEnd = buffer + nLeftOver;
+ positionPtr = bufferPtr;
+ parseEndPtr = bufferEnd;
+ eventPtr = bufferPtr;
+ eventEndPtr = bufferPtr;
return result;
}
#endif /* not defined XML_CONTEXT_BYTES */
@@ -1541,7 +1546,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
const char *start;
enum XML_Status result = XML_STATUS_OK;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
@@ -1549,7 +1554,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
default:
- parsing = XML_PARSING;
+ ps_parsing = XML_PARSING;
}
start = bufferPtr;
@@ -1557,7 +1562,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
bufferEnd += len;
parseEndPtr = bufferEnd;
parseEndByteIndex += len;
- finalBuffer = (XML_Bool)isFinal;
+ ps_finalBuffer = (XML_Bool)isFinal;
errorCode = processor(parser, start, parseEndPtr, &bufferPtr);
@@ -1567,14 +1572,14 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
return XML_STATUS_ERROR;
}
else {
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
case XML_INITIALIZED:
case XML_PARSING:
if (isFinal) {
- parsing = XML_FINISHED;
+ ps_parsing = XML_FINISHED;
return result;
}
default: ; /* should not happen */
@@ -1589,7 +1594,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
void * XMLCALL
XML_GetBuffer(XML_Parser parser, int len)
{
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
errorCode = XML_ERROR_SUSPENDED;
return NULL;
@@ -1601,9 +1606,9 @@ XML_GetBuffer(XML_Parser parser, int len)
if (len > bufferLim - bufferEnd) {
/* FIXME avoid integer overflow */
- int neededSize = len + (bufferEnd - bufferPtr);
+ int neededSize = len + (int)(bufferEnd - bufferPtr);
#ifdef XML_CONTEXT_BYTES
- int keep = bufferPtr - buffer;
+ int keep = (int)(bufferPtr - buffer);
if (keep > XML_CONTEXT_BYTES)
keep = XML_CONTEXT_BYTES;
@@ -1612,7 +1617,7 @@ XML_GetBuffer(XML_Parser parser, int len)
if (neededSize <= bufferLim - buffer) {
#ifdef XML_CONTEXT_BYTES
if (keep < bufferPtr - buffer) {
- int offset = (bufferPtr - buffer) - keep;
+ int offset = (int)(bufferPtr - buffer) - keep;
memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
bufferEnd -= offset;
bufferPtr -= offset;
@@ -1625,7 +1630,7 @@ XML_GetBuffer(XML_Parser parser, int len)
}
else {
char *newBuf;
- int bufferSize = bufferLim - bufferPtr;
+ int bufferSize = (int)(bufferLim - bufferPtr);
if (bufferSize == 0)
bufferSize = INIT_BUFFER_SIZE;
do {
@@ -1639,7 +1644,7 @@ XML_GetBuffer(XML_Parser parser, int len)
bufferLim = newBuf + bufferSize;
#ifdef XML_CONTEXT_BYTES
if (bufferPtr) {
- int keep = bufferPtr - buffer;
+ int keep = (int)(bufferPtr - buffer);
if (keep > XML_CONTEXT_BYTES)
keep = XML_CONTEXT_BYTES;
memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep);
@@ -1668,13 +1673,13 @@ XML_GetBuffer(XML_Parser parser, int len)
enum XML_Status XMLCALL
XML_StopParser(XML_Parser parser, XML_Bool resumable)
{
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
if (resumable) {
errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
}
- parsing = XML_FINISHED;
+ ps_parsing = XML_FINISHED;
break;
case XML_FINISHED:
errorCode = XML_ERROR_FINISHED;
@@ -1687,10 +1692,10 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable)
return XML_STATUS_ERROR;
}
#endif
- parsing = XML_SUSPENDED;
+ ps_parsing = XML_SUSPENDED;
}
else
- parsing = XML_FINISHED;
+ ps_parsing = XML_FINISHED;
}
return XML_STATUS_OK;
}
@@ -1700,11 +1705,11 @@ XML_ResumeParser(XML_Parser parser)
{
enum XML_Status result = XML_STATUS_OK;
- if (parsing != XML_SUSPENDED) {
+ if (ps_parsing != XML_SUSPENDED) {
errorCode = XML_ERROR_NOT_SUSPENDED;
return XML_STATUS_ERROR;
}
- parsing = XML_PARSING;
+ ps_parsing = XML_PARSING;
errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
@@ -1714,14 +1719,14 @@ XML_ResumeParser(XML_Parser parser)
return XML_STATUS_ERROR;
}
else {
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
case XML_INITIALIZED:
case XML_PARSING:
- if (finalBuffer) {
- parsing = XML_FINISHED;
+ if (ps_finalBuffer) {
+ ps_parsing = XML_FINISHED;
return result;
}
default: ;
@@ -1746,7 +1751,7 @@ XML_GetErrorCode(XML_Parser parser)
return errorCode;
}
-long XMLCALL
+XML_Index XMLCALL
XML_GetCurrentByteIndex(XML_Parser parser)
{
if (eventPtr)
@@ -1758,7 +1763,7 @@ int XMLCALL
XML_GetCurrentByteCount(XML_Parser parser)
{
if (eventEndPtr && eventPtr)
- return eventEndPtr - eventPtr;
+ return (int)(eventEndPtr - eventPtr);
return 0;
}
@@ -1767,15 +1772,15 @@ XML_GetInputContext(XML_Parser parser, int *offset, int *size)
{
#ifdef XML_CONTEXT_BYTES
if (eventPtr && buffer) {
- *offset = eventPtr - buffer;
- *size = bufferEnd - buffer;
+ *offset = (int)(eventPtr - buffer);
+ *size = (int)(bufferEnd - buffer);
return buffer;
}
#endif /* defined XML_CONTEXT_BYTES */
return (char *) 0;
}
-int XMLCALL
+XML_Size XMLCALL
XML_GetCurrentLineNumber(XML_Parser parser)
{
if (eventPtr && eventPtr >= positionPtr) {
@@ -1785,7 +1790,7 @@ XML_GetCurrentLineNumber(XML_Parser parser)
return position.lineNumber + 1;
}
-int XMLCALL
+XML_Size XMLCALL
XML_GetCurrentColumnNumber(XML_Parser parser)
{
if (eventPtr && eventPtr >= positionPtr) {
@@ -1836,7 +1841,7 @@ XML_DefaultCurrent(XML_Parser parser)
const XML_LChar * XMLCALL
XML_ErrorString(enum XML_Error code)
{
- static const XML_LChar *message[] = {
+ static const XML_LChar* const message[] = {
0,
XML_L("out of memory"),
XML_L("syntax error"),
@@ -1854,7 +1859,7 @@ XML_ErrorString(enum XML_Error code)
XML_L("reference to invalid character number"),
XML_L("reference to binary entity"),
XML_L("reference to external entity in attribute"),
- XML_L("xml declaration not at start of external entity"),
+ XML_L("XML or text declaration not at start of entity"),
XML_L("unknown encoding"),
XML_L("encoding specified in XML declaration is incorrect"),
XML_L("unclosed CDATA section"),
@@ -1874,7 +1879,10 @@ XML_ErrorString(enum XML_Error code)
XML_L("parser not suspended"),
XML_L("parsing aborted"),
XML_L("parsing finished"),
- XML_L("cannot suspend in external parameter entity")
+ XML_L("cannot suspend in external parameter entity"),
+ XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"),
+ XML_L("reserved prefix (xmlns) must not be declared or undeclared"),
+ XML_L("prefix must not be bound to one of the reserved namespace names")
};
if (code > 0 && code < sizeof(message)/sizeof(message[0]))
return message[code];
@@ -1916,9 +1924,11 @@ XML_ExpatVersionInfo(void)
const XML_Feature * XMLCALL
XML_GetFeatureList(void)
{
- static XML_Feature features[] = {
- {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), 0},
- {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), 0},
+ static const XML_Feature features[] = {
+ {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"),
+ sizeof(XML_Char)},
+ {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"),
+ sizeof(XML_LChar)},
#ifdef XML_UNICODE
{XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0},
#endif
@@ -1935,11 +1945,12 @@ XML_GetFeatureList(void)
#ifdef XML_MIN_SIZE
{XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0},
#endif
+#ifdef XML_NS
+ {XML_FEATURE_NS, XML_L("XML_NS"), 0},
+#endif
{XML_FEATURE_END, NULL, 0}
};
- features[0].value = sizeof(XML_Char);
- features[1].value = sizeof(XML_LChar);
return features;
}
@@ -2000,7 +2011,7 @@ contentProcessor(XML_Parser parser,
const char **endPtr)
{
enum XML_Error result = doContent(parser, 0, encoding, start, end,
- endPtr, (XML_Bool)!finalBuffer);
+ endPtr, (XML_Bool)!ps_finalBuffer);
if (result == XML_ERROR_NONE) {
if (!storeRawNames(parser))
return XML_ERROR_NO_MEMORY;
@@ -2036,21 +2047,21 @@ externalEntityInitProcessor2(XML_Parser parser,
doContent (by detecting XML_TOK_NONE) without processing any xml text
declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent.
*/
- if (next == end && !finalBuffer) {
+ if (next == end && !ps_finalBuffer) {
*endPtr = next;
return XML_ERROR_NONE;
}
start = next;
break;
case XML_TOK_PARTIAL:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
eventPtr = start;
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
@@ -2080,7 +2091,7 @@ externalEntityInitProcessor3(XML_Parser parser,
result = processXmlDecl(parser, 1, start, next);
if (result != XML_ERROR_NONE)
return result;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*endPtr = next;
return XML_ERROR_NONE;
@@ -2092,13 +2103,13 @@ externalEntityInitProcessor3(XML_Parser parser,
}
break;
case XML_TOK_PARTIAL:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
@@ -2116,7 +2127,7 @@ externalEntityContentProcessor(XML_Parser parser,
const char **endPtr)
{
enum XML_Error result = doContent(parser, 1, encoding, start, end,
- endPtr, (XML_Bool)!finalBuffer);
+ endPtr, (XML_Bool)!ps_finalBuffer);
if (result == XML_ERROR_NONE) {
if (!storeRawNames(parser))
return XML_ERROR_NO_MEMORY;
@@ -2315,12 +2326,12 @@ doContent(XML_Parser parser,
XmlConvert(enc,
&fromPtr, rawNameEnd,
(ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1);
- convLen = toPtr - (XML_Char *)tag->buf;
+ convLen = (int)(toPtr - (XML_Char *)tag->buf);
if (fromPtr == rawNameEnd) {
tag->name.strLen = convLen;
break;
}
- bufSize = (tag->bufEnd - tag->buf) << 1;
+ bufSize = (int)(tag->bufEnd - tag->buf) << 1;
{
char *temp = (char *)REALLOC(tag->buf, bufSize);
if (temp == NULL)
@@ -2508,12 +2519,12 @@ doContent(XML_Parser parser,
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
characterDataHandler(handlerArg, dataBuf,
- dataPtr - (ICHAR *)dataBuf);
+ (int)(dataPtr - (ICHAR *)dataBuf));
}
else
characterDataHandler(handlerArg,
(XML_Char *)s,
- (XML_Char *)end - (XML_Char *)s);
+ (int)((XML_Char *)end - (XML_Char *)s));
}
else if (defaultHandler)
reportDefault(parser, enc, s, end);
@@ -2538,7 +2549,7 @@ doContent(XML_Parser parser,
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
*eventEndPP = s;
characterDataHandler(handlerArg, dataBuf,
- dataPtr - (ICHAR *)dataBuf);
+ (int)(dataPtr - (ICHAR *)dataBuf));
if (s == next)
break;
*eventPP = s;
@@ -2547,7 +2558,7 @@ doContent(XML_Parser parser,
else
characterDataHandler(handlerArg,
(XML_Char *)s,
- (XML_Char *)next - (XML_Char *)s);
+ (int)((XML_Char *)next - (XML_Char *)s));
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
@@ -2566,7 +2577,7 @@ doContent(XML_Parser parser,
break;
}
*eventPP = s = next;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -2822,7 +2833,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
}
if (!step)
step = PROBE_STEP(uriHash, mask, nsAttsPower);
- j < step ? ( j += nsAttsSize - step) : (j -= step);
+ j < step ? (j += nsAttsSize - step) : (j -= step);
}
}
@@ -2845,8 +2856,10 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
nsAtts[j].hash = uriHash;
nsAtts[j].uriName = s;
- if (!--nPrefixes)
+ if (!--nPrefixes) {
+ i += 2;
break;
+ }
}
else /* not prefixed */
((XML_Char *)s)[-1] = 0; /* clear flag */
@@ -2879,14 +2892,14 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
prefixLen = 0;
if (ns_triplets && binding->prefix->name) {
for (; binding->prefix->name[prefixLen++];)
- ;
+ ; /* prefixLen includes null terminator */
}
tagNamePtr->localPart = localPart;
tagNamePtr->uriLen = binding->uriLen;
tagNamePtr->prefix = binding->prefix->name;
tagNamePtr->prefixLen = prefixLen;
for (i = 0; localPart[i++];)
- ;
+ ; /* i includes null terminator */
n = i + binding->uriLen + prefixLen;
if (n > binding->uriAlloc) {
TAG *p;
@@ -2901,12 +2914,13 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
FREE(binding->uri);
binding->uri = uri;
}
+ /* if namespaceSeparator != '\0' then uri includes it already */
uri = binding->uri + binding->uriLen;
memcpy(uri, localPart, i * sizeof(XML_Char));
+ /* we always have a namespace separator between localPart and prefix */
if (prefixLen) {
- uri = uri + (i - 1);
- if (namespaceSeparator)
- *uri = namespaceSeparator;
+ uri += i - 1;
+ *uri = namespaceSeparator; /* replace null terminator */
memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char));
}
tagNamePtr->str = binding->uri;
@@ -2920,6 +2934,26 @@ static enum XML_Error
addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
const XML_Char *uri, BINDING **bindingsPtr)
{
+ static const XML_Char xmlNamespace[] = {
+ 'h', 't', 't', 'p', ':', '/', '/',
+ 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+ 'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
+ 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0'
+ };
+ static const int xmlLen =
+ (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;
+ static const XML_Char xmlnsNamespace[] = {
+ 'h', 't', 't', 'p', ':', '/', '/',
+ 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+ '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0'
+ };
+ static const int xmlnsLen =
+ (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;
+
+ XML_Bool mustBeXML = XML_FALSE;
+ XML_Bool isXML = XML_TRUE;
+ XML_Bool isXMLNS = XML_TRUE;
+
BINDING *b;
int len;
@@ -2927,8 +2961,39 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
if (*uri == XML_T('\0') && prefix->name)
return XML_ERROR_UNDECLARING_PREFIX;
- for (len = 0; uri[len]; len++)
- ;
+ if (prefix->name
+ && prefix->name[0] == XML_T('x')
+ && prefix->name[1] == XML_T('m')
+ && prefix->name[2] == XML_T('l')) {
+
+ /* Not allowed to bind xmlns */
+ if (prefix->name[3] == XML_T('n')
+ && prefix->name[4] == XML_T('s')
+ && prefix->name[5] == XML_T('\0'))
+ return XML_ERROR_RESERVED_PREFIX_XMLNS;
+
+ if (prefix->name[3] == XML_T('\0'))
+ mustBeXML = XML_TRUE;
+ }
+
+ for (len = 0; uri[len]; len++) {
+ if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
+ isXML = XML_FALSE;
+
+ if (!mustBeXML && isXMLNS
+ && (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
+ isXMLNS = XML_FALSE;
+ }
+ isXML = isXML && len == xmlLen;
+ isXMLNS = isXMLNS && len == xmlnsLen;
+
+ if (mustBeXML != isXML)
+ return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML
+ : XML_ERROR_RESERVED_NAMESPACE_URI;
+
+ if (isXMLNS)
+ return XML_ERROR_RESERVED_NAMESPACE_URI;
+
if (namespaceSeparator)
len++;
if (freeBindingList) {
@@ -2985,7 +3050,7 @@ cdataSectionProcessor(XML_Parser parser,
const char **endPtr)
{
enum XML_Error result = doCdataSection(parser, encoding, &start, end,
- endPtr, (XML_Bool)!finalBuffer);
+ endPtr, (XML_Bool)!ps_finalBuffer);
if (result != XML_ERROR_NONE)
return result;
if (start) {
@@ -3044,7 +3109,7 @@ doCdataSection(XML_Parser parser,
reportDefault(parser, enc, s, next);
*startPtr = next;
*nextPtr = next;
- if (parsing == XML_FINISHED)
+ if (ps_parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
else
return XML_ERROR_NONE;
@@ -3064,7 +3129,7 @@ doCdataSection(XML_Parser parser,
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
*eventEndPP = next;
characterDataHandler(handlerArg, dataBuf,
- dataPtr - (ICHAR *)dataBuf);
+ (int)(dataPtr - (ICHAR *)dataBuf));
if (s == next)
break;
*eventPP = s;
@@ -3073,7 +3138,7 @@ doCdataSection(XML_Parser parser,
else
characterDataHandler(handlerArg,
(XML_Char *)s,
- (XML_Char *)next - (XML_Char *)s);
+ (int)((XML_Char *)next - (XML_Char *)s));
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
@@ -3100,7 +3165,7 @@ doCdataSection(XML_Parser parser,
}
*eventPP = s = next;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -3124,7 +3189,7 @@ ignoreSectionProcessor(XML_Parser parser,
const char **endPtr)
{
enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
- endPtr, (XML_Bool)!finalBuffer);
+ endPtr, (XML_Bool)!ps_finalBuffer);
if (result != XML_ERROR_NONE)
return result;
if (start) {
@@ -3169,7 +3234,7 @@ doIgnoreSection(XML_Parser parser,
reportDefault(parser, enc, s, next);
*startPtr = next;
*nextPtr = next;
- if (parsing == XML_FINISHED)
+ if (ps_parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
else
return XML_ERROR_NONE;
@@ -3409,7 +3474,7 @@ entityValueInitProcessor(XML_Parser parser,
tok = XmlPrologTok(encoding, start, end, &next);
eventEndPtr = next;
if (tok <= 0) {
- if (!finalBuffer && tok != XML_TOK_INVALID) {
+ if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -3432,7 +3497,7 @@ entityValueInitProcessor(XML_Parser parser,
result = processXmlDecl(parser, 0, start, next);
if (result != XML_ERROR_NONE)
return result;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -3452,7 +3517,7 @@ entityValueInitProcessor(XML_Parser parser,
then, when this routine is entered the next time, XmlPrologTok will
return XML_TOK_INVALID, since the BOM is still in the buffer
*/
- else if (tok == XML_TOK_BOM && next == end && !finalBuffer) {
+ else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) {
*nextPtr = next;
return XML_ERROR_NONE;
}
@@ -3472,7 +3537,7 @@ externalParEntProcessor(XML_Parser parser,
tok = XmlPrologTok(encoding, s, end, &next);
if (tok <= 0) {
- if (!finalBuffer && tok != XML_TOK_INVALID) {
+ if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -3499,7 +3564,7 @@ externalParEntProcessor(XML_Parser parser,
processor = prologProcessor;
return doProlog(parser, encoding, s, end, tok, next,
- nextPtr, (XML_Bool)!finalBuffer);
+ nextPtr, (XML_Bool)!ps_finalBuffer);
}
static enum XML_Error PTRCALL
@@ -3516,7 +3581,7 @@ entityValueProcessor(XML_Parser parser,
for (;;) {
tok = XmlPrologTok(enc, start, end, &next);
if (tok <= 0) {
- if (!finalBuffer && tok != XML_TOK_INVALID) {
+ if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -3549,7 +3614,7 @@ prologProcessor(XML_Parser parser,
const char *next = s;
int tok = XmlPrologTok(encoding, s, end, &next);
return doProlog(parser, encoding, s, end, tok, next,
- nextPtr, (XML_Bool)!finalBuffer);
+ nextPtr, (XML_Bool)!ps_finalBuffer);
}
static enum XML_Error
@@ -3738,7 +3803,8 @@ doProlog(XML_Parser parser,
*/
#ifdef XML_DTD
if (doctypeSysid || useForeignDTD) {
- dtd->hasParamEntityRefs = XML_TRUE; /* when docTypeSysid == NULL */
+ XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
+ dtd->hasParamEntityRefs = XML_TRUE;
if (paramEntityParsing && externalEntityRefHandler) {
ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,
externalSubsetName,
@@ -3754,11 +3820,17 @@ doProlog(XML_Parser parser,
entity->systemId,
entity->publicId))
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
- if (dtd->paramEntityRead &&
- !dtd->standalone &&
- notStandaloneHandler &&
- !notStandaloneHandler(handlerArg))
- return XML_ERROR_NOT_STANDALONE;
+ if (dtd->paramEntityRead) {
+ if (!dtd->standalone &&
+ notStandaloneHandler &&
+ !notStandaloneHandler(handlerArg))
+ return XML_ERROR_NOT_STANDALONE;
+ }
+ /* if we didn't read the foreign DTD then this means that there
+ is no external subset and we must reset dtd->hasParamEntityRefs
+ */
+ else if (!doctypeSysid)
+ dtd->hasParamEntityRefs = hadParamEntityRefs;
/* end of DTD - no need to update dtd->keepProcessing */
}
useForeignDTD = XML_FALSE;
@@ -3775,6 +3847,7 @@ doProlog(XML_Parser parser,
last chance to read the foreign DTD
*/
if (useForeignDTD) {
+ XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
dtd->hasParamEntityRefs = XML_TRUE;
if (paramEntityParsing && externalEntityRefHandler) {
ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,
@@ -3790,11 +3863,17 @@ doProlog(XML_Parser parser,
entity->systemId,
entity->publicId))
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
- if (dtd->paramEntityRead &&
- !dtd->standalone &&
- notStandaloneHandler &&
- !notStandaloneHandler(handlerArg))
- return XML_ERROR_NOT_STANDALONE;
+ if (dtd->paramEntityRead) {
+ if (!dtd->standalone &&
+ notStandaloneHandler &&
+ !notStandaloneHandler(handlerArg))
+ return XML_ERROR_NOT_STANDALONE;
+ }
+ /* if we didn't read the foreign DTD then this means that there
+ is no external subset and we must reset dtd->hasParamEntityRefs
+ */
+ else
+ dtd->hasParamEntityRefs = hadParamEntityRefs;
/* end of DTD - no need to update dtd->keepProcessing */
}
}
@@ -3935,7 +4014,7 @@ doProlog(XML_Parser parser,
next - enc->minBytesPerChar);
if (declEntity) {
declEntity->textPtr = poolStart(&dtd->entityValuePool);
- declEntity->textLen = poolLength(&dtd->entityValuePool);
+ declEntity->textLen = (int)(poolLength(&dtd->entityValuePool));
poolFinish(&dtd->entityValuePool);
if (entityDeclHandler) {
*eventEndPP = s;
@@ -4496,7 +4575,7 @@ doProlog(XML_Parser parser,
if (handleDefault && defaultHandler)
reportDefault(parser, enc, s, next);
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -4527,7 +4606,7 @@ epilogProcessor(XML_Parser parser,
case -XML_TOK_PROLOG_S:
if (defaultHandler) {
reportDefault(parser, encoding, s, next);
- if (parsing == XML_FINISHED)
+ if (ps_parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
}
*nextPtr = next;
@@ -4551,13 +4630,13 @@ epilogProcessor(XML_Parser parser,
eventPtr = next;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_PARTIAL:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!finalBuffer) {
+ if (!ps_finalBuffer) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -4566,7 +4645,7 @@ epilogProcessor(XML_Parser parser,
return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
}
eventPtr = s = next;
- switch (parsing) {
+ switch (ps_parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -4619,8 +4698,8 @@ processInternalEntity(XML_Parser parser, ENTITY *entity,
textEnd, &next, XML_FALSE);
if (result == XML_ERROR_NONE) {
- if (textEnd != next && parsing == XML_SUSPENDED) {
- entity->processed = next - textStart;
+ if (textEnd != next && ps_parsing == XML_SUSPENDED) {
+ entity->processed = (int)(next - textStart);
processor = internalEntityProcessor;
}
else {
@@ -4665,8 +4744,8 @@ internalEntityProcessor(XML_Parser parser,
if (result != XML_ERROR_NONE)
return result;
- else if (textEnd != next && parsing == XML_SUSPENDED) {
- entity->processed = next - (char *)entity->textPtr;
+ else if (textEnd != next && ps_parsing == XML_SUSPENDED) {
+ entity->processed = (int)(next - (char *)entity->textPtr);
return result;
}
else {
@@ -4683,7 +4762,7 @@ internalEntityProcessor(XML_Parser parser,
processor = prologProcessor;
tok = XmlPrologTok(encoding, s, end, &next);
return doProlog(parser, encoding, s, end, tok, next, nextPtr,
- (XML_Bool)!finalBuffer);
+ (XML_Bool)!ps_finalBuffer);
}
else
#endif /* XML_DTD */
@@ -4691,7 +4770,7 @@ internalEntityProcessor(XML_Parser parser,
processor = contentProcessor;
/* see externalEntityContentProcessor vs contentProcessor */
return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
- nextPtr, (XML_Bool)!finalBuffer);
+ nextPtr, (XML_Bool)!ps_finalBuffer);
}
}
@@ -4800,9 +4879,8 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
return XML_ERROR_NO_MEMORY;
entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0);
poolDiscard(&temp2Pool);
- /* first, determine if a check for an existing declaration is needed;
- if yes, check that the entity exists, and that it is internal,
- otherwise call the default handler (if called from content)
+ /* First, determine if a check for an existing declaration is needed;
+ if yes, check that the entity exists, and that it is internal.
*/
if (pool == &dtd->pool) /* are we called from prolog? */
checkEntityDecl =
@@ -4821,13 +4899,16 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
return XML_ERROR_ENTITY_DECLARED_IN_PE;
}
else if (!entity) {
- /* cannot report skipped entity here - see comments on
- skippedEntityHandler
+ /* Cannot report skipped entity here - see comments on
+ skippedEntityHandler.
if (skippedEntityHandler)
skippedEntityHandler(handlerArg, name, 0);
*/
+ /* Cannot call the default handler because this would be
+ out of sync with the call to the startElementHandler.
if ((pool == &tempPool) && defaultHandler)
reportDefault(parser, enc, ptr, next);
+ */
break;
}
if (entity->open) {
@@ -5127,12 +5208,12 @@ reportDefault(XML_Parser parser, const ENCODING *enc,
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
*eventEndPP = s;
- defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
+ defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
*eventPP = s;
} while (s != end);
}
else
- defaultHandler(handlerArg, (XML_Char *)s, (XML_Char *)end - (XML_Char *)s);
+ defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
}
@@ -5286,7 +5367,7 @@ getContext(XML_Parser parser)
if (!poolAppendChar(&tempPool, XML_T('=')))
return NULL;
len = dtd->defaultPrefix.binding->uriLen;
- if (namespaceSeparator != XML_T('\0'))
+ if (namespaceSeparator)
len--;
for (i = 0; i < len; i++)
if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i]))
@@ -5312,7 +5393,7 @@ getContext(XML_Parser parser)
if (!poolAppendChar(&tempPool, XML_T('=')))
return NULL;
len = prefix->binding->uriLen;
- if (namespaceSeparator != XML_T('\0'))
+ if (namespaceSeparator)
len--;
for (i = 0; i < len; i++)
if (!poolAppendChar(&tempPool, prefix->binding->uri[i]))
@@ -6014,7 +6095,7 @@ poolGrow(STRING_POOL *pool)
}
}
if (pool->blocks && pool->start == pool->blocks->s) {
- int blockSize = (pool->end - pool->start)*2;
+ int blockSize = (int)(pool->end - pool->start)*2;
pool->blocks = (BLOCK *)
pool->mem->realloc_fcn(pool->blocks,
(offsetof(BLOCK, s)
@@ -6028,7 +6109,7 @@ poolGrow(STRING_POOL *pool)
}
else {
BLOCK *tem;
- int blockSize = pool->end - pool->start;
+ int blockSize = (int)(pool->end - pool->start);
if (blockSize < INIT_BLOCK_SIZE)
blockSize = INIT_BLOCK_SIZE;
else
diff --git a/Modules/expat/xmlrole.c b/Modules/expat/xmlrole.c
index 2587fdf..15d4d8f 100644
--- a/Modules/expat/xmlrole.c
+++ b/Modules/expat/xmlrole.c
@@ -6,6 +6,8 @@
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
#include "macconfig.h"
+#elif defined(__amigaos4__)
+#include "amigaconfig.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include <expat_config.h>
@@ -793,7 +795,7 @@ attlist2(PROLOG_STATE *state,
return XML_ROLE_ATTLIST_NONE;
case XML_TOK_NAME:
{
- static const char *types[] = {
+ static const char * const types[] = {
KW_CDATA,
KW_ID,
KW_IDREF,
diff --git a/Modules/expat/xmltok.c b/Modules/expat/xmltok.c
index 8b9d997..db92247 100644
--- a/Modules/expat/xmltok.c
+++ b/Modules/expat/xmltok.c
@@ -6,6 +6,8 @@
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
#include "macconfig.h"
+#elif defined(__amigaos4__)
+#include "amigaconfig.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include <expat_config.h>
@@ -1451,7 +1453,7 @@ static const char KW_UTF_16LE[] = {
static int FASTCALL
getEncodingIndex(const char *name)
{
- static const char *encodingNames[] = {
+ static const char * const encodingNames[] = {
KW_ISO_8859_1,
KW_US_ASCII,
KW_UTF_8,
@@ -1484,7 +1486,7 @@ getEncodingIndex(const char *name)
static int
-initScan(const ENCODING **encodingTable,
+initScan(const ENCODING * const *encodingTable,
const INIT_ENCODING *enc,
int state,
const char *ptr,
diff --git a/Modules/expat/xmltok.h b/Modules/expat/xmltok.h
index 1ecd05f..ca867aa 100644
--- a/Modules/expat/xmltok.h
+++ b/Modules/expat/xmltok.h
@@ -111,8 +111,8 @@ extern "C" {
typedef struct position {
/* first line and first column are 0 not 1 */
- unsigned long lineNumber;
- unsigned long columnNumber;
+ XML_Size lineNumber;
+ XML_Size columnNumber;
} POSITION;
typedef struct {
diff --git a/Modules/expat/xmltok_impl.c b/Modules/expat/xmltok_impl.c
index 46569fe..0ee57ab 100644
--- a/Modules/expat/xmltok_impl.c
+++ b/Modules/expat/xmltok_impl.c
@@ -1714,7 +1714,7 @@ PREFIX(nameLength)(const ENCODING *enc, const char *ptr)
ptr += MINBPC(enc);
break;
default:
- return ptr - start;
+ return (int)(ptr - start);
}
}
}
@@ -1750,7 +1750,7 @@ PREFIX(updatePosition)(const ENCODING *enc,
LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)
#undef LEAD_CASE
case BT_LF:
- pos->columnNumber = (unsigned)-1;
+ pos->columnNumber = (XML_Size)-1;
pos->lineNumber++;
ptr += MINBPC(enc);
break;
@@ -1759,7 +1759,7 @@ PREFIX(updatePosition)(const ENCODING *enc,
ptr += MINBPC(enc);
if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF)
ptr += MINBPC(enc);
- pos->columnNumber = (unsigned)-1;
+ pos->columnNumber = (XML_Size)-1;
break;
default:
ptr += MINBPC(enc);
diff --git a/Modules/expat/xmltok_ns.c b/Modules/expat/xmltok_ns.c
index 5610eb9..d2f8938 100644
--- a/Modules/expat/xmltok_ns.c
+++ b/Modules/expat/xmltok_ns.c
@@ -19,7 +19,7 @@ NS(XmlGetUtf16InternalEncoding)(void)
#endif
}
-static const ENCODING *NS(encodings)[] = {
+static const ENCODING * const NS(encodings)[] = {
&ns(latin1_encoding).enc,
&ns(ascii_encoding).enc,
&ns(utf8_encoding).enc,
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index 477af06..4e49a7d 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -290,7 +290,7 @@ PyDoc_STRVAR(flock_doc,
"flock(fd, operation)\n\
\n\
Perform the lock operation op on file descriptor fd. See the Unix \n\
-manual flock(3) for details. (On some systems, this function is\n\
+manual page for flock(3) for details. (On some systems, this function is\n\
emulated using fcntl().)");
@@ -327,7 +327,7 @@ fcntl_lockf(PyObject *self, PyObject *args)
l.l_type = F_WRLCK;
else {
PyErr_SetString(PyExc_ValueError,
- "unrecognized flock argument");
+ "unrecognized lockf argument");
return NULL;
}
l.l_start = l.l_len = 0;
diff --git a/Modules/fpectlmodule.c b/Modules/fpectlmodule.c
index c6d4f77..74354ba 100644
--- a/Modules/fpectlmodule.c
+++ b/Modules/fpectlmodule.c
@@ -70,6 +70,10 @@ extern "C" {
#if defined(__FreeBSD__)
# include <ieeefp.h>
+#elif defined(__VMS)
+#define __NEW_STARLET
+#include <starlet.h>
+#include <ieeedef.h>
#endif
#ifndef WANT_SIGFPE_HANDLER
@@ -190,6 +194,19 @@ static void fpe_reset(Sigfunc *handler)
/*-- DEC ALPHA VMS --------------------------------------------------------*/
#elif defined(__ALPHA) && defined(__VMS)
+ IEEE clrmsk;
+ IEEE setmsk;
+ clrmsk.ieee$q_flags =
+ IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE |
+ IEEE$M_MAP_UMZ;
+ setmsk.ieee$q_flags =
+ IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE |
+ IEEE$M_TRAP_ENABLE_OVF;
+ sys$ieee_set_fp_control(&clrmsk, &setmsk, 0);
+ PyOS_setsig(SIGFPE, handler);
+
+/*-- HP IA64 VMS --------------------------------------------------------*/
+#elif defined(__ia64) && defined(__VMS)
PyOS_setsig(SIGFPE, handler);
/*-- Cray Unicos ----------------------------------------------------------*/
@@ -244,6 +261,14 @@ static PyObject *turnoff_sigfpe(PyObject *self,PyObject *args)
#ifdef __FreeBSD__
fpresetsticky(fpgetsticky());
fpsetmask(0);
+#elif defined(__VMS)
+ IEEE clrmsk;
+ clrmsk.ieee$q_flags =
+ IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE |
+ IEEE$M_MAP_UMZ | IEEE$M_TRAP_ENABLE_INV |
+ IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF |
+ IEEE$M_INHERIT;
+ sys$ieee_set_fp_control(&clrmsk, 0, 0);
#else
fputs("Operation not implemented\n", stderr);
#endif
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 8eba730..78bfaf9 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -97,19 +97,19 @@
#ifndef VERSION
-#if defined(__VMS)
-#define VERSION "2_1"
-#else
#define VERSION "2.1"
#endif
-#endif
#ifndef VPATH
#define VPATH "."
#endif
#ifndef PREFIX
-#define PREFIX "/usr/local"
+# ifdef __VMS
+# define PREFIX ""
+# else
+# define PREFIX "/usr/local"
+# endif
#endif
#ifndef EXEC_PREFIX
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 86b1bbf..d913890 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -357,7 +357,7 @@ teedataobject_jumplink(teedataobject *tdo)
{
if (tdo->nextlink == NULL)
tdo->nextlink = teedataobject_new(tdo->it);
- Py_INCREF(tdo->nextlink);
+ Py_XINCREF(tdo->nextlink);
return tdo->nextlink;
}
@@ -468,7 +468,7 @@ tee_next(teeobject *to)
if (to->index >= LINKCELLS) {
link = teedataobject_jumplink(to->dataobj);
- Py_XDECREF(to->dataobj);
+ Py_DECREF(to->dataobj);
to->dataobj = (teedataobject *)link;
to->index = 0;
}
@@ -522,6 +522,12 @@ tee_fromiterable(PyObject *iterable)
if (to == NULL)
goto done;
to->dataobj = (teedataobject *)teedataobject_new(it);
+ if (!to->dataobj) {
+ PyObject_GC_Del(to);
+ to = NULL;
+ goto done;
+ }
+
to->index = 0;
to->weakreflist = NULL;
PyObject_GC_Track(to);
diff --git a/Modules/main.c b/Modules/main.c
index 23a760f..3f39c9b 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -39,7 +39,7 @@ static char **orig_argv;
static int orig_argc;
/* command line options */
-#define BASE_OPTS "c:dEhim:OStuvVW:xX"
+#define BASE_OPTS "c:dEhim:OStuvVW:xX?"
#ifndef RISCOS
#define PROGRAM_OPTS BASE_OPTS
@@ -61,7 +61,7 @@ Options and arguments (and corresponding environment variables):\n\
-c cmd : program passed in as string (terminates option list)\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-E : ignore environment variables (such as PYTHONPATH)\n\
--h : print this help message and exit\n\
+-h : print this help message and exit (also --help)\n\
-i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
and force prompts, even if stdin does not appear to be a terminal\n\
";
@@ -76,7 +76,7 @@ static char *usage_2 = "\
static char *usage_3 = "\
see man page for details on internal buffering relating to '-u'\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
--V : print the Python version number and exit\n\
+-V : print the Python version number and exit (also --version)\n\
-W arg : warning control (arg is action:message:category:module:lineno)\n\
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
file : program read from script file\n\
@@ -281,6 +281,7 @@ Py_Main(int argc, char **argv)
break;
case 'h':
+ case '?':
help++;
break;
@@ -431,9 +432,10 @@ Py_Main(int argc, char **argv)
}
if (module != NULL) {
- /* Backup _PyOS_optind and force sys.arv[0] = module */
+ /* Backup _PyOS_optind and force sys.argv[0] = '-c'
+ so that PySys_SetArgv correctly sets sys.path[0] to ''*/
_PyOS_optind--;
- argv[_PyOS_optind] = module;
+ argv[_PyOS_optind] = "-c";
}
PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index d7a8944..afe9916 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -50,7 +50,10 @@ my_getpagesize(void)
#endif /* UNIX */
#include <string.h>
+
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
/* Prefer MAP_ANONYMOUS since MAP_ANON is deprecated according to man page. */
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c0280de..d968b6c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -64,14 +64,21 @@ corresponding Unix manual entries for more information on calls.");
#include "osdefs.h"
#endif
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
+#endif /* HAVE_SYS_STAT_H */
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h> /* For WNOHANG */
#endif
+#ifdef HAVE_SIGNAL_H
#include <signal.h>
+#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
@@ -246,9 +253,15 @@ extern int lstat(const char *, struct stat *);
#endif
#ifdef _MSC_VER
+#ifdef HAVE_DIRECT_H
#include <direct.h>
+#endif
+#ifdef HAVE_IO_H
#include <io.h>
+#endif
+#ifdef HAVE_PROCESS_H
#include <process.h>
+#endif
#include "osdefs.h"
#define _WIN32_WINNT 0x0400 /* Needed for CryptoAPI on some systems */
#include <windows.h>
@@ -1227,7 +1240,9 @@ _pystat_fromstructstat(STRUCT_STAT *st)
#define ISSLASHA(c) ((c) == '\\' || (c) == '/')
#define ISSLASHW(c) ((c) == L'\\' || (c) == L'/')
+#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
+#endif
static BOOL
IsUNCRootA(char *path, int pathlen)
@@ -1387,7 +1402,7 @@ finish:
return PyBool_FromLong(0);
/* Access is possible if either write access wasn't requested, or
the file isn't read-only. */
- return PyBool_FromLong(!(mode & 2) || !(attr && FILE_ATTRIBUTE_READONLY));
+ return PyBool_FromLong(!(mode & 2) || !(attr & FILE_ATTRIBUTE_READONLY));
#else
int res;
if (!PyArg_ParseTuple(args, "eti:access",
@@ -1847,6 +1862,15 @@ posix_listdir(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
result = FindNextFileW(hFindFile, &wFileData);
Py_END_ALLOW_THREADS
+ /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+ it got to the end of the directory. */
+ if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ Py_DECREF(d);
+ win32_error_unicode("FindNextFileW", wnamebuf);
+ FindClose(hFindFile);
+ free(wnamebuf);
+ return NULL;
+ }
} while (result == TRUE);
if (FindClose(hFindFile) == FALSE) {
@@ -1906,6 +1930,14 @@ posix_listdir(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
result = FindNextFile(hFindFile, &FileData);
Py_END_ALLOW_THREADS
+ /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+ it got to the end of the directory. */
+ if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+ Py_DECREF(d);
+ win32_error("FindNextFile", namebuf);
+ FindClose(hFindFile);
+ return NULL;
+ }
} while (result == TRUE);
if (FindClose(hFindFile) == FALSE) {
@@ -7867,6 +7899,42 @@ win32_urandom(PyObject *self, PyObject *args)
}
#endif
+#ifdef __VMS
+/* Use openssl random routine */
+#include <openssl/rand.h>
+PyDoc_STRVAR(vms_urandom__doc__,
+"urandom(n) -> str\n\n\
+Return a string of n random bytes suitable for cryptographic use.");
+
+static PyObject*
+vms_urandom(PyObject *self, PyObject *args)
+{
+ int howMany;
+ PyObject* result;
+
+ /* Read arguments */
+ if (! PyArg_ParseTuple(args, "i:urandom", &howMany))
+ return NULL;
+ if (howMany < 0)
+ return PyErr_Format(PyExc_ValueError,
+ "negative argument not allowed");
+
+ /* Allocate bytes */
+ result = PyString_FromStringAndSize(NULL, howMany);
+ if (result != NULL) {
+ /* Get random data */
+ if (RAND_pseudo_bytes((unsigned char*)
+ PyString_AS_STRING(result),
+ howMany) < 0) {
+ Py_DECREF(result);
+ return PyErr_Format(PyExc_ValueError,
+ "RAND_pseudo_bytes");
+ }
+ }
+ return result;
+}
+#endif
+
static PyMethodDef posix_methods[] = {
{"access", posix_access, METH_VARARGS, posix_access__doc__},
#ifdef HAVE_TTYNAME
@@ -8160,6 +8228,9 @@ static PyMethodDef posix_methods[] = {
#ifdef MS_WINDOWS
{"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__},
#endif
+ #ifdef __VMS
+ {"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__},
+ #endif
{NULL, NULL} /* Sentinel */
};
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 8a10bab..67f7007 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -238,6 +238,18 @@ error_external_entity_ref_handler(XML_Parser parser,
return 0;
}
+/* Dummy character data handler used when an error (exception) has
+ been detected, and the actual parsing can be terminated early.
+ This is needed since character data handler can't be safely removed
+ from within the character data handler, but can be replaced. It is
+ used only from the character data handler trampoline, and must be
+ used right after `flag_error()` is called. */
+static void
+noop_character_data_handler(void *userData, const XML_Char *data, int len)
+{
+ /* Do nothing. */
+}
+
static void
flag_error(xmlparseobject *self)
{
@@ -457,6 +469,8 @@ call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len)
if (temp == NULL) {
Py_DECREF(args);
flag_error(self);
+ XML_SetCharacterDataHandler(self->itself,
+ noop_character_data_handler);
return -1;
}
PyTuple_SET_ITEM(args, 0, temp);
@@ -469,6 +483,8 @@ call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len)
Py_DECREF(args);
if (temp == NULL) {
flag_error(self);
+ XML_SetCharacterDataHandler(self->itself,
+ noop_character_data_handler);
return -1;
}
Py_DECREF(temp);
@@ -1542,8 +1558,22 @@ sethandler(xmlparseobject *self, const char *name, PyObject* v)
xmlhandler c_handler = NULL;
PyObject *temp = self->handlers[handlernum];
- if (v == Py_None)
+ if (v == Py_None) {
+ /* If this is the character data handler, and a character
+ data handler is already active, we need to be more
+ careful. What we can safely do is replace the existing
+ character data handler callback function with a no-op
+ function that will refuse to call Python. The downside
+ is that this doesn't completely remove the character
+ data handler from the C layer if there's any callback
+ active, so Expat does a little more work than it
+ otherwise would, but that's really an odd case. A more
+ elaborate system of handlers and state could remove the
+ C handler more effectively. */
+ if (handlernum == CharacterData && self->in_callback)
+ c_handler = noop_character_data_handler;
v = NULL;
+ }
else if (v != NULL) {
Py_INCREF(v);
c_handler = handler_info[handlernum].handler;
diff --git a/Modules/readline.c b/Modules/readline.c
index 8fda228..92f2d1f 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -20,6 +20,12 @@
#include <locale.h>
#endif
+#ifdef SAVE_LOCALE
+# define RESTORE_LOCALE(sl) { setlocale(LC_CTYPE, sl); free(sl); }
+#else
+# define RESTORE_LOCALE(sl)
+#endif
+
/* GNU readline definitions */
#undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
#include <readline/readline.h>
@@ -723,10 +729,7 @@ setup_readline(void)
*/
rl_initialize();
-#ifdef SAVE_LOCALE
- setlocale(LC_CTYPE, saved_locale); /* Restore locale */
- free(saved_locale);
-#endif
+ RESTORE_LOCALE(saved_locale)
}
/* Wrapper around GNU readline that handles signals differently. */
@@ -864,7 +867,8 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p = readline_until_enter_or_signal(prompt, &signal);
/* we got an interrupt signal */
- if(signal) {
+ if (signal) {
+ RESTORE_LOCALE(saved_locale)
return NULL;
}
@@ -873,6 +877,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p = PyMem_Malloc(1);
if (p != NULL)
*p = '\0';
+ RESTORE_LOCALE(saved_locale)
return p;
}
@@ -905,10 +910,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p[n+1] = '\0';
}
free(q);
-#ifdef SAVE_LOCALE
- setlocale(LC_CTYPE, saved_locale); /* Restore locale */
- free(saved_locale);
-#endif
+ RESTORE_LOCALE(saved_locale)
return p;
}
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index dfa4e85..9eaae84 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -36,7 +36,7 @@
extern void bzero(void *, int);
#endif
-#ifndef DONT_HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -46,14 +46,14 @@ extern void bzero(void *, int);
#endif
#ifdef MS_WINDOWS
-#include <winsock.h>
+# include <winsock.h>
#else
-#ifdef __BEOS__
-#include <net/socket.h>
-#define SOCKET int
-#else
-#define SOCKET int
-#endif
+# define SOCKET int
+# ifdef __BEOS__
+# include <net/socket.h>
+# elif defined(__VMS)
+# include <socket.h>
+# endif
#endif
@@ -668,7 +668,7 @@ arguments; each contains the subset of the corresponding file descriptors\n\
that are ready.\n\
\n\
*** IMPORTANT NOTICE ***\n\
-On Windows, only sockets are supported; on Unix, all file descriptors.");
+On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");
static PyMethodDef select_methods[] = {
{"select", select_select, METH_VARARGS, select_doc},
@@ -682,7 +682,7 @@ PyDoc_STRVAR(module_doc,
"This module supports asynchronous I/O on multiple file descriptors.\n\
\n\
*** IMPORTANT NOTICE ***\n\
-On Windows, only sockets are supported; on Unix, all file descriptors.");
+On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");
PyMODINIT_FUNC
initselect(void)
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 262abe8..bb99bde 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -161,7 +161,8 @@ shutdown(how) -- shut down traffic in one or both directions\n\
(this includes the getaddrinfo emulation) protect access with a lock. */
#if defined(WITH_THREAD) && (defined(__APPLE__) || \
(defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \
- defined(__OpenBSD__) || defined(__NetBSD__) || !defined(HAVE_GETADDRINFO))
+ defined(__OpenBSD__) || defined(__NetBSD__) || \
+ defined(__VMS) || !defined(HAVE_GETADDRINFO))
#define USE_GETADDRINFO_LOCK
#endif
@@ -186,15 +187,8 @@ shutdown(how) -- shut down traffic in one or both directions\n\
#endif
#if defined(__VMS)
-#if ! defined(_SOCKADDR_LEN)
-# ifdef getaddrinfo
-# undef getaddrinfo
-# endif
-# include "TCPIP_IOCTL_ROUTINE"
-#else
# include <ioctl.h>
#endif
-#endif
#if defined(PYOS_OS2)
# define INCL_DOS
@@ -234,7 +228,9 @@ shutdown(how) -- shut down traffic in one or both directions\n\
#endif
/* Generic includes */
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
/* Generic socket object definitions and includes */
#define PySocket_BUILDING_SOCKET
@@ -270,7 +266,9 @@ int h_errno; /* not used */
#else
/* MS_WINDOWS includes */
-# include <fcntl.h>
+# ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+# endif
#endif
@@ -290,7 +288,7 @@ int h_errno; /* not used */
* _SS_ALIGNSIZE is defined in sys/socket.h by 6.5.21,
* for example, but not by 6.5.10.
*/
-#elif defined(_MSC_VER) && _MSC_VER>1200
+#elif defined(_MSC_VER) && _MSC_VER>1201
/* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and
* EAI_* constants are defined in (the already included) ws2tcpip.h.
*/
@@ -359,11 +357,6 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#define SOCKETCLOSE close
#endif
-#ifdef __VMS
-/* TCP/IP Services for VMS uses a maximum send/revc buffer length of 65535 */
-#define SEGMENT_SIZE 65535
-#endif
-
#if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)
#define USE_BLUETOOTH 1
#if defined(__FreeBSD__)
@@ -374,6 +367,14 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr)
#define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb)
#define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb)
+#elif defined(__NetBSD__)
+#define sockaddr_l2 sockaddr_bt
+#define sockaddr_rc sockaddr_bt
+#define sockaddr_sco sockaddr_bt
+#define _BT_SOCKADDR_MEMB(s, proto) &((s)->sock_addr)
+#define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb)
+#define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb)
+#define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb)
#else
#define _BT_SOCKADDR_MEMB(s, proto) (&((s)->sock_addr).bt_##proto)
#define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb)
@@ -382,6 +383,11 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#endif
#endif
+#ifdef __VMS
+/* TCP/IP Services for VMS uses a maximum send/recv buffer length */
+#define SEGMENT_SIZE (32 * 1024 -1)
+#endif
+
/*
* Constants for getnameinfo()
*/
@@ -413,14 +419,24 @@ static int taskwindow;
there has to be a circular reference. */
static PyTypeObject sock_type;
-/* Can we call select() with this socket without a buffer overrun? */
+#if defined(HAVE_POLL_H)
+#include <poll.h>
+#elif defined(HAVE_SYS_POLL_H)
+#include <sys/poll.h>
+#endif
+
#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
/* Platform can select file descriptors beyond FD_SETSIZE */
#define IS_SELECTABLE(s) 1
+#elif defined(HAVE_POLL)
+/* Instead of select(), we'll use poll() since poll() works on any fd. */
+#define IS_SELECTABLE(s) 1
+/* Can we call select() with this socket without a buffer overrun? */
#else
/* POSIX says selecting file descriptors beyond FD_SETSIZE
- has undefined behaviour. */
-#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE)
+ has undefined behaviour. If there's no timeout left, we don't have to
+ call select, so it's a safe, little white lie. */
+#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0)
#endif
static PyObject*
@@ -616,6 +632,30 @@ set_gaierror(int error)
return NULL;
}
+#ifdef __VMS
+/* Function to send in segments */
+static int
+sendsegmented(int sock_fd, char *buf, int len, int flags)
+{
+ int n = 0;
+ int remaining = len;
+
+ while (remaining > 0) {
+ unsigned int segment;
+
+ segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining);
+ n = send(sock_fd, buf, segment, flags);
+ if (n < 0) {
+ return n;
+ }
+ remaining -= segment;
+ buf += segment;
+ } /* end while */
+
+ return len;
+}
+#endif
+
/* Function to perform the setting of socket blocking mode
internally. block = (1 | 0). */
static int
@@ -640,8 +680,8 @@ internal_setblocking(PySocketSockObject *s, int block)
ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
#elif defined(__VMS)
block = !block;
- ioctl(s->sock_fd, FIONBIO, (char *)&block);
-#else /* !PYOS_OS2 && !_VMS */
+ ioctl(s->sock_fd, FIONBIO, (unsigned int *)&block);
+#else /* !PYOS_OS2 && !__VMS */
delay_flag = fcntl(s->sock_fd, F_GETFL, 0);
if (block)
delay_flag &= (~O_NONBLOCK);
@@ -664,16 +704,14 @@ internal_setblocking(PySocketSockObject *s, int block)
return 1;
}
-/* Do a select() on the socket, if necessary (sock_timeout > 0).
+/* Do a select()/poll() on the socket, if necessary (sock_timeout > 0).
The argument writing indicates the direction.
This does not raise an exception; we'll let our caller do that
after they've reacquired the interpreter lock.
- Returns 1 on timeout, 0 otherwise. */
+ Returns 1 on timeout, -1 on error, 0 otherwise. */
static int
internal_select(PySocketSockObject *s, int writing)
{
- fd_set fds;
- struct timeval tv;
int n;
/* Nothing to do unless we're in timeout mode (not non-blocking) */
@@ -684,17 +722,40 @@ internal_select(PySocketSockObject *s, int writing)
if (s->sock_fd < 0)
return 0;
- /* Construct the arguments to select */
- tv.tv_sec = (int)s->sock_timeout;
- tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
- FD_ZERO(&fds);
- FD_SET(s->sock_fd, &fds);
+ /* Prefer poll, if available, since you can poll() any fd
+ * which can't be done with select(). */
+#ifdef HAVE_POLL
+ {
+ struct pollfd pollfd;
+ int timeout;
- /* See if the socket is ready */
- if (writing)
- n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
- else
- n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
+ pollfd.fd = s->sock_fd;
+ pollfd.events = writing ? POLLOUT : POLLIN;
+
+ /* s->sock_timeout is in seconds, timeout in ms */
+ timeout = (int)(s->sock_timeout * 1000 + 0.5);
+ n = poll(&pollfd, 1, timeout);
+ }
+#else
+ {
+ /* Construct the arguments to select */
+ fd_set fds;
+ struct timeval tv;
+ tv.tv_sec = (int)s->sock_timeout;
+ tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
+ FD_ZERO(&fds);
+ FD_SET(s->sock_fd, &fds);
+
+ /* See if the socket is ready */
+ if (writing)
+ n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
+ else
+ n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
+ }
+#endif
+
+ if (n < 0)
+ return -1;
if (n == 0)
return 1;
return 0;
@@ -1494,7 +1555,7 @@ sock_accept(PySocketSockObject *s)
&addrlen);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
@@ -1721,6 +1782,8 @@ sock_getsockopt(PySocketSockObject *s, PyObject *args)
return PyInt_FromLong(flag);
}
#ifdef __VMS
+ /* socklen_t is unsigned so no negative test is needed,
+ test buflen == 0 is previously done */
if (buflen > 1024) {
#else
if (buflen <= 0 || buflen > 1024) {
@@ -1863,9 +1926,15 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
if (s->sock_timeout > 0.0) {
if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
timeout = internal_select(s, 1);
- res = connect(s->sock_fd, addr, addrlen);
- if (res < 0 && errno == EISCONN)
- res = 0;
+ if (timeout == 0) {
+ res = connect(s->sock_fd, addr, addrlen);
+ if (res < 0 && errno == EISCONN)
+ res = 0;
+ }
+ else if (timeout == -1)
+ res = errno; /* had error */
+ else
+ res = EWOULDBLOCK; /* timed out */
}
}
@@ -1895,7 +1964,7 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
res = internal_connect(s, addr, addrlen, &timeout);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
@@ -1929,6 +1998,13 @@ sock_connect_ex(PySocketSockObject *s, PyObject *addro)
res = internal_connect(s, addr, addrlen, &timeout);
Py_END_ALLOW_THREADS
+ /* Signals are not errors (though they may raise exceptions). Adapted
+ from PyErr_SetFromErrnoWithFilenameObject(). */
+#ifdef EINTR
+ if (res == EINTR && PyErr_CheckSignals())
+ return NULL;
+#endif
+
return PyInt_FromLong((long) res);
}
@@ -2149,10 +2225,10 @@ The mode and buffersize arguments are as for the built-in open() function.");
static ssize_t
sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
{
- ssize_t outlen = 0;
+ ssize_t outlen = -1;
int timeout;
#ifdef __VMS
- int remaining, nread;
+ int remaining;
char *read_buf;
#endif
@@ -2168,7 +2244,7 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
outlen = recv(s->sock_fd, cbuf, len, flags);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return -1;
}
@@ -2183,6 +2259,7 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
remaining = len;
while (remaining != 0) {
unsigned int segment;
+ int nread = -1;
segment = remaining /SEGMENT_SIZE;
if (segment != 0) {
@@ -2198,7 +2275,7 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
nread = recv(s->sock_fd, read_buf, segment, flags);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return -1;
}
@@ -2247,7 +2324,7 @@ sock_recv(PySocketSockObject *s, PyObject *args)
/* Call the guts */
outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags);
if (outlen < 0) {
- /* An error occured, release the string and return an
+ /* An error occurred, release the string and return an
error. */
Py_DECREF(buf);
return NULL;
@@ -2346,7 +2423,7 @@ sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags,
{
sock_addr_t addrbuf;
int timeout;
- ssize_t n = 0;
+ ssize_t n = -1;
socklen_t addrlen;
*addr = NULL;
@@ -2378,7 +2455,7 @@ sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags,
}
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return -1;
}
@@ -2493,10 +2570,7 @@ static PyObject *
sock_send(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = 0, flags = 0, timeout;
-#ifdef __VMS
- int send_length;
-#endif
+ int len, n = -1, flags = 0, timeout;
if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags))
return NULL;
@@ -2504,49 +2578,22 @@ sock_send(PySocketSockObject *s, PyObject *args)
if (!IS_SELECTABLE(s))
return select_error();
-#ifndef __VMS
Py_BEGIN_ALLOW_THREADS
timeout = internal_select(s, 1);
if (!timeout)
+#ifdef __VMS
+ n = sendsegmented(s->sock_fd, buf, len, flags);
+#else
n = send(s->sock_fd, buf, len, flags);
+#endif
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
if (n < 0)
return s->errorhandler();
-#else
- /* Divide packet into smaller segments for */
- /* TCP/IP Services for OpenVMS */
- send_length = len;
- while (send_length != 0) {
- unsigned int segment;
-
- segment = send_length / SEGMENT_SIZE;
- if (segment != 0) {
- segment = SEGMENT_SIZE;
- }
- else {
- segment = send_length;
- }
- Py_BEGIN_ALLOW_THREADS
- timeout = internal_select(s, 1);
- if (!timeout)
- n = send(s->sock_fd, buf, segment, flags);
- Py_END_ALLOW_THREADS
- if (timeout) {
- PyErr_SetString(socket_timeout, "timed out");
- return NULL;
- }
- if (n < 0) {
- return s->errorhandler();
- }
- send_length -= segment;
- buf += segment;
- } /* end while */
-#endif /* !__VMS */
return PyInt_FromLong((long)n);
}
@@ -2564,7 +2611,7 @@ static PyObject *
sock_sendall(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = 0, flags = 0, timeout;
+ int len, n = -1, flags = 0, timeout;
if (!PyArg_ParseTuple(args, "s#|i:sendall", &buf, &len, &flags))
return NULL;
@@ -2575,9 +2622,14 @@ sock_sendall(PySocketSockObject *s, PyObject *args)
Py_BEGIN_ALLOW_THREADS
do {
timeout = internal_select(s, 1);
+ n = -1;
if (timeout)
break;
+#ifdef __VMS
+ n = sendsegmented(s->sock_fd, buf, len, flags);
+#else
n = send(s->sock_fd, buf, len, flags);
+#endif
if (n < 0)
break;
buf += n;
@@ -2585,7 +2637,7 @@ sock_sendall(PySocketSockObject *s, PyObject *args)
} while (len > 0);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
@@ -2613,7 +2665,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
PyObject *addro;
char *buf;
struct sockaddr *addr;
- int addrlen, len, n = 0, flags, timeout;
+ int addrlen, len, n = -1, flags, timeout;
flags = 0;
if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
@@ -2635,7 +2687,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
n = sendto(s->sock_fd, buf, len, flags, addr, addrlen);
Py_END_ALLOW_THREADS
- if (timeout) {
+ if (timeout == 1) {
PyErr_SetString(socket_timeout, "timed out");
return NULL;
}
diff --git a/Modules/spwdmodule.c b/Modules/spwdmodule.c
index b7bf20e..d3f309a 100644
--- a/Modules/spwdmodule.c
+++ b/Modules/spwdmodule.c
@@ -91,7 +91,7 @@ static PyObject *mkspent(struct spwd *p)
#undef SETI
if (PyErr_Occurred()) {
- Py_XDECREF(v);
+ Py_DECREF(v);
return NULL;
}
diff --git a/Modules/sre.h b/Modules/sre.h
index b07d210..d4af05c 100644
--- a/Modules/sre.h
+++ b/Modules/sre.h
@@ -23,7 +23,7 @@
typedef struct {
PyObject_VAR_HEAD
- int groups; /* must be first! */
+ Py_ssize_t groups; /* must be first! */
PyObject* groupindex;
PyObject* indexgroup;
/* compatibility */
@@ -31,7 +31,7 @@ typedef struct {
int flags; /* flags used when compiling pattern source */
PyObject *weakreflist; /* List of weak references */
/* pattern code */
- int codesize;
+ Py_ssize_t codesize;
SRE_CODE code[1];
} PatternObject;
@@ -42,10 +42,10 @@ typedef struct {
PyObject* string; /* link to the target string (must be first) */
PyObject* regs; /* cached list of matching spans */
PatternObject* pattern; /* link to the regex (pattern) object */
- int pos, endpos; /* current target slice */
- int lastindex; /* last index marker seen by the engine (-1 if none) */
- int groups; /* number of groups (start/end marks) */
- int mark[1];
+ Py_ssize_t pos, endpos; /* current target slice */
+ Py_ssize_t lastindex; /* last index marker seen by the engine (-1 if none) */
+ Py_ssize_t groups; /* number of groups (start/end marks) */
+ Py_ssize_t mark[1];
} MatchObject;
typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
@@ -54,7 +54,7 @@ typedef unsigned int (*SRE_TOLOWER_HOOK)(unsigned int ch);
#define SRE_MARK_SIZE 200
typedef struct SRE_REPEAT_T {
- int count;
+ Py_ssize_t count;
SRE_CODE* pattern; /* points to REPEAT operator arguments */
void* last_ptr; /* helper to check for infinite loops */
struct SRE_REPEAT_T *prev; /* points to previous repeat context */
@@ -68,17 +68,17 @@ typedef struct {
void* end; /* end of original string */
/* attributes for the match object */
PyObject* string;
- int pos, endpos;
+ Py_ssize_t pos, endpos;
/* character size */
int charsize;
/* registers */
- int lastindex;
- int lastmark;
+ Py_ssize_t lastindex;
+ Py_ssize_t lastmark;
void* mark[SRE_MARK_SIZE];
/* dynamically allocated stuff */
char* data_stack;
- unsigned int data_stack_size;
- unsigned int data_stack_base;
+ size_t data_stack_size;
+ size_t data_stack_base;
/* current repeat context */
SRE_REPEAT *repeat;
/* hooks */
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 6169658..448b11c 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -586,6 +586,60 @@ allocated consecutive numbers starting at 1, this behavior should not\n\
be relied upon, and the number should be seen purely as a magic cookie.\n\
A thread's identity may be reused for another thread after it exits.");
+static PyObject *
+thread_stack_size(PyObject *self, PyObject *args)
+{
+ size_t old_size;
+ Py_ssize_t new_size = 0;
+ int rc;
+
+ if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size))
+ return NULL;
+
+ if (new_size < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "size must be 0 or a positive value");
+ return NULL;
+ }
+
+ old_size = PyThread_get_stacksize();
+
+ rc = PyThread_set_stacksize((size_t) new_size);
+ if (rc == -1) {
+ PyErr_Format(PyExc_ValueError,
+ "size not valid: %zd bytes",
+ new_size);
+ return NULL;
+ }
+ if (rc == -2) {
+ PyErr_SetString(ThreadError,
+ "setting stack size not supported");
+ return NULL;
+ }
+
+ return PyInt_FromSsize_t((Py_ssize_t) old_size);
+}
+
+PyDoc_STRVAR(stack_size_doc,
+"stack_size([size]) -> size\n\
+\n\
+Return the thread stack size used when creating new threads. The\n\
+optional size argument specifies the stack size (in bytes) to be used\n\
+for subsequently created threads, and must be 0 (use platform or\n\
+configured default) or a positive integer value of at least 32,768 (32k).\n\
+If changing the thread stack size is unsupported, a ThreadError\n\
+exception is raised. If the specified size is invalid, a ValueError\n\
+exception is raised, and the stack size is unmodified. 32k bytes\n\
+ currently the minimum supported stack size value to guarantee\n\
+sufficient stack space for the interpreter itself.\n\
+\n\
+Note that some platforms may have particular restrictions on values for\n\
+the stack size, such as requiring a minimum stack size larger than 32kB or\n\
+requiring allocation in multiples of the system memory page size\n\
+- platform documentation should be referred to for more information\n\
+(4kB pages are common; using multiples of 4096 for the stack size is\n\
+the suggested approach in the absence of more specific information).");
+
static PyMethodDef thread_methods[] = {
{"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread,
METH_VARARGS,
@@ -605,6 +659,9 @@ static PyMethodDef thread_methods[] = {
METH_NOARGS, interrupt_doc},
{"get_ident", (PyCFunction)thread_get_ident,
METH_NOARGS, get_ident_doc},
+ {"stack_size", (PyCFunction)thread_stack_size,
+ METH_VARARGS,
+ stack_size_doc},
#ifndef NO_EXIT_PROG
{"exit_prog", (PyCFunction)thread_PyThread_exit_prog,
METH_VARARGS},
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 87e543f..444b739 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -19,7 +19,9 @@
#include <ctype.h>
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
#ifdef QUICKWIN
#include <io.h>
@@ -404,13 +406,35 @@ time_strftime(PyObject *self, PyObject *args)
indexing blindly into some array for a textual representation
by some bad index (fixes bug #897625).
- No check for year since handled in gettmarg().
+ Also support values of zero from Python code for arguments in which
+ that is out of range by forcing that value to the lowest value that
+ is valid (fixed bug #1520914).
+
+ Valid ranges based on what is allowed in struct tm:
+
+ - tm_year: [0, max(int)] (1)
+ - tm_mon: [0, 11] (2)
+ - tm_mday: [1, 31]
+ - tm_hour: [0, 23]
+ - tm_min: [0, 59]
+ - tm_sec: [0, 60]
+ - tm_wday: [0, 6] (1)
+ - tm_yday: [0, 365] (2)
+ - tm_isdst: [-max(int), max(int)]
+
+ (1) gettmarg() handles bounds-checking.
+ (2) Python's acceptable range is one greater than the range in C,
+ thus need to check against automatic decrement by gettmarg().
*/
- if (buf.tm_mon < 0 || buf.tm_mon > 11) {
+ if (buf.tm_mon == -1)
+ buf.tm_mon = 0;
+ else if (buf.tm_mon < 0 || buf.tm_mon > 11) {
PyErr_SetString(PyExc_ValueError, "month out of range");
return NULL;
}
- if (buf.tm_mday < 1 || buf.tm_mday > 31) {
+ if (buf.tm_mday == 0)
+ buf.tm_mday = 1;
+ else if (buf.tm_mday < 0 || buf.tm_mday > 31) {
PyErr_SetString(PyExc_ValueError, "day of month out of range");
return NULL;
}
@@ -432,7 +456,9 @@ time_strftime(PyObject *self, PyObject *args)
PyErr_SetString(PyExc_ValueError, "day of week out of range");
return NULL;
}
- if (buf.tm_yday < 0 || buf.tm_yday > 365) {
+ if (buf.tm_yday == -1)
+ buf.tm_yday = 0;
+ else if (buf.tm_yday < 0 || buf.tm_yday > 365) {
PyErr_SetString(PyExc_ValueError, "day of year out of range");
return NULL;
}
@@ -465,6 +491,14 @@ time_strftime(PyObject *self, PyObject *args)
return ret;
}
free(outbuf);
+#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
+ /* VisualStudio .NET 2005 does this properly */
+ if (buflen == 0 && errno == EINVAL) {
+ PyErr_SetString(PyExc_ValueError, "Invalid format string");
+ return 0;
+ }
+#endif
+
}
}
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 0660353..1b0be28 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -395,6 +395,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
PyUnicodeObject *v;
char decomp[256];
int code, index, count, i;
+ unsigned int prefix_index;
if (!PyArg_ParseTuple(args, "O!:decomposition",
&PyUnicode_Type, &v))
@@ -428,9 +429,15 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
/* XXX: could allocate the PyString up front instead
(strlen(prefix) + 5 * count + 1 bytes) */
+ /* Based on how index is calculated above and decomp_data is generated
+ from Tools/unicode/makeunicodedata.py, it should not be possible
+ to overflow decomp_prefix. */
+ prefix_index = decomp_data[index] & 255;
+ assert(prefix_index < (sizeof(decomp_prefix)/sizeof(*decomp_prefix)));
+
/* copy prefix */
- i = strlen(decomp_prefix[decomp_data[index] & 255]);
- memcpy(decomp, decomp_prefix[decomp_data[index] & 255], i);
+ i = strlen(decomp_prefix[prefix_index]);
+ memcpy(decomp, decomp_prefix[prefix_index], i);
while (count-- > 0) {
if (i)
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 06b0690..da31e8b 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -653,6 +653,7 @@ PyZlib_flush(compobject *self, PyObject *args)
return RetVal;
}
+#ifdef HAVE_ZLIB_COPY
PyDoc_STRVAR(comp_copy__doc__,
"copy() -- Return a copy of the compression object.");
@@ -754,6 +755,7 @@ error:
Py_XDECREF(retval);
return NULL;
}
+#endif
PyDoc_STRVAR(decomp_flush__doc__,
"flush( [length] ) -- Return a string containing any remaining\n"
@@ -827,8 +829,10 @@ static PyMethodDef comp_methods[] =
comp_compress__doc__},
{"flush", (binaryfunc)PyZlib_flush, METH_VARARGS,
comp_flush__doc__},
+#ifdef HAVE_ZLIB_COPY
{"copy", (PyCFunction)PyZlib_copy, METH_NOARGS,
comp_copy__doc__},
+#endif
{NULL, NULL}
};
@@ -838,8 +842,10 @@ static PyMethodDef Decomp_methods[] =
decomp_decompress__doc__},
{"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS,
decomp_flush__doc__},
+#ifdef HAVE_ZLIB_COPY
{"copy", (PyCFunction)PyZlib_uncopy, METH_NOARGS,
decomp_copy__doc__},
+#endif
{NULL, NULL}
};