Skip to content

Instantly share code, notes, and snippets.

@qunaibit
Last active June 4, 2022 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qunaibit/c9b7c8a8637c84ce30dd33a107b94b0b to your computer and use it in GitHub Desktop.
Save qunaibit/c9b7c8a8637c84ce30dd33a107b94b0b to your computer and use it in GitHub Desktop.
HPy arg parser
// src/tri/_tri_wrapper.cpp
static HPy PyTriangulation_calculate_plane_coefficients(
     HPyContext *ctx, HPy h_self, HPy* args, HPy_ssize_t nargs, HPy kwds)
{
     Triangulation::CoordinateArray z;
+    PyTriangulation* self = PyTriangulation_AsStruct(ctx, h_self);
+    HPy h_z;
+    if (!HPyArg_Parse(ctx, NULL, args, nargs, "O:calculate_plane_coefficients", &h_z)) {
+        return HPy_NULL;
+    }
+    if (!z.converter(HPy_AsPyObject(ctx, h_z), &z)) {
         ...
+        return HPy_NULL;
+    }
-    if (!PyArg_ParseTuple(args, "O&:calculate_plane_coefficients",
-                          &z.converter, &z)) {
-        return NULL;
-    }    
    ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment