- Improve the runtime type sytesm

- Update all languages to new type system
- Add DohSortList function
- Fix mzscheme Examples/Makefile


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6930 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2005-02-01 00:08:24 +00:00
commit f6964f285f
48 changed files with 1380 additions and 1018 deletions

View file

@ -1,6 +1,52 @@
Version 1.3.25 (In progress)
============================
01/31/2005: wuzzeb (John Lenz)
- Add DohSortList to DOH
- Improve the runtime type system:
+ Speed. Type loading is now O(n log n) instead of O(N^2), which
for large modules is a huge improvement.
+ A whole bunch of functions in swigrun.swg no longer need the
swig_type_list_handle passed to them. The only one left is
TypeQuery. This also makes runtime.swg a lot smaller.
+ Split up swig_type_info structure into two structures
(swig_type_info and swig_cast_info)
+ Store a pointer to a swig_type_info rather than just the type
name string in the linked list of casts. First off, this makes
the guile module a little faster, and second, the
SWIG_TypeClientData() function is faster too.
+ Add the idea of a module into the type system. Before, all the
types were stored in one huge linked list. Now, another level is
added, and the type system stores a linked list of modules, each
of which stores an array of types associated with it.
+ For more information of how the runtime type system now works,
please see Doc/Manual/typemaps.html and Doc/Devel/runtime.txt
- Update all language modules to use the new type system. The changes
to each language module are minor. All languages are now able to
use runtime.swg for external access to the type system. Before
only python and perl did.
- [guile, mzscheme, ocaml, and php4] These languages opened up the
init function inside the .cxx code, and any code in the .swg files
in the init section was inside this function. This was a problem
for swiginit.swg, which needs to be inserted before the SWIG_init
function is opened. Thus I changed these languages to be like
python or perl, where the init function is declared in the .swg
file.
- [Ruby] Instead of moving the init function to the .swg file, I
added a new section initbeforefunc, and then added
%insert(initbeforefunc) "swiginit.swg"
- [MzScheme] Fix enums and fix Examples/Makefile.in so that if
multiple -I arguments are specified in the INCLUDES variable, each
gets a ++ccf.
- [Guile GH] Update Guile GH to use the new type system. See
Doc/Devel/Guile.cxx for how smobs are now used.
01/11/2005: wsfulton
[C#] New typemap called 'csconstruct'. The code in this typemaps was previously hard
coded and could not be customised by a user. This typemap contains the code that is

152
SWIG/Doc/Devel/runtime.txt Normal file
View file

@ -0,0 +1,152 @@
This file describes the necissary functions and interfaces a language module
needs to implement to take advantage of the run time type system. I assume you
have read the run-time section of the Typemaps chapter in the SWIG
documentation.
Last updated: January 23, 2005
The file we are concerned with here should be named langrun.swg. A good example
of a simple file is the Lib/mzscheme/mzrun.swg file. First, a few requirements
and notes:
1) Every function in this file should be declared static.
2) It should be inserted into the runtime section of the _wrap file from your
config file. The Lib/swigrun.swg file should be included before this file.
That is, you need to have
%runtime "swigrun.swg"
%runtime "langrun.swg"
3) You must also include the swiginit.swg file in the init section of the
wrapper. That is, you should have
%insert(init) "swiginit.swg"
4) From module.cxx, you need to call the SwigType_emit_type_table function, as
well as register types with SwigType_remember or SwigType_remember_clientdata
5) By convention, all functions in this file are of the form
SWIG_Language_Whatever, and #defines are used to rename SWIG API functions to
these function names
6) You need to call void SWIG_InitializeModule(void *clientdata) from your init
function.
-------------------------------------------------------------------------------
Required Functions
-------------------------------------------------------------------------------
swig_module_info *SWIG_GetModule(void *clientdata);
void SWIG_SetModule(void *clientdata, swig_module_info *mod);
The SetModule function should store the mod argument into some globally
accessable variable in the target language. The action of these two functions
is to provide a way for multiple modules to share information. The SetModule
function should create a new global var named something like
"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME
SWIG_RUNTIME_VERSION is currently defined as "2", and SWIG_TYPE_TABLE_NAME is
defined by the -DSWIG_TYPE_TABLE=mytable option when compiling the wrapper.
Alternativly, if the language supports modules, a module named
"swig_runtime_data" SWIG_RUNTIME_VERSION can be created, and a global variable
named "type_table" SWIG_TYPE_TABLE_NAME can be created inside it. The most
common approach is to store the mod pointer in some global variable in the
target language, but if the language provides an alternative place to store data
(like the chicken module), then that is good too.
The way the code is set up, SetModule should only be called when GetModule
returns NULL, and if SetModule is called a second time, the behavior is
undefined. Just make sure it doesn't crash in the random chance occurance that
SetModule is called twice.
There are two options here.
1) The perferred approach is for GetModule and SetModule to not require a
clientdata pointer. If you can at all avoid it, please do so. Here, you would
write swig_module_info *SWIG_Language_GetModule();
void SWIG_Language_SetModule(swig_module_info *mod);
and then add
#define SWIG_GetModule(clientdata) SWIG_Language_GetModule()
#define SWIG_SetModule(cd, ptr) SWIG_Language_SetModule(ptr)
You would then call
SWIG_InitializeModule(0)
2) If GetModule and SetModule need to take a custom pointer (most notably an
environment pointer, see tcl or mzscheme), then you should write
swig_module_info *SWIG_Language_GetModule(void *clientdata)
void SWIG_Langauge_SetModule(void *clientdata, swig_module_info *mod);
and also define
#define SWIG_GetModule(cd) SWIG_Langauge_GetModule(cd)
#define SWIG_SetModule(cd, ptr) SWIG_Language_SetModule(cd, ptr)
#define SWIG_MODULE_CLIENTDATA_TYPE Whatever
SWIG_MODULE_CLIENTDATA_TYPE should be defined to whatever the type of
clientdata is.
You would then call SWIG_InitializeModule(clientdata), and clientdata would get
passed to GetModule and SetModule. clientdata will not be stored and will only
be referenced during the InitializeModule call. After InitializeModule returns,
clientdata does not need to be valid any more.
This method is not preferred, because it makes external access to the type
system more complicated. See the Modules chapter of the documentation, and read
the "External access to the run-time" section. Then take a look at
Lib/runtime.swg. Anybody that calls SWIG_TypeQuery needs to pass along the
clientdata pointer, and that is the reason for defining
SWIG_MODULE_CLIENTDATA_TYPE.
-------------------------------------------------------------------------------
Standard Functions
-------------------------------------------------------------------------------
These functions are not required and their API is not formalized, but almost all
language modules implement them for consistancy across languages. Throughout
this discussion, I will use LangType to represent the underlying language type
(C_word in chicken, Scheme_Object * in mzscheme, PyObject * in python, etc)
LangObj SWIG_NewPointerObj(void *ptr, swig_type_info *type, int flags);
Create and return a new pointer object that has both ptr and type. For almost
all language modules, flags is used for ownership. If flags==1, then the
created pointer should be registered to be garbage collected.
int SWIG_ConvertPtr(LangType obj, void **result, swig_type_info *type, int flags);
Convert a language wrapped pointer into a void *. The pointer is returned in
result, and the function should return 0 on success, non-zero on error.
A sample ConvertPtr is given here:
swig_cast_info *cast;
if (<obj is a wrapped pointer type>) {
cast = SWIG_TypeCheck(<obj type name>, type);
cast = SWIG_TypeCheckStruct(<obj type structure>, type);
if (cast) {
*result = SWIG_TypeCast(cast, <obj pointer>);
return 0;
}
}
return 1;
Either TypeCheck or TypeCheckStruct can be called, depending on how the pointer
is wrapped in langtype. If obj stores the void pointer and the type name, then
the TypeCheck function should be used, while if obj stores the void pointer and
a pointer to the swig_type_info structure, then the TypeCheckStruct function
should be called. The TypeCheckStruct is slightly faster, since it does a
pointer comparison instead of a strcmp.
void *SWIG_MustGetPtr(LangType obj, swig_type_info *type, int flags,
int argnum, const char *func_name) {
void *result;
if (SWIG_ConvertPtr(s, &result, type, flags)) {
generate runtime type error ("Error in func_name, expected a" +
type->str ? type->str : "void *" +
"at argument number" + argnum);
}
return result;
}
This function is optional, and the number and type of parameters can be
different, but is useful for typemap purposes:
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 0, $argnum, FUNC_NAME);
}

