Commit 4c9dfc86 authored by Thomas Heller's avatar Thomas Heller

Fixes from Neal Norwitz, plus other small fixes.

parent 12755163
...@@ -285,6 +285,7 @@ CDataType_from_param(PyObject *type, PyObject *value) ...@@ -285,6 +285,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
if (PyCArg_CheckExact(value)) { if (PyCArg_CheckExact(value)) {
PyCArgObject *p = (PyCArgObject *)value; PyCArgObject *p = (PyCArgObject *)value;
PyObject *ob = p->obj; PyObject *ob = p->obj;
const char *ob_name;
StgDictObject *dict; StgDictObject *dict;
dict = PyType_stgdict(type); dict = PyType_stgdict(type);
...@@ -296,10 +297,10 @@ CDataType_from_param(PyObject *type, PyObject *value) ...@@ -296,10 +297,10 @@ CDataType_from_param(PyObject *type, PyObject *value)
Py_INCREF(value); Py_INCREF(value);
return value; return value;
} }
ob_name = (ob) ? ob->ob_type->tp_name : "???";
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"expected %s instance instead of pointer to %s", "expected %s instance instead of pointer to %s",
((PyTypeObject *)type)->tp_name, ((PyTypeObject *)type)->tp_name, ob_name);
ob->ob_type->tp_name);
return NULL; return NULL;
} }
#if 1 #if 1
...@@ -506,12 +507,12 @@ size property/method, and the sequence protocol. ...@@ -506,12 +507,12 @@ size property/method, and the sequence protocol.
static int static int
PointerType_SetProto(StgDictObject *stgdict, PyObject *proto) PointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
{ {
if (proto && !PyType_Check(proto)) { if (!proto || !PyType_Check(proto)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"_type_ must be a type"); "_type_ must be a type");
return -1; return -1;
} }
if (proto && !PyType_stgdict(proto)) { if (!PyType_stgdict(proto)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"_type_ must have storage info"); "_type_ must have storage info");
return -1; return -1;
...@@ -1264,10 +1265,14 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject ...@@ -1264,10 +1265,14 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
PyTypeObject *result; PyTypeObject *result;
StgDictObject *stgdict; StgDictObject *stgdict;
PyObject *name = PyTuple_GET_ITEM(args, 0); PyObject *name = PyTuple_GET_ITEM(args, 0);
PyObject *swapped_args = PyTuple_New(PyTuple_GET_SIZE(args)); PyObject *swapped_args;
static PyObject *suffix; static PyObject *suffix;
int i; int i;
swapped_args = PyTuple_New(PyTuple_GET_SIZE(args));
if (!swapped_args)
return NULL;
if (suffix == NULL) if (suffix == NULL)
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
suffix = PyString_FromString("_le"); suffix = PyString_FromString("_le");
...@@ -2781,7 +2786,7 @@ _get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject * ...@@ -2781,7 +2786,7 @@ _get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject *
static PyObject * static PyObject *
_build_callargs(CFuncPtrObject *self, PyObject *argtypes, _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
PyObject *inargs, PyObject *kwds, PyObject *inargs, PyObject *kwds,
int *poutmask, int *pinoutmask, int *pnumretvals) int *poutmask, int *pinoutmask, unsigned int *pnumretvals)
{ {
PyObject *paramflags = self->paramflags; PyObject *paramflags = self->paramflags;
PyObject *callargs; PyObject *callargs;
...@@ -2836,6 +2841,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes, ...@@ -2836,6 +2841,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) { switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
case PARAMFLAG_FIN | PARAMFLAG_FLCID: case PARAMFLAG_FIN | PARAMFLAG_FLCID:
/* ['in', 'lcid'] parameter. Always taken from defval */ /* ['in', 'lcid'] parameter. Always taken from defval */
assert(defval);
Py_INCREF(defval); Py_INCREF(defval);
PyTuple_SET_ITEM(callargs, i, defval); PyTuple_SET_ITEM(callargs, i, defval);
break; break;
...@@ -2939,9 +2945,10 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes, ...@@ -2939,9 +2945,10 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
*/ */
static PyObject * static PyObject *
_build_result(PyObject *result, PyObject *callargs, _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; PyObject *tup = NULL;
if (callargs == NULL) if (callargs == NULL)
...@@ -2952,6 +2959,7 @@ _build_result(PyObject *result, PyObject *callargs, ...@@ -2952,6 +2959,7 @@ _build_result(PyObject *result, PyObject *callargs,
} }
Py_DECREF(result); Py_DECREF(result);
/* tup will not be allocated if numretvals == 1 */
/* allocate tuple to hold the result */ /* allocate tuple to hold the result */
if (numretvals > 1) { if (numretvals > 1) {
tup = PyTuple_New(numretvals); tup = PyTuple_New(numretvals);
...@@ -3275,6 +3283,8 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -3275,6 +3283,8 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
if (!fields) { if (!fields) {
PyErr_Clear(); PyErr_Clear();
fields = PyTuple_New(0); fields = PyTuple_New(0);
if (!fields)
return -1;
} }
if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) { if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment