diff --git a/CHANGES.current b/CHANGES.current index 1ff98e258..570b0473f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.41 (in progress) ============================ +2009-12-20: wsfulton + Add -debug-tmsearch option for debugging the typemap pattern matching rules. + Documented in Typemaps.html. + 2009-12-12: wsfulton [Octave] Remove the -api option and use the new OCTAVE_API_VERSION_NUMBER macro provided in the octave headers for determining the api version instead. diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 7a89a679a..3a8242866 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -31,10 +31,11 @@
@@ -1432,6 +1433,104 @@ but all subsequent arguments must match exactly.
++The -debug-tmsearch command line option is available for debugging typemap searches. +This can be very useful for watching the pattern matching process in action and for debugging which typemaps are used. +The option displays all the typemaps and types that are looked for until a successful pattern match is made. +As the display includes searches for each and every type needed for wrapping, the amount of information displayed can be large. +Normally you would manually search through the displayed information for the particular type that you are interested in. +
+ ++For example, consider some of the code used in the Typedef reductions section already covered: +
+ ++typedef int Integer; +typedef Integer Row4[4]; +void foo(Row4 rows[10]); ++
+A sample of the debugging output is shown below for the "in" typemap: +
+ ++swig -debug-tmsearch example.i +... +---- Searching for a suitable 'in' typemap for: Row4 rows[10] + Looking for: Row4 rows[10] + Looking for: Row4 [10] + Looking for: Row4 [ANY] + Looking for: Integer rows[10][4] + Looking for: Integer [10][4] + Looking for: Integer [ANY][ANY] + Looking for: int rows[10][4] + Looking for: int [10][4] + Looking for: int [ANY][ANY] + Looking for: SWIGTYPE rows[ANY][ANY] + Looking for: SWIGTYPE [ANY][ANY] + Looking for: SWIGTYPE rows[ANY][] + Looking for: SWIGTYPE [ANY][] + Looking for: SWIGTYPE *rows[ANY] + Looking for: SWIGTYPE *[ANY] + Looking for: SWIGTYPE rows[ANY] + Looking for: SWIGTYPE [ANY] + Looking for: SWIGTYPE rows[] + Looking for: SWIGTYPE [] + Using: %typemap(in) SWIGTYPE [] +... ++
+showing that the best default match supplied by SWIG is the SWIGTYPE [] typemap. +As the example shows, the successful match displays just the typemap method name and type in this format: %typemap(method) type. +This information might meet your debugging needs, however, you might want to analyze further. +If you next invoke SWIG with the -E option to display the preprocessed output, and search for this particular typemap, +you'll find the full typemap contents (example shown below for Python): +
+ +
+%typemap(in, noblock=1) SWIGTYPE [] (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" "', argument " "$argnum"" of type '" "$type""'");
+ }
+ $1 = ($ltype)(argp);
+}
+
++The generated code for the foo wrapper will then contain the snippets of the typemap with the special variables expanded. +The rest of this chapter will need reading though to fully understand all of this, however, the relevant parts of the generated code for the above typemap can be seen below: +
+ +
+SWIGINTERN PyObject *_wrap_foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+...
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+...
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_a_4__int, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "foo" "', argument " "1"" of type '" "int [10][4]""'");
+ }
+ arg1 = (int (*)[4])(argp1);
+...
+}
+
+The code within typemaps is usually language dependent, -however, many languages support the same typemaps. +however, many target languages support the same typemaps. In order to distinguish typemaps across different languages, the preprocessor should be used. For example, the "in" typemap for Perl and Ruby could be written as:
@@ -3220,7 +3319,7 @@ language modules.The run-time type checker is used by many, but not all, of SWIG's supported target languages. The run-time type checker features -are not required and are thus not used for strongly typed languages such as Java and C#. +are not required and are thus not used for statically typed languages such as Java and C#. The scripting and scheme based languages rely on it and it forms a critical part of SWIG's operation for these languages.
diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index 4903416cd..9194d39a0 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -69,7 +69,8 @@ static const char *usage1 = (const char *) "\ -debug-template - Display information for debugging templates\n\ -debug-top