View file

@ -388,28 +388,36 @@ If the Scheme object passed was not a SWIG smob representing a compatible
pointer, a <code>wrong-type-arg</code> exception is raised.
<H3><a name="Guile_nn13"></a>18.6.1 GH Smobs</H3>
<p>
In earlier versions of SWIG, C pointers were represented as Scheme
strings containing a hexadecimal rendering of the pointer value and a
mangled type name. As Guile allows registering user types, so-called
"smobs" (small objects), a much cleaner representation has been
implemented now. The details will be discussed in the following.
</p>
<p>
A smob is a cons cell where the lower half of the CAR contains the
smob type tag, while the upper half of the CAR and the whole CDR are
available. <code>SWIG_Guile_Init()</code> registers a smob type named
"swig" with Guile; its type tag is stored in the variable
<code>swig_tag</code>. The upper half of the CAR store an index into
a table of all C pointer types seen so far, to which new types seen
are appended. The CDR stores the pointer value.
<p> A smob is a cons cell where the lower half of the CAR contains the smob type
tag, while the upper half of the CAR and the whole CDR are available. Every
module creates its own smob type in the clientdata field of the module. So the
lower 16 bits of the car of the smob store the tag and the upper 16 bits store
the index this type is in the array. We can then, given a smob, find its
swig_type_info struct by using the tag (lower 16 bits of car) to find which
module this type is in (since each tag is unique for the module). Then we use
the upper 16 bits to index into the array of types attached to this module.
Looking up the module from the tag is worst case O(# of modules) but average
case O(1). This is because the modules are stored in a circularly linked list,
and when we start searching the modules for the tag, we start looking with the
module that the function doing the lookup is in. SWIG_Guile_ConvertPtr() takes
as its first argument the swig_module_info * of the calling function, which is
where we start comparing tags. Most types will be looked up in the same module
that created them, so the first module we check will most likely be correct.
Once we have a swig_type_info structure, we loop through the linked list of
casts, using pointer comparisons.</p>
<H3><a name="Guile_nn14"></a>18.6.2 SCM Smobs</H3>
<p>The SCM interface (using the "-scm" argument to swig) uses common.swg.
<p>The SCM interface (using the "-scm" argument to swig) uses swigrun.swg.
The whole type system, when it is first initialized, creates two smobs named "swig" and "collected_swig".
The swig smob is used for non-garbage collected smobs, while the collected_swig smob is used as described
below. Each smob has the same format, which is a double cell created by SCM_NEWSMOB2()

View file

@ -9,9 +9,10 @@
<!-- INDEX -->
<ul>
<li><a href="#Modules_nn2">The SWIG runtime code</a>
<li><a href="#Modules_nn3">A word of caution about static libraries</a>
<li><a href="#Modules_nn4">References</a>
<li><a href="#Modules_nn5">Reducing the wrapper file size</a>
<li><a href="#external_run_time">External access to runtime system</a>
<li><a href="#Modules_nn4">A word of caution about static libraries</a>
<li><a href="#Modules_nn5">References</a>
<li><a href="#Modules_nn6">Reducing the wrapper file size</a>
</ul>
<!-- INDEX -->
@ -68,7 +69,52 @@ Be careful if you use threads and the automatic module loading that some scripti
languages provide. One solution is to load all modules before spawning any threads.
</p>
<H2><a name="Modules_nn3"></a>15.2 A word of caution about static libraries</H2>
<H2><a name="external_run_time"></a>15.2 External access to the run-time system</a></H2>
<p>As described in <a href="Typemaps.html#runtime_type_checker">The run-time type checker</a>,
the functions <tt>SWIG_TypeQuery</tt>, <tt>SWIG_NewPointerObj</tt>, and others sometimes need
to be called. Calling these functions from a typemap is supported, since the typemap code
is embedded into the <tt>_wrap.c</tt> file, which has those declerations available. If you need
to call the SWIG run-time functions from another C file, there are three headers you need
to include. They are located in the Lib directory in the SWIG source, or wherever the
SWIG Library was installed. You can see the current library path by running
<tt>swig -swiglib</tt>.</p>
<blockquote><pre>
#include &lt;swigrun.swg&gt;
#include &lt;python/pyrun.swg&gt; /* Or other header, see below */
#include &lt;runtime.swg&gt;
</pre></blockquote>
<p>After including these three headers, your code should be able to call <tt>SWIG_TypeQuery</tt>,
<tt>SWIG_NewPointerObj</tt>, <tt>SWIG_ConvertPtr</tt> and others. The exact argument paramaters
for these functions might differ between language modules; please check the language module chapters
for more information.</p>
<p>Inside these headers the functions are declared static and are included inline into the file,
and thus the file does not need to be linked against any SWIG libraries or code (you might still
need to link against the language libraries like libpython-2.3). Data is shared between this
file and the _wrap.c files through a global variable in the wrapping language. It is also
possible to copy these three header files into your own package for distribution along with
the generated wrapper files, so that you can distribute a package that can be compiled
without SWIG installed (this works because the header files are self contained, and do not
need to link with anything).</p>
<p>The headers that should be included in place of the #include &lt;python/pyrun.swg&gt;
for the different language modules are:</p>
<ul>
<li>Chicken - &lt;chicken/chickenrun.swg&gt;</li>
<li>Guile (scm) - &lt;guile/guile_scm_run.swg&gt;</li>
<li>Guile (gh) - This does not work with the -gh API, use the -scm API</li>
<li>MzScheme - &lt;mzscheme/mzrun.swg&gt;</li>
<li>Ocaml - &lt;ocaml/ocaml.swg&gt;</li>
<li>Python - &lt;python/pyrun.swg&gt;</li>
<li>Perl5 - &lt;perl5/perlrun.swg&gt;</li>
<li>Ruby - &lt;ruby/rubydef.swg&gt;</li>
<li>Tcl - &lt;tcl/swigtcl8.swg&gt;</li>
</ul>
<H2><a name="Modules_nn4"></a>15.3 A word of caution about static libraries</H2>
When working with multiple SWIG modules, you should take care not to use static
@ -77,13 +123,13 @@ of SWIG modules with that library, each module will get its own private copy of
into it. This is very often <b>NOT</b> what you want and it can lead to unexpected or bizarre program
behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libaries.
<H2><a name="Modules_nn4"></a>15.3 References</H2>
<H2><a name="Modules_nn5"></a>15.4 References</H2>
Due to the complexity of working with shared libraries and multiple modules, it might be a good idea to consult
an outside reference. John Levine's "Linkers and Loaders" is highly recommended.
<H2><a name="Modules_nn5"></a>15.4 Reducing the wrapper file size</H2>
<H2><a name="Modules_nn6"></a>15.5 Reducing the wrapper file size</H2>
<p>

View file

@ -2540,6 +2540,24 @@ ordering (and perform conversions if needed).
<H2><a name="runtime_type_checker"></a>10.8 The run-time type checker</H2>
Most scripting languages need type information at run-time. This type information
can include how to construct types, how to garbage collect types, and the inheritance
relationships between types. If the language interface does not provide its own type
information storage, the generated SWIG code needs to provide it.<br><br>
Requirements for the type system:<br>
<li>Store inheritance and type equivalence information and be able to correctly
re-create the type pointer.</li>
<li>Share type information between modules.</li>
<li>Modules can be loaded in any order, irregardless of actual type
dependency.</li>
<li>Avoid the use of dynamically allocated memory, and library/system calls in general.</li>
<li>Provide a reasonably fast implementation, minimizing the lookup time for all
language modules.</li>
<li>Custom, language specific information can be attached to types.</li>
<li>Modules can be unloaded from the type system.</li>
<H3>8.8.1 Implementation</H3>
<p>
The run-time type checker is used by many, but not all, of SWIG's supported target languages.
@ -2628,7 +2646,90 @@ pointer. However, the exact name and calling conventions of the conversion
function depends on the target language (see language specific chapters for details).
<p>
When pointers are converted in a typemap, the typemap code often looks
The actual type code is in swigrun.swg, and gets inserted near the top of the generated
swig wrapper file. The phrase "a type X that can cast into a type Y" means
that given a type X, it can be converted into a type Y. In other words, X is a derived
class of Y or X is a typedef of Y. The structure to store type information looks like this:
<blockquote>
<pre>
/* Structure to store information on one type */
typedef struct swig_type_info {
const char *name; /* mangled name of this type */
const char *str; /* human readable name for this type */
swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
struct swig_cast_info *cast; /* Linked list of types that can cast into this type */
void *clientdata; /* Language specific type data */
} swig_type_info;
/* Structure to store a type and conversion function used for casting */
typedef struct swig_cast_info {
swig_type_info *type; /* pointer to type that is equivalent to this type */
swig_converter_func converter; /* function to cast the void pointers */
struct swig_cast_info *next; /* pointer to next cast in linked list */
struct swig_cast_info *prev; /* pointer to the previous cast */
} swig_cast_info;
</pre>
</blockquote>
Each <tt>swig_type_info</tt> stores a linked list of types that it is equivalent to. Each entry in this
doubly linked list stores a pointer back to another swig_type_info structure,
along with a pointer to a conversion function. This conversion function is used
to solve the above problem of the FooBar class, correctly returning a pointer to
the type we want.
<p>
The basic problem we need to solve is verifying and building arguments passed to functions.
So going back to the <tt>SWIG_ConvertPtr()</tt> function example from above, we are
expecting a <tt>Foo *</tt> and need to
check if <tt>obj0</tt> is in fact a <tt>Foo *</tt>. From before, <tt>SWIGTYPE_p_Foo</tt> is just
a pointer to the <tt>swig_type_info</tt> structure describing <tt>Foo *</tt>. So we loop though the
linked list of <tt>swig_cast_info</tt> structures attached to <tt>SWIGTYPE_p_Foo</tt>. If we see that the type of <tt>obj0</tt> is in the
linked list, we pass the object through the associated conversion function and
then return a positive. If we reach the end of the linked list without a match,
then <tt>obj0</tt> can not be converted to a <tt>Foo *</tt> and an error is generated.
<p>
Another issue needing to be addressed is sharing type information between multiple modules.
More explicitly, we need
to have ONE <tt>swig_type_info</tt> for each type. If two modules both use the type, the
second module loaded must lookup and use the swig_type_info structure from the module already loaded.
Because no dynamic memory is used and the circular dependencies of the
casting information, loading the type information is somewhat tricky, and not explained here.
A complete description is in the <tt>common.swg</tt> file (and near the top of any generated file).
<br><br>
Each module has one swig_module_info structure which looks like this:
<blockquote>
<pre>
/* Structure used to store module information
* Each module generates one structure like this, and the runtime collects
* all of these structures and stores them in a circularly linked list.*/
typedef struct swig_module_info {
swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
int size; /* Number of types in this module */
struct swig_module_info *next; /* Pointer to next element in circularly linked list */
swig_type_info **type_initial; /* Array of initially generated type structures */
swig_cast_info **cast_initial; /* Array of initially generated casting structures */
void *clientdata; /* Language specific module data */
} swig_module_info;
</pre>
</blockquote>
Each module stores an array of pointers to <tt>swig_type_info</tt> structures and the number of
types in this module. So when a second module is loaded, it finds the <tt>swig_module_info</tt>
structure for the first module and searches the array of types. If any of its own
types are in the first module and have already been loaded, it uses those <tt>swig_type_info</tt>
structures rather than creating new ones. These <tt>swig_module_info</tt>
structures are chained together in a circularly linked list.
<a name="n43"></a><H3>8.8.2 Usage</H3>
<p>This section covers how to use these functions from typemaps. To learn how to
call these functions from external files (not the generated _wrap.c file), see
the <a href="Modules.html#external_run_time">External access to the run-time system</a>
section.</p>
<p>When pointers are converted in a typemap, the typemap code often looks
similar to this:
</p>

View file

@ -433,12 +433,12 @@ MZSCHEME_SO = @MZSCHEME_SO@
mzscheme: $(SRCS)
$(SWIG) -mzscheme $(SWIGOPT) $(INTERFACE)
$(MZC) ++ccf "$(INCLUDES)" --cc $(ISRCS) $(SRCS)
$(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ISRCS) $(SRCS)
$(MZC) --ld $(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS)
mzscheme_cpp: $(SRCS)
$(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACE)
$(MZC) ++ccf "$(INCLUDES)" --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS)
$(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS)
$(CXXSHARED) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)
# -----------------------------------------------------------------

