summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-03-16 19:26:21 (GMT)
committerThomas Heller <theller@ctypes.org>2006-03-16 19:26:21 (GMT)
commit4c9dfc86f3babfb8ae3d4931c8e5572fab21afc2 (patch)
tree09deba144391bcc50f5bcb5bbd6ac9cb62677738 /Modules
parent127551637bc65d0e268aad10d65c48147ae566e8 (diff)
downloadcpython-4c9dfc86f3babfb8ae3d4931c8e5572fab21afc2.zip
cpython-4c9dfc86f3babfb8ae3d4931c8e5572fab21afc2.tar.gz
cpython-4c9dfc86f3babfb8ae3d4931c8e5572fab21afc2.tar.bz2
Fixes from Neal Norwitz, plus other small fixes.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 47890df..c916c75 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -285,6 +285,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
if (PyCArg_CheckExact(value)) {
PyCArgObject *p = (PyCArgObject *)value;
PyObject *ob = p->obj;
+ const char *ob_name;
StgDictObject *dict;
dict = PyType_stgdict(type);
@@ -296,10 +297,10 @@ CDataType_from_param(PyObject *type, PyObject *value)
Py_INCREF(value);
return value;
}
+ ob_name = (ob) ? ob->ob_type->tp_name : "???";
PyErr_Format(PyExc_TypeError,
"expected %s instance instead of pointer to %s",
- ((PyTypeObject *)type)->tp_name,
- ob->ob_type->tp_name);
+ ((PyTypeObject *)type)->tp_name, ob_name);
return NULL;
}
#if 1
@@ -506,12 +507,12 @@ size property/method, and the sequence protocol.
static int
PointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
{
- if (proto && !PyType_Check(proto)) {
+ if (!proto || !PyType_Check(proto)) {
PyErr_SetString(PyExc_TypeError,
"_type_ must be a type");
return -1;
}
- if (proto && !PyType_stgdict(proto)) {
+ if (!PyType_stgdict(proto)) {
PyErr_SetString(PyExc_TypeError,
"_type_ must have storage info");
return -1;
@@ -1264,10 +1265,14 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
PyTypeObject *result;
StgDictObject *stgdict;
PyObject *name = PyTuple_GET_ITEM(args, 0);
- PyObject *swapped_args = PyTuple_New(PyTuple_GET_SIZE(args));
+ PyObject *swapped_args;
static PyObject *suffix;
int i;
+ swapped_args = PyTuple_New(PyTuple_GET_SIZE(args));
+ if (!swapped_args)
+ return NULL;
+
if (suffix == NULL)
#ifdef WORDS_BIGENDIAN
suffix = PyString_FromString("_le");
@@ -2781,7 +2786,7 @@ _get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject *
static PyObject *
_build_callargs(CFuncPtrObject *self, PyObject *argtypes,
PyObject *inargs, PyObject *kwds,
- int *poutmask, int *pinoutmask, int *pnumretvals)
+ int *poutmask, int *pinoutmask, unsigned int *pnumretvals)
{
PyObject *paramflags = self->paramflags;
PyObject *callargs;
@@ -2836,6 +2841,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
case PARAMFLAG_FIN | PARAMFLAG_FLCID:
/* ['in', 'lcid'] parameter. Always taken from defval */
+ assert(defval);
Py_INCREF(defval);
PyTuple_SET_ITEM(callargs, i, defval);
break;
@@ -2939,9 +2945,10 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
*/
static PyObject *
_build_result(PyObject *result, PyObject *callargs,
- int outmask, int inoutmask, int numretvals)
+ int outmask, int inoutmask, unsigned int numretvals)
{
- int i, index, bit;
+ unsigned int i, index;
+ int bit;
PyObject *tup = NULL;
if (callargs == NULL)
@@ -2952,6 +2959,7 @@ _build_result(PyObject *result, PyObject *callargs,
}
Py_DECREF(result);
+ /* tup will not be allocated if numretvals == 1 */
/* allocate tuple to hold the result */
if (numretvals > 1) {
tup = PyTuple_New(numretvals);
@@ -3275,6 +3283,8 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
if (!fields) {
PyErr_Clear();
fields = PyTuple_New(0);
+ if (!fields)
+ return -1;
}
if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) {