Commit 3457e4bd authored by Thomas Heller's avatar Thomas Heller

New support functions for test_getargs2.

Theres now a separate function for each of the format codes
b, B, H, I, k, i, l, L, K.
parent 0eadaac7
...@@ -294,94 +294,89 @@ test_L_code(PyObject *self) ...@@ -294,94 +294,89 @@ test_L_code(PyObject *self)
#endif /* ifdef HAVE_LONG_LONG */ #endif /* ifdef HAVE_LONG_LONG */
/* Call PyArg_ParseTuple, and return the result as unsigned long */ /* Functions to call PyArg_ParseTuple with integer format codes,
and return the result.
*/
static PyObject * static PyObject *
getargs_ul(PyObject *self, PyObject *args) getargs_b(PyObject *self, PyObject *args)
{ {
PyObject *ob, *result = NULL, *argtuple; unsigned char value;
char *fmt; if (!PyArg_ParseTuple(args, "b", &value))
unsigned long value = 0; return NULL;
return PyLong_FromUnsignedLong((unsigned long)value);
}
if (!PyArg_ParseTuple(args, "sO", &fmt, &ob)) static PyObject *
getargs_B(PyObject *self, PyObject *args)
{
unsigned char value;
if (!PyArg_ParseTuple(args, "B", &value))
return NULL; return NULL;
argtuple = PyTuple_New(1); return PyLong_FromUnsignedLong((unsigned long)value);
Py_INCREF(ob);
PyTuple_SET_ITEM(argtuple, 0, ob);
if (PyArg_ParseTuple(argtuple, fmt, &value))
result = PyLong_FromUnsignedLong(value);
Py_DECREF(argtuple);
return result;
} }
/* Call PyArg_ParseTuple, and return the result as signed long */
static PyObject * static PyObject *
getargs_l(PyObject *self, PyObject *args) getargs_H(PyObject *self, PyObject *args)
{ {
PyObject *ob, *result = NULL, *argtuple; unsigned short value;
char *fmt; if (!PyArg_ParseTuple(args, "H", &value))
return NULL;
return PyLong_FromUnsignedLong((unsigned long)value);
}
if (!PyArg_ParseTuple(args, "sO", &fmt, &ob)) static PyObject *
getargs_I(PyObject *self, PyObject *args)
{
unsigned int value;
if (!PyArg_ParseTuple(args, "I", &value))
return NULL; return NULL;
argtuple = PyTuple_New(1); return PyLong_FromUnsignedLong((unsigned long)value);
Py_INCREF(ob); }
PyTuple_SET_ITEM(argtuple, 0, ob);
/* It's necessary to distinguish between ints and longs, since static PyObject *
sizeof(int) != sizeof(long) on some (64 bit) platforms. getargs_k(PyObject *self, PyObject *args)
value must be an int for: PyArg_ParseTuple(t, 'i', &value) {
value must be an long for: PyArg_ParseTuple(t, 'l', &value) unsigned long value;
*/ if (!PyArg_ParseTuple(args, "k", &value))
if (*fmt == 'i') { return NULL;
return PyLong_FromUnsignedLong(value);
}
static PyObject *
getargs_i(PyObject *self, PyObject *args)
{
int value; int value;
if (PyArg_ParseTuple(argtuple, fmt, &value)) if (!PyArg_ParseTuple(args, "i", &value))
result = PyLong_FromLong(value); return NULL;
} else if (*fmt == 'l') { return PyLong_FromLong((long)value);
}
static PyObject *
getargs_l(PyObject *self, PyObject *args)
{
long value; long value;
if (PyArg_ParseTuple(argtuple, fmt, &value)) if (!PyArg_ParseTuple(args, "l", &value))
result = PyLong_FromLong(value); return NULL;
} else { return PyLong_FromLong(value);
PyErr_SetString(PyExc_TypeError, "format was not i or l");
}
Py_DECREF(argtuple);
return result;
} }
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
/* Call PyArg_ParseTuple, and return the result as signed long long */
static PyObject * static PyObject *
getargs_ll(PyObject *self, PyObject *args) getargs_L(PyObject *self, PyObject *args)
{ {
PyObject *ob, *result = NULL, *argtuple; PY_LONG_LONG value;
char *fmt; if (!PyArg_ParseTuple(args, "L", &value))
PY_LONG_LONG value = 0;
if (!PyArg_ParseTuple(args, "sO", &fmt, &ob))
return NULL; return NULL;
argtuple = PyTuple_New(1); return PyLong_FromLongLong(value);
Py_INCREF(ob);
PyTuple_SET_ITEM(argtuple, 0, ob);
if (PyArg_ParseTuple(argtuple, fmt, &value))
result = PyLong_FromLongLong(value);
Py_DECREF(argtuple);
return result;
} }
/* Call PyArg_ParseTuple, and return the result as unsigned long long */
static PyObject * static PyObject *
getargs_ull(PyObject *self, PyObject *args) getargs_K(PyObject *self, PyObject *args)
{ {
PyObject *ob, *result = NULL, *argtuple; unsigned PY_LONG_LONG value;
char *fmt; if (!PyArg_ParseTuple(args, "K", &value))
unsigned PY_LONG_LONG value = 0;
if (!PyArg_ParseTuple(args, "sO", &fmt, &ob))
return NULL; return NULL;
argtuple = PyTuple_New(1); return PyLong_FromUnsignedLongLong(value);
Py_INCREF(ob);
PyTuple_SET_ITEM(argtuple, 0, ob);
if (PyArg_ParseTuple(argtuple, fmt, &value))
result = PyLong_FromUnsignedLongLong(value);
Py_DECREF(argtuple);
return result;
} }
#endif #endif
...@@ -600,11 +595,17 @@ static PyMethodDef TestMethods[] = { ...@@ -600,11 +595,17 @@ static PyMethodDef TestMethods[] = {
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
{"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS},
{"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS},
{"getargs_ul", (PyCFunction)getargs_ul, METH_VARARGS},
{"getargs_b", (PyCFunction)getargs_b, METH_VARARGS},
{"getargs_B", (PyCFunction)getargs_B, METH_VARARGS},
{"getargs_H", (PyCFunction)getargs_H, METH_VARARGS},
{"getargs_I", (PyCFunction)getargs_I, METH_VARARGS},
{"getargs_k", (PyCFunction)getargs_k, METH_VARARGS},
{"getargs_i", (PyCFunction)getargs_i, METH_VARARGS},
{"getargs_l", (PyCFunction)getargs_l, METH_VARARGS}, {"getargs_l", (PyCFunction)getargs_l, METH_VARARGS},
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
{"getargs_ll", (PyCFunction)getargs_ll, METH_VARARGS}, {"getargs_L", (PyCFunction)getargs_L, METH_VARARGS},
{"getargs_ull", (PyCFunction)getargs_ull, METH_VARARGS}, {"getargs_K", (PyCFunction)getargs_K, METH_VARARGS},
{"test_longlong_api", (PyCFunction)test_longlong_api, METH_NOARGS}, {"test_longlong_api", (PyCFunction)test_longlong_api, METH_NOARGS},
{"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
#endif #endif
......
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