comparison python/pydc/pydc.c @ 60:8e905c0798c7

- p2Z() helper func - import fix for test code avoiding potential circular import
author Tassilo Philipp
date Wed, 03 Aug 2022 15:38:07 +0200
parents 2725de59454a
children c5a69c454963
comparison
equal deleted inserted replaced
59:2725de59454a 60:8e905c0798c7
731 731
732 Py_RETURN_NONE; 732 Py_RETURN_NONE;
733 } 733 }
734 734
735 735
736 /* helper creating a string from a pointer handle (Py_ssize_t, must point to
737 * string data); this makes it easier to use C functions that allocate memory,
738 * retrieve the handle via 'p' in order to call free() on it later, and get the
739 * string it points to
740 */
741 static PyObject*
742 pydc_p2Z(PyObject* self, PyObject* args)
743 {
744 size_t p;
745 if(PyArg_ParseTuple(args, "n", &p))
746 return Py_BuildValue("s", (const char*)p);
747
748 Py_RETURN_NONE;
749 }
736 750
737 751
738 // module deinit 752 // module deinit
739 static void deinit_pydc(void* x) 753 static void deinit_pydc(void* x)
740 { 754 {
770 {"free", pydc_free, METH_VARARGS, "free library" }, 784 {"free", pydc_free, METH_VARARGS, "free library" },
771 {"get_path", pydc_get_path, METH_VARARGS, "get library path" }, 785 {"get_path", pydc_get_path, METH_VARARGS, "get library path" },
772 {"call", pydc_call, METH_VARARGS, "call function" }, 786 {"call", pydc_call, METH_VARARGS, "call function" },
773 {"new_callback", pydc_new_callback, METH_VARARGS, "new callback obj" }, // @@@ doc: only functions, not every callable, and only with positional args 787 {"new_callback", pydc_new_callback, METH_VARARGS, "new callback obj" }, // @@@ doc: only functions, not every callable, and only with positional args
774 {"free_callback", pydc_free_callback, METH_VARARGS, "free callback obj"}, 788 {"free_callback", pydc_free_callback, METH_VARARGS, "free callback obj"},
789 {"p2Z", pydc_p2Z, METH_VARARGS, "ptr to C-string" }, // helper func
775 {NULL,NULL,0,NULL} 790 {NULL,NULL,0,NULL}
776 }; 791 };
777 792
778 PyObject* m; 793 PyObject* m;
779 #if PY_MAJOR_VERSION >= 3 794 #if PY_MAJOR_VERSION >= 3