diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2010-04-26 01:02:04 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2010-04-26 01:02:04 +0000 |
commit | 22ee215bf2c34d7ec66901083cd94dc67fe26e4f (patch) | |
tree | 8557c2741e8d0ffd02068a1b994f6215271bcc3d /numpy | |
parent | e0457991ee4a8b9c6272baa97afe49f5be93c2bf (diff) | |
download | numpy-22ee215bf2c34d7ec66901083cd94dc67fe26e4f.tar.gz |
ENH: Add NpyArg_ParseKeywords helper function.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/methods.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index 5dd555be5..f09856c55 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -1,4 +1,5 @@ #define PY_SSIZE_T_CLEAN +#include <stdarg.h> #include <Python.h> #include "structmember.h" @@ -17,6 +18,32 @@ #include "methods.h" + +/* NpyArg_ParseKeywords + * + * Utility function that provides the keyword parsing functionality of + * PyArg_ParseTupleAndKeywords without having to have an args argument. + * + */ +static int +NpyArg_ParseKeywords(PyObject *keys, const char *format, char **kwlist, ...) +{ + PyObject *args = PyTuple_New(0); + int ret; + va_list va; + + if (args == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "Failed to allocate new tuple"); + return 0; + } + va_start(va, kwlist); + ret = PyArg_VaParseTupleAndKeywords(args, keys, format, kwlist, va); + va_end(va); + Py_DECREF(args); + return ret; +} + /* Should only be used if x is known to be an nd-array */ #define _ARET(x) PyArray_Return((PyArrayObject *)(x)) |