[Numpy-svn] r8365 - trunk/numpy/core/src/multiarray
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Apr 25 21:02:04 EDT 2010
Author: charris
Date: 2010-04-25 20:02:04 -0500 (Sun, 25 Apr 2010)
New Revision: 8365
Modified:
trunk/numpy/core/src/multiarray/methods.c
Log:
ENH: Add NpyArg_ParseKeywords helper function.
Modified: trunk/numpy/core/src/multiarray/methods.c
===================================================================
--- trunk/numpy/core/src/multiarray/methods.c 2010-04-25 17:26:08 UTC (rev 8364)
+++ trunk/numpy/core/src/multiarray/methods.c 2010-04-26 01:02:04 UTC (rev 8365)
@@ -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))
More information about the Numpy-svn
mailing list