View file

@ -11,7 +11,6 @@
%}
%insert(runtime) "swigrun.swg"; // Common C API type-checking code
%insert(runtime) "common.swg"; // Common type-checking code
%insert(runtime) "chickenrun.swg"; // CHICKEN run-time code
/* -----------------------------------------------------------------------------
@ -583,12 +582,12 @@ SWIGEXPORT(void) SWIG_init(int, C_word, C_word) C_noret;
%insert(closprefix) "swigclosprefix.scm"
%insert(init) "swiginit.swg"
%insert(init) %{
/* CHICKEN initialization function */
static char *swig_type_ptr_name = "type_pointer" SWIG_TYPE_TABLE_NAME;
SWIGEXPORT(void)
SWIG_init(int argc, C_word closure, C_word continuation) {
static int typeinit = 0;
int i;
C_word sym;
C_word tmp;
@ -596,32 +595,9 @@ SWIG_init(int argc, C_word closure, C_word continuation) {
C_word ret;
C_word *return_vec;
if (!typeinit) {
/* lookup the type pointer... it is stored in it's own symbol table */
C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
if (stable != NULL) {
sym = SWIG_Chicken_LookupSymbol(swig_type_ptr_name, stable);
if (C_truep(sym) && C_swig_is_ptr(sym)) {
swig_type_list_handle = (swig_type_info **) C_block_item(sym, 0);
}
} else {
C_word *a = C_alloc(C_SIZEOF_POINTER + C_SIZEOF_INTERNED_SYMBOL(C_strlen(swig_type_ptr_name)));
stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16);
sym = C_intern_in(&a, C_strlen(swig_type_ptr_name), swig_type_ptr_name, stable);
C_mutate(&C_block_item(sym, 0), C_mpointer(&a, (void *) swig_type_list_handle));
}
for (i = 0; swig_types_initial[i]; i++) {
swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
for (i = 0; swig_types_initial[i]; i++) {
SWIG_PropagateClientData(swig_types[i]);
}
typeinit = 1;
ret = C_SCHEME_TRUE;
} else {
ret = C_SCHEME_FALSE;
}
SWIG_InitializeModule(0);
SWIG_PropagateClientData();
ret = C_SCHEME_TRUE;
#if $veclength
return_vec = C_alloc(C_SIZEOF_VECTOR($veclength));

View file

@ -28,6 +28,10 @@ extern "C" {
SWIG_Chicken_NewPointerObj((void*)ptr, type, owner, &known_space)
#define swig_barf SWIG_Chicken_Barf
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Chicken_SetModule(pointer)
#define C_swig_is_bool(x) C_truep (C_booleanp (x))
#define C_swig_is_char(x) C_truep (C_charp (x))
#define C_swig_is_fixnum(x) C_truep (C_fixnump (x))
@ -186,7 +190,7 @@ SWIG_Chicken_NewPointerObj(void *ptr, swig_type_info *type, int owner, C_word **
static int
SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags)
{
swig_type_info *cast;
swig_cast_info *cast;
swig_type_info *from;
if (s == C_SCHEME_FALSE) {
@ -196,7 +200,7 @@ SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags
from = (swig_type_info *) C_block_item(s, 1);
if (!from) return 1;
if (type) {
cast = SWIG_TypeCheck((char*)from->name, type);
cast = SWIG_TypeCheckStruct(from, type);
if (cast) {
*result = SWIG_TypeCast(cast, (void *) C_block_item(s, 0));
return 0;
@ -223,6 +227,48 @@ SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags)
return result;
}
static char *chicken_runtimevar_name = "type_pointer" SWIG_TYPE_TABLE_NAME;
static swig_module_info *
SWIG_Chicken_GetModule() {
swig_module_info *ret = 0;
C_word sym;
/* lookup the type pointer... it is stored in it's own symbol table */
C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
if (stable != NULL) {
sym = SWIG_Chicken_LookupSymbol(chicken_runtimevar_name, stable);
if (C_truep(sym) && C_swig_is_ptr(sym)) {
ret = (swig_module_info *) C_block_item(sym, 0);
}
}
return ret;
}
static void
SWIG_Chicken_SetModule(swig_module_info *module) {
C_word *a;
C_SYMBOL_TABLE *stable;
C_word sym;
C_word pointer;
static C_word *space = 0;
/* type pointer is stored in it's own symbol table */
stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION);
if (stable == NULL) {
stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16);
}
if (!space) {
space = (C_word *) C_malloc((C_SIZEOF_POINTER + C_SIZEOF_INTERNED_SYMBOL(C_strlen(chicken_runtimevar_name))) * sizeof(C_word));
}
a = space;
pointer = C_mpointer(&a, (void *) module);
sym = C_intern_in(&a, C_strlen(chicken_runtimevar_name), chicken_runtimevar_name, stable);
C_set_block_item(sym, 0, pointer);
}
#ifdef __cplusplus
}
#endif

View file

@ -1,71 +0,0 @@
/***********************************************************************
* common.swg
*
* This file contains generic SWIG runtime support for pointer
* type checking as well as a few commonly used macros to control
* external linkage.
*
* Author : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (c) 1999-2000, The University of Chicago
*
* This file may be freely redistributed without license or fee provided
* this copyright message remains intact.
************************************************************************/
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if !defined(STATIC_LINKED)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# define SWIGEXPORT(a) a
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************************/
/* The static type info list */
static swig_type_info *swig_type_list = 0;
static swig_type_info **swig_type_list_handle = &swig_type_list;
/* Register a type mapping with the type-checking */
static swig_type_info *
SWIG_TypeRegister(swig_type_info *ti) {
return SWIG_TypeRegisterTL(swig_type_list_handle, ti);
}
/* Search for a swig_type_info structure */
static swig_type_info *
SWIG_TypeQuery(const char *name) {
return SWIG_TypeQueryTL(*swig_type_list_handle, name);
}
/* Set the clientdata field for a type */
static void
SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
SWIG_TypeClientDataTL(*swig_type_list_handle, ti, clientdata);
}
/* This function will propagate the clientdata field of type to
* any new swig_type_info structures that have been added into the list
* of equivalent types. It is like calling
* SWIG_TypeClientData(type, clientdata) a second time.
*/
static void
SWIG_PropagateClientData(swig_type_info *type) {
SWIG_PropagateClientDataTL(*swig_type_list_handle, type);
}
#ifdef __cplusplus
}
#endif

