diff --git a/SWIG/CHANGES b/SWIG/CHANGES
index 28d5707bd..9f40f843f 100644
--- a/SWIG/CHANGES
+++ b/SWIG/CHANGES
@@ -3,6 +3,14 @@ SWIG (Simplified Wrapper and Interface Generator)
Version 1.3 Alpha 4 (not yet released)
======================================
+7/22/00 : beazley
+ A variety of old type handling functions such as print_type(),
+ print_full(), print_mangle(), etc... are gone and have been
+ replaced with a smaller set of functions. See the file
+ Doc/internals.html for details. This will break all third
+ party language modules.
+ *** POTENTIAL INCOMPATIBILITY ***
+
7/20/00 : beazley
Deprecated the %val and %out directives. These directives
shouldn't really be necessary since typemaps can be used
diff --git a/SWIG/Doc/internals.html b/SWIG/Doc/internals.html
index 4eb0b2ea9..dfa8ed83f 100644
--- a/SWIG/Doc/internals.html
+++ b/SWIG/Doc/internals.html
@@ -192,7 +192,7 @@ which uses the callbacks registered by SWIG_main() above.
4. Parsing
5. Difference Between SWIG 1.1 and SWIG 1.3
6. Plans for SWIG 2.0
-7. Reserved
+7. C/C++ Wrapper Support Functions
8. Reserved
9. Reserved
10. Guile Support
@@ -461,7 +461,7 @@ of which must be reassignable types since they are the targets of conversions fr
representation.
-
DataType_caststr(DataType *t, char *name).
+DataType_rcaststr(DataType *t, char *name).
This function produces a string
that casts a type produced by the lstr() function to the type produced by the
str() function. You might view it as the inverse of lstr(). This function only produces
@@ -470,7 +470,7 @@ name can be supplied when the cast is to be applied to a specific name. Exampl
-Original Datatype caststr()
+Original Datatype rcaststr()
------------------ ---------
char *a
const char *a (const char *) name
@@ -480,6 +480,27 @@ double &a (double &) *name
+
+
+
DataType_lcaststr(DataType *t, char *name).
+
This function produces a string
+that casts a type produced by the str() function to the type produced by the
+lstr() function. This function only produces
+output when it needs to (when str() and lstr() produce different results). Furthermore, an optional
+name can be supplied when the cast is to be applied to a specific name.
+
+
+
+Original Datatype lcaststr()
+------------------ ---------
+char *a
+const char *a (char *) name
+double a[20] (double *) name
+double a[20][30] (double *) name
+double &a (double *) &name
+
+
+
DataType_manglestr(DataType *t).
Produces a type-string that is used to identify this datatype in the target scripting language.
@@ -489,7 +510,6 @@ references, and arrays---producing a mangled version of the type produced by the
-
The following example illustrates the intended use of the above functions when creating wrapper
functions using shorthand pseudocode. Suppose you had a function like this:
@@ -577,9 +597,203 @@ repeated calls without making any copies.
[TODO]
-7. Reserved
+7. C/C++ Wrapper Support Functions
+Added: Dave Beazley (July 22, 2000)
+
+
+When generating wrappers, SWIG tries to provide a mostly
+seamless with the original code. However, there are a number of
+problematic features of C/C++ that are handled in the following manner:
+
+
+- Passing and returning structures by value. When used, SWIG converts
+all pass-by-value functions into wrappers that pass by reference. For example:
+
+
+
+double dot_product(Vector a, Vector b);
+
+
+
+gets turned into a wrapper like this:
+
+
+
+double wrap_dot_product(Vector *a, Vector *b) {
+ return dot_product(*a,*b);
+}
+
+
+
+Functions that return by value require a memory allocation to store the result. For example:
+
+
+
+Vector cross_product(Vector *a, Vector *b);
+
+
+
+become
+
+
+
+Vector *wrap_cross_product(Vector *a, Vector *b) {
+ Vector *result = (Vector *) malloc(sizeof(Vector));
+ *result = cross_product(a,b);
+ return result;
+}
+
+
+
+Note: If C++ is being wrapped, the default copy constructor is used
+instead of malloc() to create a copy of the return result.
+
+
+
- C++ references. C++ references are handled exactly the same as
+pass/return by value except that a memory allocation is not made for functions
+that return a reference.
+
+
+
- Qualifiers such as "const" and "volatile". SWIG strips all
+qualifiers from the interface presented to the target language.
+Besides, what in the heck is "const" in Perl anyways?
+
+
+
+All of these transformations are handled by a collection of functions found
+in the file Source/Swig/cwrap.c.
+
+
+-
+char *Swig_clocal(DataType *t, char *name, char *value)
+This function creates a string containing the declaration of a local variable with
+type t, name name, and default value value. This local
+variable is stripped of all qualifiers and will be a pointer if the type is a reference
+or user defined type.
+
+
+
- char *Swig_clocal_deref(DataType *t, char *name)
+This function is the inverse of the clocal() function. Given a type and a name,
+it produces a string containing the code needed to cast/convert the type produced by
+Swig_clocal() back into it's original type.
+
+
+
- char *Swig_clocal_assign(DataType *t, char *name)
+Given a type and name, this produces a string containing the code (and an optional cast)
+needed to make an assignment from the real datatype to the local datatype produced
+by Swig_clocal(). Kind of the opposite of deref().
+
+
+
- int Swig_cargs(Wrapper *w, ParmList *l)
+Given a wrapper function object and a list of parameters, this function declares a set
+of local variables for holding all of the parameter values (using Swig_clocal()). Returns
+the number of parameters. In addition, this function sets the local name of each parameter
+which can be retrieved using the Parm_Getlname() function.
+
+
+
- void Swig_cresult(Wrapper *w, DataType *t, char *resultname, char *decl)
+Generates the code needed to set the result of a wrapper function and performs all of
+the needed memory allocations for ANSI C (if necessary). t is the type of the
+result, resultname is the name of the result variable, and decl is
+a string that contains the C code which produces the result.
+
+
+
- void Swig_cppresult(Wrapper *w, DataType *t, char *resultname, char *decl)
+Generates the code needed to set the result of a wrapper function and performs all of
+the needed memory allocations for C++ (if necessary). t is the type of the
+result, resultname is the name of the result variable, and decl is
+a string that contains the C code which produces the result.
+
+
+
- char *Swig_cfunction(char *name, ParmList *parms)
+This function produces a string containing the code needed to call a C function.
+The string that is produced contains all of the transformations needed to convert
+pass-by-value into pass-by-reference as well as handle C++ references. Produces
+a string like "name(arg0, arg1, ..., argn)".
+
+
+
- char *Swig_cmethod(char *name, ParmList *parms)
+This function produces a string containing the code needed to call a C++ class
+method. parms should be a complete list of arguments where the first
+argument is the "this" variable. Produces a string like "arg0->name(arg1, ..., argn)".
+
+
+
+Here is a short example showing how these functions could be used. Suppose you had a
+C function like this:
+
+
+
+double dot_product(Vector a, Vector b);
+
+
+
+Here's how you might write a really simple wrapper function
+
+
+
+ParmList *l = ... parameter list of the function ...
+DataType *t = ... return type of the function ...
+char *name = ... name of the function ...
+Wrapper *w = NewWrapper();
+Printf(w->def,"void wrap_%s() {\n", name);
+
+/* Declare all of the local variables */
+Swig_cargs(w, l);
+
+/* Convert all of the arguments */
+...
+
+/* Make the function call and declare the result variable */
+Swig_cresult(w,t,"result",Swig_cfunction(name,l));
+
+/* Convert the result into whatever */
+...
+
+Printf(w->code,"}\n");
+Wrapper_print(w,out);
+
+
+
+The output of this would appear as follows:
+
+
+
+void wrap_dot_product() {
+ Vector *arg0;
+ Vector *arg1;
+ double result;
+
+ ...
+ result = dot_product(*arg0, *arg1);
+ ...
+}
+
+
+
+Notice that the Swig_cargs(), Swig_cresult(), and Swig_cfunction() functions
+have taken care of the type conversions for the Vector type automatically.
+
+
+Notes:
+
+- The intent of these functions is to provide consistent handling of function parameters
+and return values so that language module writers don't have to worry about it too much.
+
+
+
- These functions may be superceded by features in the new typemap system which provide hooks
+for specifying local variable declarations and argument conversions.
+
+
+
+
+
+
+
+
+
8. Reserved