summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorAlex Gorrod <alexg@wiredtiger.com>2013-04-17 12:01:27 +1000
committerAlex Gorrod <alexg@wiredtiger.com>2013-04-17 12:01:27 +1000
commit9f32a8755c397a4a3736cbdf454a36c93db4ba66 (patch)
tree335c6f81c202b59b8e70444d3dfba7eb88799251 /lang
parentf1b62c12aa6c92694ba544c028ae506668822751 (diff)
downloadmongo-9f32a8755c397a4a3736cbdf454a36c93db4ba66.tar.gz
Add implementation for close callbacks. Add event callbacks to Python.
This breaks the test suite - since it is playing tricks to capture a weird output stream, due to not implementing the event callbacks.
Diffstat (limited to 'lang')
-rw-r--r--lang/python/wiredtiger.i76
1 files changed, 74 insertions, 2 deletions
diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i
index 8c381d5aae5..fd25f21e993 100644
--- a/lang/python/wiredtiger.i
+++ b/lang/python/wiredtiger.i
@@ -35,8 +35,9 @@ from packing import pack, unpack
$1 = &temp;
}
-/* Event handlers are not supported in Python. */
-%typemap(in, numinputs=0) WT_EVENT_HANDLER * { $1 = NULL; }
+%typemap(in, numinputs=0) WT_EVENT_HANDLER * %{
+ $1 = &pyApiEventHandler;
+%}
/* Set the return value to the returned connection, session, or cursor */
%typemap(argout) WT_CONNECTION ** {
@@ -441,6 +442,77 @@ typedef int int_void;
%include "wiredtiger.h"
+/* Add event handler support. */
+%{
+
+static int writeToPythonStream(const char *streamname, const char *message) {
+ PyObject *sys = NULL;
+ PyObject *se = NULL;
+ PyObject *sys_stderr_write = NULL;
+ PyObject *written = NULL;
+ PyObject *arglist = NULL;
+ int ret = 0;
+ /*PyGILState_STATE gstate;*/
+
+ /* Aquire python Global Interpreter Lock. Otherwise can segfault. */
+ SWIG_PYTHON_THREAD_BEGIN_BLOCK;
+ /*gstate = PyGILState_Ensure();*/
+
+ sys = PyImport_ImportModule("sys");
+ if (!sys) {
+ ret = 1;
+ goto err;
+ }
+ se = PyObject_GetAttrString(sys, streamname);
+ if (!se) {
+ ret = 1;
+ goto err;
+ }
+ sys_stderr_write = PyObject_GetAttrString(se, "write");
+ if (!sys_stderr_write) {
+ ret = 1;
+ goto err;
+ }
+
+ arglist = Py_BuildValue("(s)", message);
+ if (!arglist) {
+ ret = 1;
+ goto err;
+ }
+ written = PyObject_CallObject(sys_stderr_write, arglist);
+err: /* Release python Global Interpreter Lock */
+ SWIG_PYTHON_THREAD_END_BLOCK;
+ /*PyGILState_Release(gstate);*/
+ if (arglist)
+ Py_XDECREF(arglist);
+ if (sys_stderr_write)
+ Py_XDECREF(sys_stderr_write);
+ if (se)
+ Py_XDECREF(se);
+ if (sys)
+ Py_XDECREF(sys);
+ if (written)
+ Py_XDECREF(written);
+ return ret;
+}
+static int pythonErrorCallback(WT_EVENT_HANDLER *handler, int err, const char *message)
+{
+ return writeToPythonStream("stderr", message);
+}
+
+static int pythonMessageCallback(WT_EVENT_HANDLER *handler, const char *message)
+{
+ return writeToPythonStream("stdout", message);
+}
+
+static int pythonCloseCallback(WT_EVENT_HANDLER *handler, WT_SESSION *session, WT_CURSOR *cursor)
+{
+ return 0;
+}
+
+WT_EVENT_HANDLER pyApiEventHandler = {pythonErrorCallback, pythonMessageCallback, NULL, pythonCloseCallback};
+%}
+
%pythoncode %{
class stat:
'''keys for statistics cursors'''