Lots more bug fixes for the chicken module: almost the entire test-sutie now runs
The only tests that are failing are ones that depend on std_vector.i and similar git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7079 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a28fc0f8c4
commit
897e5ad40d
17 changed files with 322 additions and 43 deletions
|
|
@ -78,58 +78,86 @@
|
|||
$result = to_scheme (convtype ($varname));
|
||||
%}
|
||||
|
||||
%typemap(throws) type_
|
||||
%{
|
||||
SWIG_Chicken_ThrowException(to_scheme ( convtype ($1)));
|
||||
%}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(out) type_
|
||||
%{
|
||||
{
|
||||
C_word *space = C_alloc(storage_);
|
||||
$result = to_scheme (&space, convtype ($1));
|
||||
}
|
||||
%}
|
||||
|
||||
/* References to primitive types. Return by value */
|
||||
|
||||
%typemap(out) const type_ &
|
||||
%{
|
||||
$result = to_scheme (convtype (*$1));
|
||||
{
|
||||
C_word *space = C_alloc(storage_);
|
||||
$result = to_scheme (&space, convtype (*$1));
|
||||
}
|
||||
%}
|
||||
|
||||
/* --- Variable output --- */
|
||||
%typemap(varout) type_
|
||||
%{
|
||||
{
|
||||
C_word *space = C_alloc(storage_);
|
||||
$result = to_scheme (&space, convtype ($varname));
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(throws) type_
|
||||
%{
|
||||
{
|
||||
C_word *space = C_alloc(storage_);
|
||||
SWIG_Chicken_ThrowException(to_scheme (&space, convtype ($1)));
|
||||
}
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
#if ("type_" == "char") || ("type_" == "unsigned char") || ("type_" == "signed char")
|
||||
%typemap(constcode) type_
|
||||
"static const $1_type $result = '$value';"
|
||||
#else
|
||||
%typemap(constcode) type_
|
||||
"static const $1_type $result = $value;"
|
||||
#endif
|
||||
|
||||
%enddef
|
||||
|
||||
SIMPLE_TYPEMAP(int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
//SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(unsigned int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(unsigned short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(unsigned long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(unsigned long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(unsigned char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(signed char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
SIMPLE_TYPEMAP(unsigned long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(unsigned long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
|
||||
SIMPLE_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
|
||||
SIMPLE_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
|
||||
SIMPLE_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
|
||||
SIMPLE_TYPEMAP(float, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
SIMPLE_TYPEMAP(double, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
|
||||
/* enum SWIGTYPE */
|
||||
%apply int { enum SWIGTYPE };
|
||||
%apply const int& { const enum SWIGTYPE& };
|
||||
|
||||
%typemap(varin) enum SWIGTYPE
|
||||
{
|
||||
if (!C_swig_is_fixnum($input) && sizeof(int) != sizeof($1)) {
|
||||
swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "enum variable '$name' can not be set");
|
||||
}
|
||||
*((int *)(void *)&$1) = C_unfix($input);
|
||||
}
|
||||
|
||||
|
||||
/* --- Input arguments --- */
|
||||
|
||||
/* Strings */
|
||||
|
|
@ -287,6 +315,17 @@ SIMPLE_TYPEMAP(double, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double),
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(throws) char *
|
||||
{
|
||||
if ($1 == NULL) {
|
||||
SWIG_Chicken_ThrowException(C_SCHEME_FALSE);
|
||||
} else {
|
||||
int string_len = strlen($1);
|
||||
C_word *string_space = C_alloc(C_SIZEOF_STRING(string_len));
|
||||
SWIG_Chicken_ThrowException(C_string(&string_space, string_len, (char *) $1));
|
||||
}
|
||||
}
|
||||
|
||||
/* Void */
|
||||
%typemap(out) void
|
||||
%{
|
||||
|
|
@ -416,7 +455,7 @@ $result = C_SCHEME_UNDEFINED;
|
|||
/* --- Constants --- */
|
||||
|
||||
%typemap(constcode) char *
|
||||
"static const char *$result = \"$value\";"
|
||||
"static const char *$result = $value;"
|
||||
|
||||
%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"static const void *$result = (void*) $value;"
|
||||
|
|
@ -513,11 +552,61 @@ $result = C_SCHEME_UNDEFINED;
|
|||
$1 = !SWIG_ConvertPtr($input, &ptr, 0, 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
|
||||
{
|
||||
void *ptr = 0;
|
||||
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
|
||||
/* error */
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = (ptr != 0);
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
|
||||
{
|
||||
void *ptr = 0;
|
||||
if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0)) {
|
||||
/* error */
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = (ptr != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* TODO */
|
||||
/* ------------------------------------------------------------
|
||||
* --- Exception handling ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) SWIGTYPE {
|
||||
$<ype temp = new $ltype($1);
|
||||
C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
|
||||
C_word ptr = SWIG_NewPointerObj(temp, $&descriptor,1);
|
||||
SWIG_Chicken_ThrowException(ptr);
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE * {
|
||||
C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
|
||||
C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
|
||||
SWIG_Chicken_ThrowException(ptr);
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE [ANY] {
|
||||
C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
|
||||
C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
|
||||
SWIG_Chicken_ThrowException(ptr);
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE & {
|
||||
C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
|
||||
C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0);
|
||||
SWIG_Chicken_ThrowException(ptr);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ extern "C" {
|
|||
#define C_swig_is_ptr(x) (C_truep (C_blockp (x)) && C_truep (C_pointerp (x)))
|
||||
#define C_swig_is_swigpointer(x) (C_truep (C_blockp(x)) && C_truep (C_swigpointerp(x)))
|
||||
#define C_swig_is_closurep(x) (C_truep (C_blockp(x)) && C_truep(C_closurep(x)))
|
||||
#define C_swig_is_long(x) (C_swig_is_fixnum(x) || C_swig_is_flonum(x))
|
||||
|
||||
#define SWIG_APPEND_VALUE(object) \
|
||||
if (resultobj == C_SCHEME_UNDEFINED) \
|
||||
|
|
@ -178,6 +179,21 @@ SWIG_Chicken_Barf(int code, C_char *msg, ...)
|
|||
}
|
||||
}
|
||||
|
||||
static void SWIG_Chicken_ThrowException(C_word value) C_noret;
|
||||
static void SWIG_Chicken_ThrowException(C_word value)
|
||||
{
|
||||
char *aborthook = C_text("\003sysabort");
|
||||
C_word *a = C_alloc(C_SIZEOF_STRING(strlen(aborthook)));
|
||||
C_word abort = C_intern2(&a, aborthook);
|
||||
|
||||
abort = C_block_item(abort, 0);
|
||||
if (C_immediatep(abort))
|
||||
SWIG_Chicken_Panic(C_text("`##sys#abort' is not defiend"));
|
||||
|
||||
C_save(value);
|
||||
C_do_apply(1, abort, C_SCHEME_UNDEFINED);
|
||||
}
|
||||
|
||||
static void
|
||||
SWIG_Chicken_Finalizer(C_word argc, C_word closure, C_word continuation, C_word s)
|
||||
{
|
||||
|
|
@ -251,6 +267,8 @@ SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags
|
|||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
C_do_unregister_finalizer(s);
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
58
Lib/chicken/std_string.i
Normal file
58
Lib/chicken/std_string.i
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// SWIG typemaps for std::string
|
||||
// copied from the guile std_string.i and modified
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
class string;
|
||||
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in) string (char* tempptr) {
|
||||
if ($input == C_SCHEME_FALSE) {
|
||||
$1 = std::string();
|
||||
} else {
|
||||
if (!C_swig_is_string ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE,
|
||||
"Argument #$argnum is not a string");
|
||||
}
|
||||
tempptr = SWIG_MakeString($input);
|
||||
$1 = std::string(tempptr);
|
||||
if (tempptr) SWIG_free(tempptr);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string& (std::string temp,
|
||||
char* tempptr) {
|
||||
|
||||
if ($input == C_SCHEME_FALSE) {
|
||||
temp = std::string();
|
||||
$1 = &temp;
|
||||
} else {
|
||||
if (!C_swig_is_string ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE,
|
||||
"Argument #$argnum is not a string");
|
||||
}
|
||||
tempptr = SWIG_MakeString($input);
|
||||
temp = std::string(tempptr);
|
||||
if (tempptr) SWIG_free(tempptr);
|
||||
$1 = &temp;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
int size = $1.size();
|
||||
C_word *space = C_alloc (C_SIZEOF_STRING (size));
|
||||
$result = C_string (&space, size, (char *) $1.c_str());
|
||||
}
|
||||
|
||||
%typemap(out) const string& {
|
||||
int size = $1->size();
|
||||
C_word *space = C_alloc (C_SIZEOF_STRING (size));
|
||||
$result = C_string (&space, size, (char *) $1->c_str());
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ output values, in reverse order.
|
|||
%{ if (!checker ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
|
||||
}
|
||||
temp = from_scheme ($input);
|
||||
temp = ($*1_ltype) from_scheme ($input);
|
||||
$1 = &temp; %}
|
||||
|
||||
%typemap(typecheck) type_ *INPUT = type_;
|
||||
|
|
@ -166,12 +166,12 @@ output values, in reverse order.
|
|||
INOUT_TYPEMAP(int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLOWNUM);
|
||||
INOUT_TYPEMAP(long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(unsigned int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(unsigned short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(unsigned long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(unsigned long long, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(unsigned long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(unsigned long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
|
||||
INOUT_TYPEMAP(unsigned char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(signed char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
INOUT_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue