{"action":"created","comment":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/39556898","id":39556898,"diff_hunk":"@@ -0,0 +1,401 @@\n+/**\n+ * \\file\n+ *\n+ * \\brief Plugin which acts as proxy and calls other plugins written in python\n+ *\n+ * \\copyright BSD License (see doc/COPYING or http://www.libelektra.org)\n+ *\n+ */\n+\n+#ifndef SWIG_TYPE_TABLE\n+# error Build system error, SWIG_TYPE_TABLE is not defined\n+#endif\n+\n+extern \"C\"\n+{\n+#include <Python.h>\n+#ifndef HAVE_KDBCONFIG\n+# include \"kdbconfig.h\"\n+#endif\n+#include SWIG_RUNTIME\n+}\n+\n+#include \"python.hpp\"\n+#include <key.hpp>\n+#include <keyset.hpp>\n+#include <libgen.h>\n+#include <pthread.h>\n+#include <iostream>\n+\n+using namespace ckdb;\n+\n+static PyObject *Python_fromSWIG(ckdb::Key *key)\n+{\n+\tswig_type_info *ti = SWIG_TypeQuery(\"kdb::Key *\");\n+\tif (key == NULL || ti == NULL)\n+\t\treturn Py_None;\n+\treturn SWIG_NewPointerObj(new kdb::Key(key), ti, 0);\n+}\n+\n+static PyObject *Python_fromSWIG(ckdb::KeySet *keyset)\n+{\n+\tswig_type_info *ti = SWIG_TypeQuery(\"kdb::KeySet *\");\n+\tif (keyset == NULL || ti == NULL)\n+\t\treturn Py_None;\n+\treturn SWIG_NewPointerObj(new kdb::KeySet(keyset), ti, 0);\n+}\n+\n+extern \"C\"\n+{\n+\n+typedef struct\n+{\n+\tPyObject *kdbModule;\n+\tPyObject *instance;\n+} moduleData;\n+\n+/* pythons repr() - a little debug helper - misses all Py_DECREF calls! */\n+#define Python_Repr(obj) \\\n+\tPyBytes_AS_STRING( \\\n+\t\tPyUnicode_AsEncodedString(PyObject_Repr(obj), \"utf-8\", \"Error ~\") \\\n+\t)\n+\n+static PyObject *Python_ImportModule(const char *name)\n+{\n+\tif (!name)\n+\t\treturn NULL;\n+\n+\tPyGILState_STATE gstate = PyGILState_Ensure();\n+\tPyObject *module = PyImport_ImportModule(name);\n+\tPyGILState_Release(gstate);\n+\treturn module;\n+}\n+\n+static PyObject *Python_CallFunction(PyObject *object, PyObject *args)\n+{\n+\tPyGILState_STATE gstate = PyGILState_Ensure();\n+\n+\tif (!PyCallable_Check(object))\n+\t{\n+\t\tPyGILState_Release(gstate);\n+\t\treturn NULL;\n+\t}\n+\n+\tPyObject *res = PyObject_CallObject(object, args ? args : PyTuple_New (0));\n+\tPyGILState_Release(gstate);\n+\tPy_XINCREF(res);\n+\treturn res;\n+}\n+\n+static int Python_CallFunction_Int(PyObject *object, PyObject *args)\n+{\n+\tint ret = -1;\n+\tPyGILState_STATE gstate = PyGILState_Ensure();\n+\n+\tPyObject *res = Python_CallFunction(object, args);\n+\tif (!res)\n+\t{\n+\t\tstd::cerr << \"Error while calling python function\" << std::endl;\n+\t\tPyErr_Print();\n+\t}\n+\telse\n+\t{\n+#if PY_MAJOR_VERSION >= 3\n+\t\tif (!PyLong_Check(res))\n+#else\n+\t\tif (!PyInt_Check(res))\n+#endif\n+\t\t\tstd::cerr << \"Error: return value is no integer\" << std::endl;\n+\t\telse\n+\t\t\tret = PyLong_AsLong(res);\n+\t}\n+\n+\tPyGILState_Release(gstate);\n+\tPy_XDECREF(res);\n+\treturn ret;\n+}\n+\n+static int Python_AppendToSysPath(const char *path)\n+{\n+\tif (path == NULL)\n+\t\treturn 0;\n+\n+\tPyGILState_STATE gstate = PyGILState_Ensure();\n+\tPyObject *sysPath = PySys_GetObject((char *)\"path\");\n+\tPyObject *pyPath  = PyUnicode_FromString(path);\n+\tPyList_Append(sysPath, pyPath);\n+\tPy_DECREF(pyPath);\n+\tPyGILState_Release(gstate);\n+\treturn 1;\n+}\n+\n+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;\n+static unsigned open_cnt = 0;\n+\n+int ELEKTRA_PLUGIN_FUNCTION(Python, Open)(ckdb::Plugin *handle, ckdb::Key *errorKey)\n+{\n+\tKeySet *config = elektraPluginGetConfig(handle);\n+\tKey *script = ksLookupByName(config, \"/script\", 0);\n+\t/* success if no script to execute */\n+\n+\tif (script == NULL || keyString(script) == NULL)\n+\t\treturn 0;\n+\n+\t/* initialize python interpreter - only once */\n+\tpthread_mutex_lock(&mutex);\n+\tif (!Py_IsInitialized())\n+\t{\n+\t\tPy_Initialize();\n+\t\tPyEval_InitThreads();\n+\t\tif (!Py_IsInitialized())\n+\t\t{\n+\t\t\tpthread_mutex_unlock(&mutex);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\topen_cnt++;\n+\tpthread_mutex_unlock(&mutex);\n+\n+\t/* import kdb */\n+\tPyObject *kdbModule = Python_ImportModule(\"kdb\");\n+\tif (kdbModule == NULL)\n+\t{\n+\t\tstd::cerr << \"ERROR: Failed to import kdb module\" << std::endl;\n+\t\tPyErr_Print();\n+\t\treturn -1;\n+\t}\n+\tPy_XDECREF(kdbModule);\n+\n+\t/* extend sys path */\n+\tchar *tmpScript = strdup(keyString(script));","path":"src/plugins/python/python.cpp","position":170,"original_position":170,"commit_id":"9534db7a6ad88f38b81d476afc5ce3a0eb4d0da0","original_commit_id":"9534db7a6ad88f38b81d476afc5ce3a0eb4d0da0","user":{"login":"markus2330","id":7949075,"avatar_url":"https://avatars.githubusercontent.com/u/7949075?v=3","gravatar_id":"","url":"https://api.github.com/users/markus2330","html_url":"https://github.com/markus2330","followers_url":"https://api.github.com/users/markus2330/followers","following_url":"https://api.github.com/users/markus2330/following{/other_user}","gists_url":"https://api.github.com/users/markus2330/gists{/gist_id}","starred_url":"https://api.github.com/users/markus2330/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markus2330/subscriptions","organizations_url":"https://api.github.com/users/markus2330/orgs","repos_url":"https://api.github.com/users/markus2330/repos","events_url":"https://api.github.com/users/markus2330/events{/privacy}","received_events_url":"https://api.github.com/users/markus2330/received_events","type":"User","site_admin":false},"body":"should use elektraStrDup\r\n\r\nbasically all memory allocations should use the elektra wrappers.\r\n\r\nWrappers are useful for profiling and memory testing (overwrite elektraMalloc to return 0)","created_at":"2015-09-15T19:57:28Z","updated_at":"2015-09-15T19:57:28Z","html_url":"https://github.com/ElektraInitiative/libelektra/pull/286#discussion_r39556898","pull_request_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286","_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments/39556898"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/286#discussion_r39556898"},"pull_request":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286"}}},"pull_request":{"url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286","id":45080509,"html_url":"https://github.com/ElektraInitiative/libelektra/pull/286","diff_url":"https://github.com/ElektraInitiative/libelektra/pull/286.diff","patch_url":"https://github.com/ElektraInitiative/libelektra/pull/286.patch","issue_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/286","number":286,"state":"open","locked":false,"title":"Python plugin","user":{"login":"manuelm","id":357694,"avatar_url":"https://avatars.githubusercontent.com/u/357694?v=3","gravatar_id":"","url":"https://api.github.com/users/manuelm","html_url":"https://github.com/manuelm","followers_url":"https://api.github.com/users/manuelm/followers","following_url":"https://api.github.com/users/manuelm/following{/other_user}","gists_url":"https://api.github.com/users/manuelm/gists{/gist_id}","starred_url":"https://api.github.com/users/manuelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manuelm/subscriptions","organizations_url":"https://api.github.com/users/manuelm/orgs","repos_url":"https://api.github.com/users/manuelm/repos","events_url":"https://api.github.com/users/manuelm/events{/privacy}","received_events_url":"https://api.github.com/users/manuelm/received_events","type":"User","site_admin":false},"body":"This is an initial PR mainly intended for review work. Please do not pull this in yet.\r\n\r\n","created_at":"2015-09-15T17:50:52Z","updated_at":"2015-09-15T19:57:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f37ee813648bb245eac842accefedc6f7e618c70","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286/commits","review_comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286/comments","review_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/286/comments","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/9534db7a6ad88f38b81d476afc5ce3a0eb4d0da0","head":{"label":"manuelm:python","ref":"python","sha":"9534db7a6ad88f38b81d476afc5ce3a0eb4d0da0","user":{"login":"manuelm","id":357694,"avatar_url":"https://avatars.githubusercontent.com/u/357694?v=3","gravatar_id":"","url":"https://api.github.com/users/manuelm","html_url":"https://github.com/manuelm","followers_url":"https://api.github.com/users/manuelm/followers","following_url":"https://api.github.com/users/manuelm/following{/other_user}","gists_url":"https://api.github.com/users/manuelm/gists{/gist_id}","starred_url":"https://api.github.com/users/manuelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manuelm/subscriptions","organizations_url":"https://api.github.com/users/manuelm/orgs","repos_url":"https://api.github.com/users/manuelm/repos","events_url":"https://api.github.com/users/manuelm/events{/privacy}","received_events_url":"https://api.github.com/users/manuelm/received_events","type":"User","site_admin":false},"repo":{"id":21131285,"name":"libelektra","full_name":"manuelm/libelektra","owner":{"login":"manuelm","id":357694,"avatar_url":"https://avatars.githubusercontent.com/u/357694?v=3","gravatar_id":"","url":"https://api.github.com/users/manuelm","html_url":"https://github.com/manuelm","followers_url":"https://api.github.com/users/manuelm/followers","following_url":"https://api.github.com/users/manuelm/following{/other_user}","gists_url":"https://api.github.com/users/manuelm/gists{/gist_id}","starred_url":"https://api.github.com/users/manuelm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manuelm/subscriptions","organizations_url":"https://api.github.com/users/manuelm/orgs","repos_url":"https://api.github.com/users/manuelm/repos","events_url":"https://api.github.com/users/manuelm/events{/privacy}","received_events_url":"https://api.github.com/users/manuelm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/manuelm/libelektra","description":"Elektra provides a universal and secure framework to store configuration parameters in a global, hierarchical key database.","fork":true,"url":"https://api.github.com/repos/manuelm/libelektra","forks_url":"https://api.github.com/repos/manuelm/libelektra/forks","keys_url":"https://api.github.com/repos/manuelm/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/manuelm/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/manuelm/libelektra/teams","hooks_url":"https://api.github.com/repos/manuelm/libelektra/hooks","issue_events_url":"https://api.github.com/repos/manuelm/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/manuelm/libelektra/events","assignees_url":"https://api.github.com/repos/manuelm/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/manuelm/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/manuelm/libelektra/tags","blobs_url":"https://api.github.com/repos/manuelm/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/manuelm/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/manuelm/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/manuelm/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/manuelm/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/manuelm/libelektra/languages","stargazers_url":"https://api.github.com/repos/manuelm/libelektra/stargazers","contributors_url":"https://api.github.com/repos/manuelm/libelektra/contributors","subscribers_url":"https://api.github.com/repos/manuelm/libelektra/subscribers","subscription_url":"https://api.github.com/repos/manuelm/libelektra/subscription","commits_url":"https://api.github.com/repos/manuelm/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/manuelm/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/manuelm/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/manuelm/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/manuelm/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/manuelm/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/manuelm/libelektra/merges","archive_url":"https://api.github.com/repos/manuelm/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/manuelm/libelektra/downloads","issues_url":"https://api.github.com/repos/manuelm/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/manuelm/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/manuelm/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/manuelm/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/manuelm/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/manuelm/libelektra/releases{/id}","created_at":"2014-06-23T15:25:38Z","updated_at":"2015-09-07T12:24:38Z","pushed_at":"2015-09-15T17:43:32Z","git_url":"git://github.com/manuelm/libelektra.git","ssh_url":"git@github.com:manuelm/libelektra.git","clone_url":"https://github.com/manuelm/libelektra.git","svn_url":"https://github.com/manuelm/libelektra","homepage":"","size":28918,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ElektraInitiative:master","ref":"master","sha":"86473bedb658b2bad055e463de707c09ca6518fe","user":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"repo":{"id":21063580,"name":"libelektra","full_name":"ElektraInitiative/libelektra","owner":{"login":"ElektraInitiative","id":7949092,"avatar_url":"https://avatars.githubusercontent.com/u/7949092?v=3","gravatar_id":"","url":"https://api.github.com/users/ElektraInitiative","html_url":"https://github.com/ElektraInitiative","followers_url":"https://api.github.com/users/ElektraInitiative/followers","following_url":"https://api.github.com/users/ElektraInitiative/following{/other_user}","gists_url":"https://api.github.com/users/ElektraInitiative/gists{/gist_id}","starred_url":"https://api.github.com/users/ElektraInitiative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElektraInitiative/subscriptions","organizations_url":"https://api.github.com/users/ElektraInitiative/orgs","repos_url":"https://api.github.com/users/ElektraInitiative/repos","events_url":"https://api.github.com/users/ElektraInitiative/events{/privacy}","received_events_url":"https://api.github.com/users/ElektraInitiative/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ElektraInitiative/libelektra","description":"Elektra provides a universal and secure framework to store configuration parameters in a global, hierarchical key database.","fork":false,"url":"https://api.github.com/repos/ElektraInitiative/libelektra","forks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/forks","keys_url":"https://api.github.com/repos/ElektraInitiative/libelektra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ElektraInitiative/libelektra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ElektraInitiative/libelektra/teams","hooks_url":"https://api.github.com/repos/ElektraInitiative/libelektra/hooks","issue_events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/events{/number}","events_url":"https://api.github.com/repos/ElektraInitiative/libelektra/events","assignees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/assignees{/user}","branches_url":"https://api.github.com/repos/ElektraInitiative/libelektra/branches{/branch}","tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/tags","blobs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/refs{/sha}","trees_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/{sha}","languages_url":"https://api.github.com/repos/ElektraInitiative/libelektra/languages","stargazers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/stargazers","contributors_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contributors","subscribers_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscribers","subscription_url":"https://api.github.com/repos/ElektraInitiative/libelektra/subscription","commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/commits{/sha}","git_commits_url":"https://api.github.com/repos/ElektraInitiative/libelektra/git/commits{/sha}","comments_url":"https://api.github.com/repos/ElektraInitiative/libelektra/comments{/number}","issue_comment_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/comments{/number}","contents_url":"https://api.github.com/repos/ElektraInitiative/libelektra/contents/{+path}","compare_url":"https://api.github.com/repos/ElektraInitiative/libelektra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ElektraInitiative/libelektra/merges","archive_url":"https://api.github.com/repos/ElektraInitiative/libelektra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ElektraInitiative/libelektra/downloads","issues_url":"https://api.github.com/repos/ElektraInitiative/libelektra/issues{/number}","pulls_url":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls{/number}","milestones_url":"https://api.github.com/repos/ElektraInitiative/libelektra/milestones{/number}","notifications_url":"https://api.github.com/repos/ElektraInitiative/libelektra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ElektraInitiative/libelektra/labels{/name}","releases_url":"https://api.github.com/repos/ElektraInitiative/libelektra/releases{/id}","created_at":"2014-06-21T08:01:04Z","updated_at":"2015-08-30T22:05:09Z","pushed_at":"2015-09-15T19:48:46Z","git_url":"git://github.com/ElektraInitiative/libelektra.git","ssh_url":"git@github.com:ElektraInitiative/libelektra.git","clone_url":"https://github.com/ElektraInitiative/libelektra.git","svn_url":"https://github.com/ElektraInitiative/libelektra","homepage":"","size":31200,"stargazers_count":17,"watchers_count":17,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":39,"forks":15,"open_issues":39,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286"},"html":{"href":"https://github.com/ElektraInitiative/libelektra/pull/286"},"issue":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/286"},"comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/issues/286/comments"},"review_comments":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286/comments"},"review_comment":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/pulls/286/commits"},"statuses":{"href":"https://api.github.com/repos/ElektraInitiative/libelektra/statuses/9534db7a6ad88f38b81d476afc5ce3a0eb4d0da0"}}}}