summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2012-08-16 11:44:12 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2012-08-16 11:44:12 +1000
commitd5c301155b2957786064f844ae44fa41a3a4e8c4 (patch)
tree96882c0217a7ecd2d8be46d2731456aece8ccc91 /lang
parenta2f20ac60c6f6c1a17cbb5e96d16d2d826924a22 (diff)
parent71407c0ce76538ef7035bdb5e0cef35c6e4c84b6 (diff)
downloadmongo-d5c301155b2957786064f844ae44fa41a3a4e8c4.tar.gz
Merge branch 'develop' of github.com:wiredtiger/wiredtiger into develop
Conflicts: build_posix/configure.ac.in
Diffstat (limited to 'lang')
-rw-r--r--lang/python/Makefile.am2
-rw-r--r--lang/python/setup.py39
-rw-r--r--lang/python/wiredtiger.i100
3 files changed, 107 insertions, 34 deletions
diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am
index fbc7d3b5835..fede28ff058 100644
--- a/lang/python/Makefile.am
+++ b/lang/python/Makefile.am
@@ -7,7 +7,7 @@ endif
all-local: _wiredtiger.so
$(PYSRC)/wiredtiger_wrap.c: $(top_srcdir)/src/include/wiredtiger.in $(PYSRC)/wiredtiger.i
@(cd $(PYSRC) && \
- $(SWIG) -python -threads -I$(abs_top_builddir) wiredtiger.i)
+ $(SWIG) -python -nodefaultctor -nodefaultdtor -threads -I$(abs_top_builddir) wiredtiger.i)
_wiredtiger.so: $(top_builddir)/libwiredtiger.la $(PYSRC)/wiredtiger_wrap.c
$(PYTHON) $(PYSRC)/setup.py build_ext -b . -t . -f $(PY_SETUP_DEBUG)
diff --git a/lang/python/setup.py b/lang/python/setup.py
index 366f71532eb..fb2e036578b 100644
--- a/lang/python/setup.py
+++ b/lang/python/setup.py
@@ -1,34 +1,43 @@
-#
+#!/usr/bin/env python
#
# Copyright (c) 2008-2012 WiredTiger, Inc.
-# All rights reserved.
+# All rights reserved.
#
# See the file LICENSE for redistribution information.
-import re, os
+import re, os, sys
from distutils.core import setup, Extension
# OS X hack: turn off the Universal binary support that is built into the
# Python build machinery, just build for the default CPU architecture.
if not 'ARCHFLAGS' in os.environ:
- os.environ['ARCHFLAGS'] = ''
+ os.environ['ARCHFLAGS'] = ''
+
+# Suppress warnings building SWIG code on OS X 10.8
+extra_cflags = []
+if sys.platform == 'darwin':
+ kernel_version = os.uname()[2] # e.g. 12.0.0 is Mountain Lion
+ major_version = int(kernel_version.split('.')[0])
+ if major_version >= 12:
+ extra_cflags += ['-Wno-self-assign', '-Qunused-arguments']
dir = os.path.dirname(__file__)
-# Read the version information from dist/RELEASE
-dist = os.path.join(os.path.dirname(os.path.dirname(dir)), 'dist')
-for l in open(os.path.join(dist, 'RELEASE')):
- if re.match(r'WIREDTIGER_VERSION_(?:MAJOR|MINOR|PATCH)=', l):
- exec(l)
+# Read the version information from the RELEASE file
+top = os.path.dirname(os.path.dirname(dir))
+for l in open(os.path.join(top, 'RELEASE')):
+ if re.match(r'WIREDTIGER_VERSION_(?:MAJOR|MINOR|PATCH)=', l):
+ exec(l)
wt_ver = '%d.%d' % (WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR)
setup(name='wiredtiger', version=wt_ver,
ext_modules=[Extension('_wiredtiger',
- [os.path.join(dir, 'wiredtiger_wrap.c')],
- include_dirs=['../..'],
- library_dirs=['../../.libs'],
- libraries=['wiredtiger'],
- )],
- py_modules=['wiredtiger'],
+ [os.path.join(dir, 'wiredtiger_wrap.c')],
+ include_dirs=['../..'],
+ library_dirs=['../../.libs'],
+ libraries=['wiredtiger'],
+ extra_compile_args=extra_cflags,
+ )],
+ py_modules=['wiredtiger'],
)
diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i
index 50b81399c27..9466ea2ab5c 100644
--- a/lang/python/wiredtiger.i
+++ b/lang/python/wiredtiger.i
@@ -35,9 +35,6 @@ from packing import pack, unpack
$1 = &temp;
}
-/* Convert 'int *' to an output arg in search_near, wiredtiger_version */
-%apply int *OUTPUT { int * };
-
/* Event handlers are not supported in Python. */
%typemap(in, numinputs=0) WT_EVENT_HANDLER * { $1 = NULL; }
@@ -130,15 +127,6 @@ class IterableCursor:
## @endcond
%}
-%typemap(out) int {
- if ($1 != 0 && $1 != WT_NOTFOUND) {
- /* We could use PyErr_SetObject for more complex reporting. */
- SWIG_Python_SetErrorMsg(wtError, wiredtiger_strerror($1));
- SWIG_fail;
- }
- $result = SWIG_From_int((int)($1));
-}
-
/*
* Extra 'self' elimination.
* The methods we're wrapping look like this:
@@ -150,8 +138,8 @@ class IterableCursor:
* and we use consecutive argument matching of typemaps to convert two args to
* one.
*/
-%define SELFHELPER(type)
-%typemap(in) (type *self, type *) (void *argp = 0, int res = 0) %{
+%define SELFHELPER(type, name)
+%typemap(in) (type *self, type *name) (void *argp = 0, int res = 0) %{
res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '$symname', "
@@ -161,17 +149,21 @@ class IterableCursor:
%}
%enddef
-SELFHELPER(struct __wt_connection)
-SELFHELPER(struct __wt_session)
-SELFHELPER(struct __wt_cursor)
+SELFHELPER(struct __wt_connection, connection)
+SELFHELPER(struct __wt_session, session)
+SELFHELPER(struct __wt_cursor, cursor)
/* WT_CURSOR customization. */
/* First, replace the varargs get / set methods with Python equivalents. */
%ignore __wt_cursor::get_key;
-%ignore __wt_cursor::set_key;
%ignore __wt_cursor::get_value;
+%ignore __wt_cursor::set_key;
%ignore __wt_cursor::set_value;
+/* Next, override methods that return integers via arguments. */
+%ignore __wt_cursor::equals(WT_CURSOR *, WT_CURSOR *, int *);
+%ignore __wt_cursor::search_near(WT_CURSOR *, int *);
+
/* SWIG magic to turn Python byte strings into data / size. */
%apply (char *STRING, int LENGTH) { (char *data, int size) };
@@ -247,6 +239,34 @@ SELFHELPER(struct __wt_cursor)
return SWIG_FromCharPtrAndSize(v.data, v.size);
}
+ /* equals and search_near need special handling. */
+ PyObject *equals(WT_CURSOR *other) {
+ int is_equal = 0;
+ int ret = $self->equals($self, other, &is_equal);
+ if (ret != 0) {
+ SWIG_Python_SetErrorMsg(wtError,
+ wiredtiger_strerror(ret));
+ return (NULL);
+ }
+ return (SWIG_From_int(is_equal));
+ }
+
+ PyObject *search_near() {
+ int cmp = 0;
+ int ret = $self->search_near($self, &cmp);
+ if (ret != 0 && ret != WT_NOTFOUND) {
+ SWIG_Python_SetErrorMsg(wtError,
+ wiredtiger_strerror(ret));
+ return (NULL);
+ }
+ /*
+ * Map less-than-zero to -1 and greater-than-zero to 1 to avoid
+ * colliding with WT_NOTFOUND.
+ */
+ return (SWIG_From_int((ret != 0) ? ret :
+ (cmp < 0) ? -1 : (cmp == 0) ? 0 : 1));
+ }
+
%pythoncode %{
def get_key(self):
'''get_key(self) -> object
@@ -333,6 +353,50 @@ SELFHELPER(struct __wt_cursor)
%ignore wiredtiger_extension_init;
+/*
+ * Error handling. This comes last so it doesn't interfere with the extension
+ * code above.
+ *
+ * Default case: a non-zero return is an error.
+ */
+%exception {
+ $action
+ if (result != 0) {
+ /* We could use PyErr_SetObject for more complex reporting. */
+ SWIG_Python_SetErrorMsg(wtError, wiredtiger_strerror(result));
+ SWIG_fail;
+ }
+}
+
+/* Cursor positioning methods can also return WT_NOTFOUND. */
+%define NOTFOUND_OK(m)
+%exception m {
+ $action
+ if (result != 0 && result != WT_NOTFOUND) {
+ /* We could use PyErr_SetObject for more complex reporting. */
+ SWIG_Python_SetErrorMsg(wtError, wiredtiger_strerror(result));
+ SWIG_fail;
+ }
+}
+%enddef
+
+NOTFOUND_OK(__wt_cursor::next)
+NOTFOUND_OK(__wt_cursor::prev)
+NOTFOUND_OK(__wt_cursor::remove)
+NOTFOUND_OK(__wt_cursor::search)
+NOTFOUND_OK(__wt_cursor::update)
+
+/* Lastly, some methods need no (additional) error checking. */
+%exception __wt_connection::equals;
+%exception __wt_connection::search_near;
+%exception __wt_connection::get_home;
+%exception __wt_connection::is_new;
+%exception wiredtiger_strerror;
+%exception wiredtiger_version;
+
+/* Convert 'int *' to output args for wiredtiger_version */
+%apply int *OUTPUT { int * };
+
%rename(Cursor) __wt_cursor;
%rename(Session) __wt_session;
%rename(Connection) __wt_connection;