martinzink commented on code in PR #1504:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1504#discussion_r1116681549


##########
extensions/python/types/PyProcessContext.cpp:
##########
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+a * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "PyProcessContext.h"
+#include <string>
+#include "PyException.h"
+
+extern "C" {
+namespace org::apache::nifi::minifi::extensions::python {
+
+static PyMethodDef PyProcessContext_methods[] = {
+    {"getProperty", (PyCFunction) PyProcessContext::getProperty, METH_VARARGS, 
nullptr},
+    {}  /* Sentinel */
+};
+
+static PyType_Slot PyProcessContextTypeSpecSlots[] = {
+    {Py_tp_dealloc, 
reinterpret_cast<void*>(pythonAllocatedInstanceDealloc<PyProcessContext>)},
+    {Py_tp_init, reinterpret_cast<void*>(PyProcessContext::init)},
+    {Py_tp_methods, reinterpret_cast<void*>(PyProcessContext_methods)},
+    {Py_tp_new, 
reinterpret_cast<void*>(newPythonAllocatedInstance<PyProcessContext>)},
+    {}  /* Sentinel */
+};
+
+static PyType_Spec PyProcessContextTypeSpec{
+    .name = "minifi_native.ProcessContext",
+    .basicsize = sizeof(PyProcessContext),
+    .itemsize = 0,
+    .flags = Py_TPFLAGS_DEFAULT,
+    .slots = PyProcessContextTypeSpecSlots
+};
+
+int PyProcessContext::init(PyProcessContext* self, PyObject* args, PyObject*) {
+  PyObject* weak_ptr_capsule = nullptr;
+  if (!PyArg_ParseTuple(args, "O", &weak_ptr_capsule)) {
+    return -1;
+  }
+
+  auto process_context = 
static_cast<HeldType*>(PyCapsule_GetPointer(weak_ptr_capsule, nullptr));

Review Comment:
   Good idea, I've changed the Capsule handling to include a name and also to 
check if 
   it failed for some reason in 
https://github.com/apache/nifi-minifi-cpp/pull/1504/commits/76a40cf9f22aa9bd8481733dc6705b4be48ac06b
   
   For the other suggestion: the 4 parameter variant type checking only works 
for PyTypeObjects, and if I am not mistaken it is already used everywhere where 
it is applicable. A lot of the code uses simply capsule-wraped C types, so 
there is nothing we can check there (besides the name, which you recommended)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to