View file

@ -5,16 +5,48 @@
#define SWIGGUILE_GH
%runtime "swigrun.swg"
%runtime "guile_gh_run.swg"
%include "guile.i"
%init %{
static int _swig_init = 0;
%runtime %{
if (!_swig_init) {
SWIG_Guile_RegisterTypes(swig_types, swig_types_initial);
_swig_init = 1;
}
/* scm_values was implemented on C level in 1.4.1, and the prototype
is not included in libguile.h, so play safe and lookup `values'... */
#define GUILE_MAYBE_VALUES \
if (gswig_list_p) \
gswig_result = gh_apply(gh_lookup("values"), gswig_result);
#define GUILE_MAYBE_VECTOR \
if (gswig_list_p) \
gswig_result = gh_list_to_vector(gswig_result);
#define SWIG_APPEND_VALUE(object) \
if (gswig_result == SCM_UNSPECIFIED) { \
gswig_result = object; \
} else { \
if (!gswig_list_p) { \
gswig_list_p = 1; \
gswig_result = gh_list(gswig_result, object, SCM_UNDEFINED); \
} \
else \
gswig_result = gh_append2(gswig_result, \
gh_list(object, SCM_UNDEFINED)); \
}
SWIG_Guile_Init();
%}
%init "swiginit.swg"
%init %{
static int _swig_module_smob_tag;
SWIG_GUILE_INIT_STATIC void
SWIG_init(void)
{
SWIG_InitializeModule(0);
swig_module.clientdata = (void *) &_swig_module_smob_tag;
SWIG_Guile_Init(&swig_module);
%}

View file

@ -3,9 +3,10 @@
* Lib/guile/guile_gh_run.swg
*
* Guile GH runtime file
* Copyright (C) 2000 Matthias Koeppe
* Copyright (C) 2004 John Lenz <lenz@cs.wisc.edu>
* ----------------------------------------------------------------------- */
#define SWIGGUILE
#include "guile/gh.h"
#include <stdio.h>
#include <string.h>
@ -15,16 +16,20 @@
extern "C" {
#endif
typedef SCM (*swig_guile_proc)();
#define SWIG_malloc(size) \
SCM_MUST_MALLOC(size)
#define SWIG_free(mem) \
scm_must_free(mem)
#define SWIG_ConvertPtr(s, result, type, flags) \
SWIG_Guile_GetPtr(s, result, type)
SWIG_Guile_ConvertPtr(&swig_module, s, result, type, flags)
#define SWIG_MustGetPtr(s, type, argnum, flags) \
SWIG_Guile_MustGetPtr(s, type, argnum, FUNC_NAME)
SWIG_Guile_MustGetPtr(&swig_module, s, type, argnum, flags, FUNC_NAME)
#define SWIG_NewPointerObj(ptr, type, owner) \
SWIG_Guile_MakePtr((void*)ptr, type)
SWIG_Guile_NewPointerObj(&swig_module, (void*)ptr, type, owner)
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)
/* Ignore object-ownership changes in gh mode */
#define SWIG_Guile_MarkPointerNoncollectable(s) (s)
@ -36,50 +41,24 @@ extern "C" {
(char *) FUNC_NAME, (char *) msg, \
SCM_EOL, SCM_BOOL_F); else
#if defined(SWIG_NOINCLUDE)
# define SWIGSTATIC
#elif defined(SWIG_GLOBAL)
# define SWIGSTATIC
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if defined(_MSC_VER) || defined(__GNUC__)
# if defined(STATIC_LINKED)
# define SWIGEXPORT(a) a
# else
# define SWIGEXPORT(a) __declspec(dllexport) a
# endif
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGSTATIC static
# define SWIGEXPORT(a) a
#endif
#define GH_NOT_PASSED SCM_UNDEFINED
#define GH_UNSPECIFIED SCM_UNSPECIFIED
#define SWIG_APPEND_VALUE(object) \
if (gswig_result == GH_UNSPECIFIED) \
gswig_result = object; \
else { \
if (!gswig_list_p) { \
gswig_list_p = 1; \
gswig_result = gh_list(gswig_result, object, GH_NOT_PASSED); \
} \
else \
gswig_result = gh_append2(gswig_result, \
gh_list(object, GH_NOT_PASSED)); \
}
#define GUILE_APPEND_RESULT SWIG_APPEND_VALUE
/* scm_values was implemented on C level in 1.4.1, and the prototype
is not included in libguile.h, so play safe and lookup `values'... */
#define GUILE_MAYBE_VALUES \
if (gswig_list_p) \
gswig_result = gh_apply(gh_lookup("values"), gswig_result);
#define GUILE_MAYBE_VECTOR \
if (gswig_list_p) \
gswig_result = gh_list_to_vector(gswig_result);
static char *
SWIG_scm2str (SCM s)
{
return gh_scm2newstr (s, NULL);
}
#define GSWIG_scm2str SWIG_scm2str
/* SCM_CHAR and SCM_CHARP were introduced in Guile 1.4; the following is for
1.3.4 compatibility. */
#ifndef SCM_CHAR
@ -98,298 +77,86 @@ GSWIG_scm2char (SCM s)
}
#define gh_scm2char GSWIG_scm2char
/* Interface function */
#define SWIG_scm2str(x) gh_scm2newstr(x, NULL)
/* More 1.3.4 compatibility */
#ifndef SCM_INPUT_PORT_P
# define SCM_INPUT_PORT_P SCM_INPORTP
# define SCM_OUTPUT_PORT_P SCM_OUTPORTP
#endif
/* Type system */
typedef void *(*swig_converter_func)(void *);
typedef struct swig_type_info *(*swig_dycast_func)(void **);
typedef struct SwigPtrType SwigPtrType;
typedef struct swig_type_info {
const char *name;
swig_converter_func converter;
const char *str;
void *clientdata;
swig_dycast_func dcast;
size_t tag;
int dummy;
} swig_type_info;
SWIGSTATIC void
SWIG_Guile_RegisterTypes (swig_type_info **table,
swig_type_info **init);
/* Register a new type-mapping with the type-checker. origtype is the
original datatype and newtype is an equivalent type. cast is optional
pointer to a function to cast pointer values between types (this is
typically used to cast pointers from derived classes to base classes in
C++). */
SWIGSTATIC void
SWIG_RegisterMapping (const char *origtype, const char *newtype,
swig_converter_func cast);
/* Dynamic pointer casting. Down an inheritance hierarchy */
SWIGSTATIC swig_type_info *
SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr);
/* Register SWIG smobs with Guile. */
SWIGSTATIC void
SWIG_Guile_Init();
/* Initialization function for this SWIG module; actually renamed by a
#define */
/* extern void SWIG_init(); */
/* Get a pointer value from a smob. If there is a type-mismatch,
return nonzero; on success, return 0. */
SWIGSTATIC int
SWIG_Guile_GetPtr (SCM s, void **result, swig_type_info *type);
/* Get a pointer value from a smob. If there is a type-mismatch,
signal a wrong-type-arg error for the given argument number. */
SWIGSTATIC void *
SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type,
int argnum, const char *func_name);
/* Make a smob from a pointer and typeinfo. */
SWIGSTATIC SCM
SWIG_Guile_MakePtr (void *ptr, swig_type_info *type);
/* Get arguments from an argument list */
SWIGSTATIC int
SWIG_Guile_GetArgs (SCM *dest, SCM rest,
int reqargs, int optargs,
const char *procname);
typedef SCM (*swig_guile_proc)();
#ifdef __cplusplus
static swig_type_info *SWIG_Guile_LookupType(swig_module_info *module, SCM s, int normal) {
swig_module_info *iter;
if (!module) return 0;
iter = module;
do {
if ((normal && (unsigned long) SCM_TYP16(s) == *((int *)iter->clientdata))) {
return iter->types[(long) SCM_CAR(s) >> 16];
}
iter = iter->next;
} while (iter != module);
return 0;
}
#ifdef SWIG_GLOBAL
#define SWIG_GUILE_MODULE_STATIC
#elif !defined(SWIG_NOINCLUDE)
#define SWIG_GUILE_MODULE_STATIC static
#endif
/* guiledec.swg ends here */
#ifndef SWIG_NOINCLUDE
/* SWIG pointer structure */
#ifdef __cplusplus
extern "C" {
#ifdef SWIG_GUILE_MODULE_STATIC
static swig_module_info *swig_guile_module = 0;
SWIG_GUILE_MODULE_STATIC swig_module_info *SWIG_Guile_GetModule() {
return swig_guile_module;
}
SWIG_GUILE_MODULE_STATIC void SWIG_Guile_SetModule(swig_module_info *pointer) {
swig_guile_module = pointer;
}
#else
SWIGEXPORT(swig_module_info *) SWIG_Guile_GetModule();
SWIGEXPORT(void) SWIG_Guile_SetModule(swig_module_info *pointer);
#endif
struct SwigCast {
unsigned short type; /* Index into SwigPtrTbl */
void *(*cast)(void *); /* Pointer casting function */
struct SwigCast *next; /* Linked list pointer */
};
struct SwigPtrType {
const char *name; /* Datatype name */
const char *prettyname; /* Pretty datatype name */
unsigned short tag; /* Index in SwigPtrTable */
struct SwigCast *cast; /* List of compatible types */
};
/* Some variables */
static int SwigPtrMax = 64; /* Max entries that can be held */
/* (may be adjusted dynamically) */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
/* Pointer table */
static SwigPtrType *SwigPtrList = 0; /* Table containing types and
equivalences; items will only
be appended */
static size_t *SwigPtrTbl = 0; /* Sorted indirect table; items will
be inserted */
/* Sort comparison function */
static int
swigsort (const void *data1, const void *data2)
{
size_t index1 = * (size_t *) data1;
size_t index2 = * (size_t *) data2;
return strcmp(SwigPtrList[index1].name, SwigPtrList[index2].name);
}
/* Register a new datatype with the type-checker */
SWIGSTATIC size_t
SWIG_RegisterType (const char *type, const char *prettyname)
{
int i;
/* Allocate the pointer table if necessary */
if (!SwigPtrList) {
SwigPtrList = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrTbl = (size_t *) malloc(SwigPtrMax*sizeof(size_t));
SwigPtrN = 0;
}
/* Grow the table if necessary */
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrList = (SwigPtrType *) realloc((char *) SwigPtrList,
SwigPtrMax*sizeof(SwigPtrType));
SwigPtrTbl = (size_t *) realloc((char *) SwigPtrTbl,
SwigPtrMax*sizeof(size_t));
}
/* Look up type */
for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrList[i].name,type) == 0) {
if (prettyname!=NULL)
SwigPtrList[i].prettyname = prettyname;
return i;
}
{
struct SwigPtrType *t;
size_t tag;
#if 0
fprintf(stderr, "New type: %s\n", type);
#endif
tag = SwigPtrTbl[SwigPtrN] = SwigPtrN;
t = &SwigPtrList[tag];
t->name = type;
t->prettyname = prettyname;
t->tag = SwigPtrN;
t->cast = NULL;
SwigPtrN++;
SwigPtrSort = 0;
return tag;
}
}
/* Register two data types and their mapping with the type checker. */
SWIGSTATIC void
SWIG_RegisterMapping (const char *origtype, const char *newtype,
swig_converter_func cast)
{
size_t t = SWIG_RegisterType(origtype, NULL);
if (newtype!=NULL) {
size_t t1 = SWIG_RegisterType(newtype, NULL);
struct SwigCast *c;
/* Check for existing cast */
for (c = SwigPtrList[t].cast; c && c->type!=t1; c=c->next) /* nothing */;
if (c) {
if (cast) c->cast = cast;
}
else {
c = (struct SwigCast *) malloc(sizeof(struct SwigCast));
c->type = t1;
c->cast = cast;
c->next = SwigPtrList[t].cast;
SwigPtrList[t].cast = c;
}
}
}
/* Sort table */
static void
SWIG_SortTable (void)
{
qsort ((void *) SwigPtrTbl, SwigPtrN, sizeof(size_t), swigsort);
/* Indicate that everything is sorted */
SwigPtrSort = 1;
}
/* Look up pointer-type entry in table */
static int
swigcmp (const void *key, const void *data)
{
char *k = (char *) key;
size_t index = *(size_t *)data;
return strcmp(k, SwigPtrList[index].name);
}
static SwigPtrType *
SWIG_GetPtrType (const char *_t)
{
size_t *result;
if (!SwigPtrSort) SWIG_SortTable();
result = (size_t *) bsearch(_t, SwigPtrTbl, SwigPtrN, sizeof(size_t), swigcmp);
if (result!=NULL) return SwigPtrList+*result;
else return NULL;
}
/* Cast a pointer if possible; returns 1 if successful */
static int
SWIG_Cast (void *source, size_t source_type,
void **ptr, size_t dest_type)
{
if (dest_type != source_type) {
/* We have a type mismatch. Will have to look through our type
mapping table to figure out whether or not we can accept this
datatype. */
struct SwigCast *c;
for (c = SwigPtrList[dest_type].cast;
c && c->type!=source_type; c = c->next) /* nothing */;
if (c) {
/* Get pointer value. */
if (c->cast) *ptr = (*(c->cast))(source);
else *ptr = source;
return 1;
}
/* Didn't find any sort of match for this data.
Get the pointer value and return false. */
*ptr = source;
return 0;
} else {
/* Found a match on the first try. Return pointer value. */
*ptr = source;
return 1;
}
}
/* Dynamic pointer casting. Down an inheritance hierarchy */
SWIGSTATIC swig_type_info *
SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr)
{
swig_type_info *lastty = ty;
if (!ty || !ty->dcast) return ty;
while (ty && (ty->dcast)) {
ty = (*ty->dcast)(ptr);
if (ty) lastty = ty;
}
return lastty;
}
/* Function for getting a pointer value */
static unsigned long swig_tag = 0;
SWIGSTATIC SCM
SWIG_Guile_MakePtr (void *ptr, swig_type_info *type)
static SCM
SWIG_Guile_NewPointerObj(swig_module_info *module, void *ptr, swig_type_info *type, int owner)
{
unsigned long tag;
if (ptr==NULL) return SCM_EOL;
SCM_RETURN_NEWSMOB((((unsigned long)type->tag << 16) | swig_tag),
ptr);
if (!module) return SCM_EOL;
for (tag = 0; tag < module->size; ++tag) {
if (module->types[tag] == type)
break;
}
if (tag >= module->size)
return SCM_EOL;
SCM_RETURN_NEWSMOB( ((tag << 16) | *((int *)module->clientdata)), ptr);
}
/* Return 0 if successful. */
SWIGSTATIC int
SWIG_Guile_GetPtr(SCM s, void **result, swig_type_info *type)
static int
SWIG_Guile_ConvertPtr(swig_module_info *module, SCM s, void **result, swig_type_info *type, int flags)
{
swig_cast_info *cast;
swig_type_info *from;
if (SCM_NULLP(s)) {
*result = NULL;
return 0;
}
else if (SCM_NIMP(s)
&& (unsigned long) SCM_TYP16(s) == swig_tag) {
if (type)
return !SWIG_Cast((void *) SCM_CDR(s),
(long) SCM_CAR(s) >> 16,
result, type->tag);
else {
} else if (SCM_NIMP(s)) {
from = SWIG_Guile_LookupType(module, s, 1);
if (!from) return 1;
if (type) {
cast = SWIG_TypeCheckStruct(from, type);
if (cast) {
*result = SWIG_TypeCast(cast, (void *) SCM_CDR(s));
return 0;
} else {
return 1;
}
} else {
*result = (void *) SCM_CDR(s);
return 0;
}
@ -397,12 +164,12 @@ SWIG_Guile_GetPtr(SCM s, void **result, swig_type_info *type)
return 1;
}
SWIGSTATIC void *
SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type,
int argnum, const char *func_name)
static void *
SWIG_Guile_MustGetPtr (swig_module_info *module, SCM s, swig_type_info *type,
int argnum, int flags, const char *func_name)
{
void *result;
if (SWIG_Guile_GetPtr(s, &result, type)) {
if (SWIG_Guile_ConvertPtr(module, s, &result, type, flags)) {
/* type mismatch */
scm_wrong_type_arg((char *) func_name, argnum, s);
}
@ -414,15 +181,21 @@ SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type,
static int
print_swig (SCM swig_smob, SCM port, scm_print_state *pstate)
{
scm_puts((char *) "#<swig ", port);
if (SwigPtrList[(long) SCM_CAR(swig_smob) >> 16].prettyname != NULL)
scm_puts((char*) SwigPtrList[(long) SCM_CAR(swig_smob) >> 16].prettyname, port);
else scm_puts((char*) SwigPtrList[(long) SCM_CAR(swig_smob) >> 16].name, port);
scm_puts((char *) " ", port);
scm_intprint((long) SCM_CDR(swig_smob), 16, port);
scm_puts((char *) ">", port);
/* non-zero means success */
return 1;
swig_type_info *type = SWIG_Guile_LookupType(0, swig_smob, 1);
if (type) {
scm_puts((char *) "#<swig ", port);
if (type->str != NULL)
scm_puts((char *) type->str, port);
else
scm_puts((char *) type->name, port);
scm_puts((char *) " ", port);
scm_intprint((long) SCM_CDR(swig_smob), 16, port);
scm_puts((char *) ">", port);
/* non-zero means success */
return 1;
} else {
return 0;
}
}
static SCM
@ -434,33 +207,14 @@ equalp_swig (SCM A, SCM B)
else return SCM_BOOL_F;
}
SWIGSTATIC void
SWIG_Guile_Init (void)
static void
SWIG_Guile_Init (swig_module_info *module)
{
if (swig_tag == 0) {
swig_tag = scm_make_smob_type_mfpe((char *) "swig", 0, NULL, NULL,
print_swig, equalp_swig);
}
*((int *)module->clientdata) =
scm_make_smob_type_mfpe((char *) "swig", 0, NULL, NULL, print_swig, equalp_swig);
}
/* Convert datatype table */
SWIGSTATIC
void SWIG_Guile_RegisterTypes(swig_type_info **table,
swig_type_info **init)
{
for (; *init; table++, init++) {
swig_type_info *type = *table = *init;
const char *origname = type->name;
/* Register datatype itself and store pointer back */
type->tag = SWIG_RegisterType(origname, type->str);
/* Register compatible types */
for (type++; type->name; type++)
SWIG_RegisterMapping(origname, type->name, type->converter);
}
}
SWIGSTATIC int
static int
SWIG_Guile_GetArgs (SCM *dest, SCM rest,
int reqargs, int optargs,
const char *procname)
@ -480,7 +234,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
num_args_passed++;
}
for (; i<optargs; i++)
*dest++ = GH_NOT_PASSED;
*dest++ = SCM_UNDEFINED;
if (!SCM_NULLP(rest))
scm_wrong_num_args(gh_str02scm((char *) procname));
return num_args_passed;
@ -491,5 +245,3 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
#endif
/* guile.swg ends here */
#endif

View file

@ -6,7 +6,6 @@
#define SWIGGUILE_SCM
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "common.swg"
%runtime "guile_scm_run.swg"
%include "ghinterface.i"
@ -38,19 +37,12 @@
%}
%insert(init) "swiginit.swg"
%init %{
static int _swig_init = 0;
SWIG_Guile_Init();
if (!_swig_init) {
int i;
for (i = 0; swig_types_initial[i]; i++) {
swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
for (i = 0; swig_types_initial[i]; i++) {
SWIG_PropagateClientData(swig_types[i]);
}
_swig_init = 1;
}
SWIG_GUILE_INIT_STATIC void
SWIG_init(void)
{
SWIG_InitializeModule(0);
SWIG_PropagateClientData();
%}

View file

@ -47,6 +47,10 @@ typedef struct swig_guile_clientdata {
scm_error(scm_str2symbol("swig-contract-assertion-failed"), \
(char *) FUNC_NAME, (char *) msg, \
SCM_EOL, SCM_BOOL_F); else
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_Guile_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Guile_SetModule(pointer)
static char *
SWIG_Guile_scm2newstr(SCM str, size_t *len) {
@ -138,7 +142,7 @@ SWIG_Guile_PointerType(SCM object)
static int
SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
{
swig_type_info *cast;
swig_cast_info *cast;
swig_type_info *from;
SCM smob = SWIG_Guile_GetSmob(s);
@ -150,7 +154,7 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
from = (swig_type_info *) SCM_CELL_WORD_2(smob);
if (!from) return 1;
if (type) {
cast = SWIG_TypeCheck((char*)from->name, type);
cast = SWIG_TypeCheckStruct(from, type);
if (cast) {
*result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob));
return 0;
@ -304,12 +308,12 @@ ensure_smob_tag(SCM swig_module,
}
}
static void
static SCM
SWIG_Guile_Init ()
{
SCM swig_module;
static SCM swig_module;
if (swig_initialized) return;
if (swig_initialized) return swig_module;
swig_initialized = 1;
swig_module = scm_c_resolve_module("Swig swigrun");
@ -329,19 +333,6 @@ SWIG_Guile_Init ()
scm_set_smob_print(swig_destroyed_tag, print_destroyed_swig);
scm_set_smob_equalp(swig_destroyed_tag, equalp_swig);
}
{
SCM variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME),
scm_module_lookup_closure(swig_module),
SCM_BOOL_T);
if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) {
SCM_VARIABLE_SET(variable, scm_ulong2num((unsigned long) swig_type_list_handle));
}
else {
swig_type_list_handle
= (swig_type_info **) scm_num2ulong(SCM_VARIABLE_REF(variable), 0,
"SWIG_Guile_Init");
}
}
swig_make_func = scm_permanent_object(
scm_variable_ref(scm_c_module_lookup(scm_c_resolve_module("oop goops"), "make")));
swig_keyword = scm_permanent_object(scm_c_make_keyword((char*) "init-smob"));
@ -349,6 +340,41 @@ SWIG_Guile_Init ()
#ifdef SWIG_INIT_RUNTIME_MODULE
SWIG_INIT_RUNTIME_MODULE
#endif
return swig_module;
}
static swig_module_info *
SWIG_Guile_GetModule()
{
SCM module;
SCM variable;
module = SWIG_Guile_Init();
variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME),
scm_module_lookup_closure(module),
SCM_BOOL_T);
if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) {
return NULL;
} else {
return (swig_module_info *) scm_num2ulong(SCM_VARIABLE_REF(variable), 0, "SWIG_Guile_Init");
}
}
static void
SWIG_Guile_SetModule(swig_module_info *swig_module)
{
SCM module;
SCM variable;
module = SWIG_Guile_Init();
variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME),
scm_module_lookup_closure(module),
SCM_BOOL_T);
SCM_VARIABLE_SET(variable, scm_ulong2num((unsigned long) swig_module));
}
static int

