diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/python/symbols/module/module.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/python/symbols/module/module.cpp')
-rw-r--r-- | library/python/symbols/module/module.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/library/python/symbols/module/module.cpp b/library/python/symbols/module/module.cpp new file mode 100644 index 0000000000..92bc7f4d67 --- /dev/null +++ b/library/python/symbols/module/module.cpp @@ -0,0 +1,85 @@ +#include <Python.h> + +#include <library/python/symbols/registry/syms.h> + +#include <util/generic/string.h> + +#define CAP(x) SYM_2(x, x) + +BEGIN_SYMS("_capability") +#if defined(_musl_) +CAP("musl") +#endif +#if defined(_linux_) +CAP("linux") +#endif +#if defined(_darwin_) +CAP("darwin") +#endif +CAP("_sentinel") +END_SYMS() + +#undef CAP + +using namespace NPrivate; + +namespace { + template <class T> + struct TCB: public ICB { + inline TCB(T& t) + : CB(&t) + { + } + + void Apply(const char* mod, const char* name, void* sym) override { + (*CB)(mod, name, sym); + } + + T* CB; + }; + + template <class T> + static inline TCB<T> MakeTCB(T& t) { + return t; + } +} + +static void DictSetStringPtr(PyObject* dict, const char* name, void* value) { + PyObject* p = PyLong_FromVoidPtr(value); + PyDict_SetItemString(dict, name, p); + Py_DECREF(p); +} + +static PyObject* InitSyms(PyObject* m) { + if (!m) + return NULL; + PyObject* d = PyDict_New(); + if (!d) + return NULL; + + auto f = [&](const char* mod, const char* name, void* sym) { + DictSetStringPtr(d, (TString(mod) + "|" + TString(name)).c_str(), sym); + }; + + auto cb = MakeTCB(f); + + ForEachSymbol(cb); + + if (PyObject_SetAttrString(m, "syms", d)) + m = NULL; + Py_DECREF(d); + return m; +} + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef module = { + PyModuleDef_HEAD_INIT, "syms", NULL, -1, NULL, NULL, NULL, NULL, NULL}; + +extern "C" PyObject* PyInit_syms() { + return InitSyms(PyModule_Create(&module)); +} +#else +extern "C" void initsyms() { + InitSyms(Py_InitModule("syms", NULL)); +} +#endif |