lordgamez commented on code in PR #1863: URL: https://github.com/apache/nifi-minifi-cpp/pull/1863#discussion_r1775091943
########## extensions/python/types/PyRecordSetReader.cpp: ########## @@ -0,0 +1,110 @@ +/** + * 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 "PyRecordSetReader.h" +#include "rapidjson/writer.h" +#include "rapidjson/stream.h" + +#include "PyProcessSession.h" +#include "PyScriptFlowFile.h" + +extern "C" { +namespace org::apache::nifi::minifi::extensions::python { + +static PyMethodDef PyRecordSetReader_methods[] = { // NOLINT(cppcoreguidelines-avoid-c-arrays) + {"read", (PyCFunction) PyRecordSetReader::read, METH_VARARGS, nullptr}, + {} /* Sentinel */ +}; + +static PyType_Slot PyRecordSetReaderTypeSpecSlots[] = { // NOLINT(cppcoreguidelines-avoid-c-arrays) + {Py_tp_dealloc, reinterpret_cast<void*>(pythonAllocatedInstanceDealloc<PyRecordSetReader>)}, + {Py_tp_init, reinterpret_cast<void*>(PyRecordSetReader::init)}, + {Py_tp_methods, reinterpret_cast<void*>(PyRecordSetReader_methods)}, + {Py_tp_new, reinterpret_cast<void*>(newPythonAllocatedInstance<PyRecordSetReader>)}, + {} /* Sentinel */ +}; + +static PyType_Spec PyRecordSetReaderTypeSpec{ + .name = "minifi_native.RecordSetReader", + .basicsize = sizeof(PyRecordSetReader), + .itemsize = 0, + .flags = Py_TPFLAGS_DEFAULT, + .slots = PyRecordSetReaderTypeSpecSlots +}; + +int PyRecordSetReader::init(PyRecordSetReader* self, PyObject* args, PyObject*) { Review Comment: It doesn't seem to be possible to use references due to the python C API only provides pointers for these methods. As I checked if the methods are bound to an object the self should never be null and the args parameter should always contain a value as it is passed as a tuple even if the tuple is empty. But in edge cases like memory corruption it could happen that these result in null values so it doesn't hurt to check them anyway, so I added the checks in 1366b3b397a13faa54769543083ff9b46290ebf7 -- 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]