View file

@ -23,6 +23,11 @@ extern "C" {
#define SWIG_MustGetPtr(s, type, argnum, flags) \
SWIG_MzScheme_MustGetPtr(s, type, argnum, flags, FUNC_NAME, argc, argv)
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_MzScheme_GetModule((Scheme_Env *)(clientdata))
#define SWIG_SetModule(clientdata, pointer) SWIG_MzScheme_SetModule((Scheme_Env *) (clientdata), pointer)
#define SWIG_MODULE_CLIENTDATA_TYPE Scheme_Env *
/* MzScheme-specific SWIG API */
#define SWIG_malloc(size) SWIG_MzScheme_Malloc(size, FUNC_NAME)
@ -39,42 +44,8 @@ struct swig_mz_proxy {
void *object;
};
/* The interpreter will store a pointer to this structure in a global
variable called swig-runtime-data-type-pointer. The instance of this
struct is only used if no other module has yet been loaded */
struct swig_mzscheme_runtime_data {
swig_type_info **handle;
Scheme_Type type;
};
static struct swig_mzscheme_runtime_data swig_mzscheme_runtime_data;
static Scheme_Type swig_type;
static void
SWIG_MzScheme_LookupTypePointer(Scheme_Env *env) {
Scheme_Object *pointer, *symbol;
struct swig_mzscheme_runtime_data *data;
/* first check if pointer already created */
symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
pointer = scheme_lookup_global(symbol, env);
if (pointer && SCHEME_CPTRP(pointer)) {
data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer);
swig_type_list_handle = data->handle;
swig_type = data->type;
} else {
/* create a new type for wrapped pointer values */
swig_type = scheme_make_type((char *)"swig");
swig_mzscheme_runtime_data.handle = swig_type_list_handle;
swig_mzscheme_runtime_data.type = swig_type;
/* create a new pointer */
pointer = scheme_make_cptr((void *) &swig_mzscheme_runtime_data, "swig_mzscheme_runtime_data");
scheme_add_global_symbol(symbol, pointer, env);
}
}
static void
mz_free_swig(void *p, void *data) {
struct swig_mz_proxy *proxy = (struct swig_mz_proxy *) p;
@ -102,7 +73,7 @@ SWIG_MzScheme_NewPointerObj(void *ptr, swig_type_info *type, int owner) {
static int
SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, int flags) {
swig_type_info *cast;
swig_cast_info *cast;
if (SCHEME_NULLP(s)) {
*result = NULL;
@ -192,7 +163,58 @@ SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename,
return new_type;
}
/* The interpreter will store a pointer to this structure in a global
variable called swig-runtime-data-type-pointer. The instance of this
struct is only used if no other module has yet been loaded */
struct swig_mzscheme_runtime_data {
swig_module_info *module_head;
Scheme_Type type;
};
static struct swig_mzscheme_runtime_data swig_mzscheme_runtime_data;
static swig_module_info *
SWIG_MzScheme_GetModule(Scheme_Env *env) {
Scheme_Object *pointer, *symbol;
struct swig_mzscheme_runtime_data *data;
/* first check if pointer already created */
symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
pointer = scheme_lookup_global(symbol, env);
if (pointer && SCHEME_CPTRP(pointer)) {
data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer);
swig_type = data->type;
return data->module_head;
} else {
return NULL;
}
}
static void
SWIG_MzScheme_SetModule(Scheme_Env *env, swig_module_info *module) {
Scheme_Object *pointer, *symbol;
struct swig_mzscheme_runtime_data *data;
/* first check if pointer already created */
symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
pointer = scheme_lookup_global(symbol, env);
if (pointer && SCHEME_CPTRP(pointer)) {
data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer);
swig_type = data->type;
data->module_head = module;
} else {
/* create a new type for wrapped pointer values */
swig_type = scheme_make_type((char *)"swig");
swig_mzscheme_runtime_data.module_head = module;
swig_mzscheme_runtime_data.type = swig_type;
/* create a new pointer */
pointer = scheme_make_cptr((void *) &swig_mzscheme_runtime_data, "swig_mzscheme_runtime_data");
scheme_add_global_symbol(symbol, pointer, env);
}
}
#ifdef __cplusplus
}
#endif

