summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2015-01-24 09:33:20 -0500
committerKeith Bostic <keith.bostic@mongodb.com>2015-01-24 09:33:20 -0500
commitaa13db7ab192a7e491f265a4f8b8e34c765dbdc4 (patch)
tree4bb27ba8899633c4a9e67399f94f349a794985f1
parentd324db82b021ed5385585047cbec783522bed1b6 (diff)
parent930f899ec58dd21032602e295100a29867092dbe (diff)
downloadmongo-aa13db7ab192a7e491f265a4f8b8e34c765dbdc4.tar.gz
Merge pull request #1588 from wiredtiger/py-swig-naming
Python SWIG renaming to avoid naming conflicts
-rw-r--r--dist/s_all1
-rwxr-xr-xdist/s_lang19
-rw-r--r--lang/python/wiredtiger.i42
-rw-r--r--src/cursor/cur_ds.c2
-rw-r--r--src/cursor/cur_log.c2
-rw-r--r--src/cursor/cur_metadata.c2
-rw-r--r--src/cursor/cur_std.c4
-rw-r--r--src/cursor/cur_table.c2
-rw-r--r--src/include/extern.h2
-rw-r--r--src/lsm/lsm_cursor.c2
10 files changed, 62 insertions, 16 deletions
diff --git a/dist/s_all b/dist/s_all
index 1b171bdeafd..0e584b938b9 100644
--- a/dist/s_all
+++ b/dist/s_all
@@ -69,6 +69,7 @@ run "sh ./s_copyright" "checking copyright notices"
run "sh ./s_define" "checking for unused #defines"
run "sh ./s_funcs" "checking for unused functions"
run "sh ./s_getopt" "checking for incorrect getopt usage"
+run "sh ./s_lang" "checking for SWIG generated name conflicts"
run "sh ./s_longlines" "checking for long lines"
run "sh ./s_stat" "checking for unused statistics fields"
run "sh ./s_string" "checking string spelling"
diff --git a/dist/s_lang b/dist/s_lang
new file mode 100755
index 00000000000..56a7a212e6b
--- /dev/null
+++ b/dist/s_lang
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Check lang directories for potential name conflicts
+t=__wt.$$
+trap 'rm -f $t; exit 0' 0 1 2 3 13 15
+
+cd ..
+
+for l in java python; do
+ sed -e '/SWIGINTERN.*__wt_[a-z][a-z]*_[a-z]/!d' \
+ -e '/__wt_[^(]*__.*(/d' \
+ -e '/_wrap/d' \
+ -e "/_${l}_/d" \
+ lang/$l/wiredtiger_wrap.c > $t
+ if [ -s $t ]; then
+ echo "$l: potential name conflict"
+ cat $t
+ fi
+done
diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i
index bf726ceac0a..d35d7d5c456 100644
--- a/lang/python/wiredtiger.i
+++ b/lang/python/wiredtiger.i
@@ -157,7 +157,7 @@ from packing import pack, unpack
%define DESTRUCTOR(class, method)
%feature("shadow") class::method %{
def method(self, *args):
- '''close(self, config) -> int
+ '''method(self, config) -> int
@copydoc class::method'''
try:
@@ -171,6 +171,26 @@ DESTRUCTOR(__wt_connection, close)
DESTRUCTOR(__wt_cursor, close)
DESTRUCTOR(__wt_session, close)
+/*
+ * OVERRIDE_METHOD must be used when overriding or extending an existing
+ * method in the C interface. It creates Python method() that calls
+ * _method(), which is the extended version of the method. This works
+ * around potential naming conflicts. Without this technique, for example,
+ * defining __wt_cursor::equals() creates the wrapper function
+ * __wt_cursor_equals(), which may be defined in the WT library.
+ */
+%define OVERRIDE_METHOD(cclass, pyclass, method, pyargs)
+%extend cclass {
+%pythoncode %{
+ def method(self, *args):
+ '''method pyargs -> int
+
+ @copydoc class::method'''
+ return self._##method(*args)
+%}
+};
+%enddef
+
/* Don't require empty config strings. */
%typemap(default) const char *config { $1 = NULL; }
%typemap(default) WT_CURSOR *to_dup { $1 = NULL; }
@@ -389,9 +409,9 @@ NOTFOUND_OK(__wt_cursor::remove)
NOTFOUND_OK(__wt_cursor::search)
NOTFOUND_OK(__wt_cursor::update)
-COMPARE_OK(__wt_cursor::compare)
-COMPARE_OK(__wt_cursor::equals)
-COMPARE_NOTFOUND_OK(__wt_cursor::search_near)
+COMPARE_OK(__wt_cursor::_compare)
+COMPARE_OK(__wt_cursor::_equals)
+COMPARE_NOTFOUND_OK(__wt_cursor::_search_near)
/* Lastly, some methods need no (additional) error checking. */
%exception __wt_connection::get_home;
@@ -428,6 +448,10 @@ COMPARE_NOTFOUND_OK(__wt_cursor::search_near)
%ignore __wt_cursor::equals(WT_CURSOR *, WT_CURSOR *, int *);
%ignore __wt_cursor::search_near(WT_CURSOR *, int *);
+OVERRIDE_METHOD(__wt_cursor, WT_CURSOR, compare, (self, other))
+OVERRIDE_METHOD(__wt_cursor, WT_CURSOR, equals, (self, other))
+OVERRIDE_METHOD(__wt_cursor, WT_CURSOR, search_near, (self))
+
/* SWIG magic to turn Python byte strings into data / size. */
%apply (char *STRING, int LENGTH) { (char *data, int size) };
@@ -685,7 +709,7 @@ typedef int int_void;
}
/* compare: special handling. */
- int compare(WT_CURSOR *other) {
+ int _compare(WT_CURSOR *other) {
int cmp = 0;
int ret = 0;
if (other == NULL) {
@@ -709,7 +733,7 @@ typedef int int_void;
}
/* equals: special handling. */
- int equals(WT_CURSOR *other) {
+ int _equals(WT_CURSOR *other) {
int cmp = 0;
int ret = 0;
if (other == NULL) {
@@ -728,7 +752,7 @@ typedef int int_void;
}
/* search_near: special handling. */
- int search_near() {
+ int _search_near() {
int cmp = 0;
int ret = $self->search_near($self, &cmp);
/*
@@ -828,7 +852,7 @@ typedef int int_void;
};
%extend __wt_session {
- int log_printf(const char *msg) {
+ int _log_printf(const char *msg) {
return self->log_printf(self, "%s", msg);
}
@@ -892,6 +916,8 @@ int verbose_build();
%ignore __wt_connection::get_extension_api;
%ignore __wt_session::log_printf;
+OVERRIDE_METHOD(__wt_session, WT_SESSION, log_printf, (self, msg))
+
%ignore wiredtiger_struct_pack;
%ignore wiredtiger_struct_size;
%ignore wiredtiger_struct_unpack;
diff --git a/src/cursor/cur_ds.c b/src/cursor/cur_ds.c
index cc3e23570d5..c58d6899150 100644
--- a/src/cursor/cur_ds.c
+++ b/src/cursor/cur_ds.c
@@ -454,7 +454,7 @@ __wt_curds_open(
__wt_cursor_set_key, /* set-key */
__wt_cursor_set_value, /* set-value */
__curds_compare, /* compare */
- __wt_cursor_equal, /* equals */
+ __wt_cursor_equals, /* equals */
__curds_next, /* next */
__curds_prev, /* prev */
__curds_reset, /* reset */
diff --git a/src/cursor/cur_log.c b/src/cursor/cur_log.c
index 2e2a2530df6..5de3762217f 100644
--- a/src/cursor/cur_log.c
+++ b/src/cursor/cur_log.c
@@ -344,7 +344,7 @@ __wt_curlog_open(WT_SESSION_IMPL *session,
__wt_cursor_set_key, /* set-key */
__wt_cursor_set_value, /* set-value */
__curlog_compare, /* compare */
- __wt_cursor_equal, /* equals */
+ __wt_cursor_equals, /* equals */
__curlog_next, /* next */
__wt_cursor_notsup, /* prev */
__curlog_reset, /* reset */
diff --git a/src/cursor/cur_metadata.c b/src/cursor/cur_metadata.c
index 31c96e3087a..9860eb65a55 100644
--- a/src/cursor/cur_metadata.c
+++ b/src/cursor/cur_metadata.c
@@ -409,7 +409,7 @@ __wt_curmetadata_open(WT_SESSION_IMPL *session,
__wt_cursor_set_key, /* set-key */
__wt_cursor_set_value, /* set-value */
__curmetadata_compare, /* compare */
- __wt_cursor_equal, /* equals */
+ __wt_cursor_equals, /* equals */
__curmetadata_next, /* next */
__curmetadata_prev, /* prev */
__curmetadata_reset, /* reset */
diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c
index df38eb9e57d..858c6af6853 100644
--- a/src/cursor/cur_std.c
+++ b/src/cursor/cur_std.c
@@ -480,11 +480,11 @@ __wt_cursor_close(WT_CURSOR *cursor)
}
/*
- * __wt_cursor_equal --
+ * __wt_cursor_equals --
* WT_CURSOR->equals default implementation.
*/
int
-__wt_cursor_equal(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp)
+__wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp)
{
WT_DECL_RET;
WT_SESSION_IMPL *session;
diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c
index f8e8625b0bd..a046b2b1ed9 100644
--- a/src/cursor/cur_table.c
+++ b/src/cursor/cur_table.c
@@ -839,7 +839,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session,
__wt_curtable_set_key, /* set-key */
__wt_curtable_set_value, /* set-value */
__curtable_compare, /* compare */
- __wt_cursor_equal, /* equals */
+ __wt_cursor_equals, /* equals */
__curtable_next, /* next */
__curtable_prev, /* prev */
__curtable_reset, /* reset */
diff --git a/src/include/extern.h b/src/include/extern.h
index 35b8dfc113e..4872e48eeed 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -280,7 +280,7 @@ extern int __wt_cursor_get_valuev(WT_CURSOR *cursor, va_list ap);
extern void __wt_cursor_set_value(WT_CURSOR *cursor, ...);
extern void __wt_cursor_set_valuev(WT_CURSOR *cursor, va_list ap);
extern int __wt_cursor_close(WT_CURSOR *cursor);
-extern int __wt_cursor_equal(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp);
+extern int __wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp);
extern int __wt_cursor_reconfigure(WT_CURSOR *cursor, const char *config);
extern int __wt_cursor_dup_position(WT_CURSOR *to_dup, WT_CURSOR *cursor);
extern int __wt_cursor_init(WT_CURSOR *cursor, const char *uri, WT_CURSOR *owner, const char *cfg[], WT_CURSOR **cursorp);
diff --git a/src/lsm/lsm_cursor.c b/src/lsm/lsm_cursor.c
index 39b4b4508b7..bf5ae465664 100644
--- a/src/lsm/lsm_cursor.c
+++ b/src/lsm/lsm_cursor.c
@@ -1429,7 +1429,7 @@ __wt_clsm_open(WT_SESSION_IMPL *session,
__wt_cursor_set_key, /* set-key */
__wt_cursor_set_value, /* set-value */
__clsm_compare, /* compare */
- __wt_cursor_equal, /* equals */
+ __wt_cursor_equals, /* equals */
__clsm_next, /* next */
__clsm_prev, /* prev */
__clsm_reset, /* reset */