aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Utility/CommonStructures.c
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
committeralexv-smirnov <alex@ydb.tech>2023-06-13 11:05:01 +0300
commitbf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch)
tree1d1df72c0541a59a81439842f46d95396d3e7189 /contrib/tools/cython/Cython/Utility/CommonStructures.c
parent8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff)
downloadydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz
add ymake export to ydb
Diffstat (limited to 'contrib/tools/cython/Cython/Utility/CommonStructures.c')
-rw-r--r--contrib/tools/cython/Cython/Utility/CommonStructures.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/contrib/tools/cython/Cython/Utility/CommonStructures.c b/contrib/tools/cython/Cython/Utility/CommonStructures.c
new file mode 100644
index 0000000000..c7945feb49
--- /dev/null
+++ b/contrib/tools/cython/Cython/Utility/CommonStructures.c
@@ -0,0 +1,86 @@
+/////////////// FetchCommonType.proto ///////////////
+
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
+
+/////////////// FetchCommonType ///////////////
+
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
+ PyObject* fake_module;
+ PyTypeObject* cached_type = NULL;
+
+ fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+ if (!fake_module) return NULL;
+ Py_INCREF(fake_module);
+
+ cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
+ if (cached_type) {
+ if (!PyType_Check((PyObject*)cached_type)) {
+ PyErr_Format(PyExc_TypeError,
+ "Shared Cython type %.200s is not a type object",
+ type->tp_name);
+ goto bad;
+ }
+ if (cached_type->tp_basicsize != type->tp_basicsize) {
+ PyErr_Format(PyExc_TypeError,
+ "Shared Cython type %.200s has the wrong size, try recompiling",
+ type->tp_name);
+ goto bad;
+ }
+ } else {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
+ PyErr_Clear();
+ if (PyType_Ready(type) < 0) goto bad;
+ if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
+ goto bad;
+ Py_INCREF(type);
+ cached_type = type;
+ }
+
+done:
+ Py_DECREF(fake_module);
+ // NOTE: always returns owned reference, or NULL on error
+ return cached_type;
+
+bad:
+ Py_XDECREF(cached_type);
+ cached_type = NULL;
+ goto done;
+}
+
+
+/////////////// FetchCommonPointer.proto ///////////////
+
+static void* __Pyx_FetchCommonPointer(void* pointer, const char* name);
+
+/////////////// FetchCommonPointer ///////////////
+
+
+static void* __Pyx_FetchCommonPointer(void* pointer, const char* name) {
+#if PY_VERSION_HEX >= 0x02070000
+ PyObject* fake_module = NULL;
+ PyObject* capsule = NULL;
+ void* value = NULL;
+
+ fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+ if (!fake_module) return NULL;
+ Py_INCREF(fake_module);
+
+ capsule = PyObject_GetAttrString(fake_module, name);
+ if (!capsule) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
+ PyErr_Clear();
+ capsule = PyCapsule_New(pointer, name, NULL);
+ if (!capsule) goto bad;
+ if (PyObject_SetAttrString(fake_module, name, capsule) < 0)
+ goto bad;
+ }
+ value = PyCapsule_GetPointer(capsule, name);
+
+bad:
+ Py_XDECREF(capsule);
+ Py_DECREF(fake_module);
+ return value;
+#else
+ return pointer;
+#endif
+}