View file

@ -4,7 +4,6 @@
/* Include headers */
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "common.swg"
%runtime "mzrun.swg"
%define SWIG_APPEND_VALUE(value)
@ -22,15 +21,11 @@
/* Read in standard typemaps. */
%include "typemaps.i"
%init %{
static int _swig_init = 0;
%insert(init) "swiginit.swg"
if (!_swig_init) {
int i;
SWIG_MzScheme_LookupTypePointer(env);
for (i = 0; swig_types_initial[i]; i++) {
swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
}
_swig_init = 1;
}
%init %{
Scheme_Object *scheme_reload(Scheme_Env *env) {
Scheme_Env *menv = SWIG_MZSCHEME_CREATE_MENV(env);
SWIG_InitializeModule((void *) env);
%}

View file

@ -91,7 +91,7 @@
%typemap(in) enum SWIGTYPE {
if (!SCHEME_INTP($input))
scheme_wrong_type(FUNC_NAME, "integer", $argnum - 1, argc, argv);
$1 = SCHEME_INT_VAL($input);
$1 = ($1_type) SCHEME_INT_VAL($input);
}
%typemap(varin) enum SWIGTYPE {

View file

@ -3,14 +3,18 @@
This file is parsed by SWIG before reading any other interface
file. */
%runtime %{
#define SWIGSTATIC static
%}
/* Insert common stuff */
%insert(runtime) "swigrun.swg"
%insert(runtime) "common.swg"
/* Include headers */
%insert(runtime) "ocamldec.swg"
/* Type registration */
%insert(init) "swiginit.swg"
%insert(init) "typeregister.swg"
%insert(mlitail) %{

View file

@ -58,8 +58,8 @@ extern "C" {
*ptr = source;
return 0;
} else {
swig_type_info *tc =
SWIG_TypeCheck( (char *)source_type->name, dest_type );
swig_cast_info *tc =
SWIG_TypeCheckStruct(source_type, dest_type );
#ifdef TYPE_CAST_VERBOSE
fprintf( stderr, "Typecheck -> %s\n",
tc ? tc->str : "<none>" );
@ -371,11 +371,12 @@ extern "C" {
CAMLreturn(vv);
}
SWIGSTATIC CAML_VALUE caml_val_obj( void *v, char *object_type ) {
#define caml_val_obj(v, name) caml_val_obj_helper(v, SWIG_TypeQuery((name)), name)
SWIGSTATIC CAML_VALUE caml_val_obj_helper( void *v, swig_type_info *type, char *name) {
CAMLparam0();
CAMLreturn(callback2(*caml_named_value("caml_create_object_fn"),
caml_val_ptr(v,SWIG_TypeQuery(object_type)),
copy_string(object_type)));
caml_val_ptr(v,type),
copy_string(name)));
}
SWIGSTATIC long caml_long_val_full( CAML_VALUE v, char *name ) {
@ -575,14 +576,21 @@ extern "C" {
}
}
static void SWIG_Ocaml_LookupTypePointer() {
CAML_VALUE mod_pointer, pointer;
static swig_module_info *SWIG_Ocaml_GetModule() {
CAML_VALUE pointer;
mod_pointer = caml_val_ptr(swig_type_list_handle, NULL);
pointer = callback(*caml_named_value("swig_find_type_info"), mod_pointer);
if (SWIG_Tag_val(pointer) == C_ptr) {
swig_type_list_handle = (swig_type_info **)(void *)(long)SWIG_Int64_val(SWIG_Field(pointer,0));
pointer = callback(*caml_named_value("swig_find_type_info"), caml_val_int(0));
if (Is_block(pointer) && SWIG_Tag_val(pointer) == C_ptr) {
return (swig_module_info *)(void *)(long)SWIG_Int64_val(SWIG_Field(pointer,0));
}
return 0;
}
static void SWIG_Ocaml_SetModule(swig_module_info *pointer) {
CAML_VALUE mod_pointer;
mod_pointer = caml_val_ptr(pointer, NULL);
callback(*caml_named_value("swig_set_type_info"), mod_pointer);
}
#ifdef __cplusplus
@ -590,7 +598,7 @@ extern "C" {
#endif
#undef value
/* ocaml keywords */
/* please test and activate */
/* There's no need to use this, because of my rewriting machinery. C++
* words never collide with ocaml keywords */
//%include "ocamlkw.swg"

View file

@ -81,14 +81,9 @@ CAMLextern int64 Int64_val(caml_value_t v);
#define SWIG_Int64_val(v) Int64_val(v)
#endif
#ifdef __GNUC__
# define SWIGSTATIC static inline
#else
# define SWIGSTATIC static
#endif
#define SWIG_NewPointerObj(p,type,flags) caml_val_ptr(p,type)
#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Ocaml_SetModule(pointer)
#define SWIG_contract_assert(expr, msg) if(!(expr)) {failwith(msg);} else

View file

@ -143,16 +143,14 @@ let new_derived_object cfun x_class args =
end
let swig_current_type_info = ref C_void
let find_type_info obj =
match obj with
C_ptr _ -> if !swig_current_type_info = C_void
then begin
swig_current_type_info := obj ;
obj
end else
!swig_current_type_info
| _ -> raise (Failure "Internal error: passed non pointer to find_type_info")
let find_type_info obj = !swig_current_type_info
let _ = Callback.register "swig_find_type_info" find_type_info
let set_type_info obj =
match obj with
C_ptr _ -> swig_current_type_info := obj ;
obj
| _ -> raise (Failure "Internal error: passed non pointer to set_type_info")
let _ = Callback.register "swig_set_type_info" set_type_info
let class_master_list = Hashtbl.create 20
let register_class_byname nm co =

Some files were not shown because too many files have changed in this diff Show more