From df8516b78200789ccf3f69153e4f87817dcbf9d3 Mon Sep 17 00:00:00 2001
From: John Lenz
The purpose of the C# module is to offer an automated way of accessing existing C/C++ code from .NET languages.
@@ -26,7 +38,9 @@ Swig C# works equally well on non-Microsoft operating systems such as Linux, Sol
Mono and Portable.NET.
The C# module is very similar to the Java module, so until some more complete documentation has been written,
please use the Java documentation as a guide to using SWIG with C#.
@@ -170,7 +184,9 @@ Windows users can also get the examples working using a
Cygwin or MinGW environment for automatic configuration of the example makefiles.
Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path.
-
It is possible to throw a C# Exception from C/C++ code.
SWIG already provides the framework for throwing C# exceptions if it is able to detect that a C++ exception could be thrown.
@@ -264,7 +280,9 @@ set so should only be used when a C# exception is not created.
Lets say we have the following simple C++ method:
16 SWIG and C#
Introduction
+16.1 Introduction
+
Differences to the Java module
+16.2 Differences to the Java module
+
+
C# Exceptions
+16.3 C# Exceptions
+
+
C# exception example using "check" typemap
+16.3.1 C# exception example using "check" typemap
+
+
Let's consider a similar, but more common example that throws a C++ exception from within a wrapped function. We can use %exception as mentioned in Exception handling with %exception. @@ -499,7 +519,8 @@ The managed code generated does check for the pending exception as mentioned ear -
When C++ exception specifications are used, SWIG is able to detect that the method might throw an exception. @@ -555,7 +576,8 @@ DllExport void SWIGSTDCALL CSharp_evensonly(int jarg1) { Multiple catch handlers are generated should there be more than one exception specifications declared.
-This example involves a user defined exception. diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html index 8d1fbffb4..bf132b987 100644 --- a/Doc/Manual/Chicken.html +++ b/Doc/Manual/Chicken.html @@ -35,9 +35,9 @@
You may want to look at any of the examples in Examples/chicken/ or Examples/GIFPlot/Chicken for the basic steps to run SWIG CHICKEN. - - We will generically refer to the wrapper as the - generated files. - -
+could be run with
-(handle-exceptions exvar (if (= exvar 15) (print "Correct!") (print "Threw something else " exvar)) (test-throw 1)) +(handle-exceptions exvar + (if (= exvar 15) + (print "Correct!") + (print "Threw something else " exvar)) + (test-throw 1))
If the owner flag in the SWIG_NewPointerObj is 1, NewPointerObj will add a +
If the owner flag passed to SWIG_NewPointerObj is 1, NewPointerObj will add a
finalizer to the type which will call the destructor or delete method of
that type. The destructor and delete functions are no longer exported for
- use in scheme code, instead SWIG and chicken completly manage pointers.
-
In situations where SWIG knows that a function is returning a type that should
+ use in scheme code, instead SWIG and chicken manage pointers.
+ In situations where SWIG knows that a function is returning a type that should
be garbage collected, SWIG will automaticly set the owner flag to 1. For other functions,
- The %newobject directive must be specified for functions whose return values
+ the %newobject directive must be specified for functions whose return values
should be garbage collected. See
Object ownership and %newobject for more information.
In situations where a C or C++ function will assume ownership of a pointer, and thus
- chicken should no longer garbage collect this type, SWIG provides the DISOWN input typemap.
- After applying this typemap (see the Typemaps chapter for more information on how to apply typemaps),
+ chicken should no longer garbage collect it, SWIG provides the DISOWN input typemap.
+ After applying this typemap (see the Typemaps chapter for more information on how to apply typemaps),
any pointer that gets passed in will no longer be garbage collected.
- An object is disowned by passing the SWIG_POINTER_DISOWN flag to SWIG_ConvertPtr.
+ An object is disowned by passing the SWIG_POINTER_DISOWN flag to SWIG_ConvertPtr.
Warning: Since the lifetime of the object is now controlled by the underlying code, the object might
get deleted while the scheme code still holds a pointer to it. Further use of this pointer
can lead to a crash.
Adding a finalizer function from C code was added to chicken in the 1.89 release, so garbage collection
+ does not work for chicken versions below 1.89. If you would like the SWIG generated code to work with
+ chicken 1.40 to 1.89, pass the -nocollection argument to SWIG. This will not export code
+ inside the _wrap.c file to register finalizers, and will then export destructor functions which
+ must be called manually.
+