summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Anderson <dda@ddanderson.com>2015-01-22 10:40:11 -0500
committerDon Anderson <dda@ddanderson.com>2015-01-22 10:40:11 -0500
commit4843cd78e7f90937ebdb23f84fbd7c133a7e5256 (patch)
tree9d547f6c3fe2dd9104e88bc5bf026384d1e5b18c
parent72172b088fba6769866aecabba8176303140f5c4 (diff)
downloadmongo-4843cd78e7f90937ebdb23f84fbd7c133a7e5256.tar.gz
Prepend underscores to methods that could have name conflicts
with WT internal names. These methods were exposed for conflict because we created public C names by 'extending' classes in SWIG. SWIG's wrapper naming for such methods apparently follows a different convention than the usual "_wrap_<PythonName>_<FunctionName>", and uses "<CTypeName>_<FunctionName", e.g. "__wt_cursor_equals". Refs #1574.
-rw-r--r--lang/python/wiredtiger.i42
1 files changed, 34 insertions, 8 deletions
diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i
index bf726ceac0a..c206017a5df 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):
+ '''equals 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;