diff options
Diffstat (limited to 'Lib/guile')
-rw-r--r-- | Lib/guile/argcargv.i | 44 | ||||
-rw-r--r-- | Lib/guile/guile_scm_run.swg | 86 | ||||
-rw-r--r-- | Lib/guile/list-vector.i | 19 | ||||
-rw-r--r-- | Lib/guile/pointer-in-out.i | 3 | ||||
-rw-r--r-- | Lib/guile/std_auto_ptr.i | 39 | ||||
-rw-r--r-- | Lib/guile/std_common.i | 2 | ||||
-rw-r--r-- | Lib/guile/std_map.i | 1116 | ||||
-rw-r--r-- | Lib/guile/std_string.i | 17 | ||||
-rw-r--r-- | Lib/guile/std_unique_ptr.i | 39 | ||||
-rw-r--r-- | Lib/guile/swigmove.i | 19 | ||||
-rw-r--r-- | Lib/guile/swigrun.i | 2 | ||||
-rw-r--r-- | Lib/guile/typemaps.i | 107 |
12 files changed, 293 insertions, 1200 deletions
diff --git a/Lib/guile/argcargv.i b/Lib/guile/argcargv.i new file mode 100644 index 000000000..003be96a7 --- /dev/null +++ b/Lib/guile/argcargv.i @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------- + * SWIG library containing argc and argv multi-argument typemaps + * ------------------------------------------------------------- */ + +%typemap(in) (int ARGC, char **ARGV) { + $1_ltype i, len; + SWIG_contract_assert($input != (SCM)0 && + !scm_is_null($input) && + scm_is_array($input), + "you must pass array of strings"); + len = scm_c_array_length($input); + $1 = len; + $2 = ($2_ltype) malloc((len+1)*sizeof($*2_ltype)); + if ($2 == NULL) { + scm_misc_error(FUNC_NAME, "fail allocating memory for array", SCM_EOL); + } + for (i = 0; i < len; i++) { + SCM args = scm_list_1(scm_from_long(i)); + SCM str = scm_array_ref($input, args); + SWIG_contract_assert(scm_is_string(str), "elements in array must be strings"); + $2[i] = ($*2_ltype)SWIG_scm2str(str); + } + $2[i] = NULL; +} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) { + if ($input != (SCM)0 && !scm_is_null($input) && scm_is_array($input)) { + size_t len = scm_c_array_length($input); + size_t i; + for(i = 0; i < len; i++) { + SCM args = scm_list_1(scm_from_long(i)); + SCM str = scm_array_ref($input, args); + if (!scm_is_string(str)) { + break; + } + } + /* All elements are strings! */ + $1 = (i == len); + } +} + +%typemap(freearg) (int ARGC, char **ARGV) { + free((void *)$2); +} diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 86e5c3be0..89eda3983 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -2,6 +2,12 @@ * guile_scm_run.swg * ----------------------------------------------------------------------------- */ +#if __GNUC__ >= 10 +#if defined(__cplusplus) +#pragma GCC diagnostic ignored "-Wvolatile" /* For 'volatile SCM *' in at least Guile 3.0 and earlier */ +#endif +#endif + #include <libguile.h> #include <stdio.h> #include <string.h> @@ -65,10 +71,11 @@ typedef struct swig_guile_clientdata { #define SWIG_IsPointer(object) \ SWIG_Guile_IsPointer(object) #define SWIG_contract_assert(expr, msg) \ - if (!(expr)) \ - scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \ - (char *) FUNC_NAME, (char *) msg, \ - SCM_EOL, SCM_BOOL_F); else + do { \ + if (!(expr)) \ + scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \ + FUNC_NAME, msg, SCM_EOL, SCM_BOOL_F); \ + } while (0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) \ @@ -110,6 +117,8 @@ static SCM swig_symbol = SCM_EOL; ( !scm_is_null(x) && SCM_INSTANCEP(x) && scm_is_true(scm_slot_exists_p(x, swig_symbol)) \ ? scm_slot_ref(x, swig_symbol) : (x) ) +SWIGINTERN void SWIG_Guile_MarkPointerNoncollectable(SCM s); + SWIGINTERN SCM SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner) { @@ -123,7 +132,7 @@ SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner) else SCM_NEWSMOB2(smob, swig_tag, ptr, (void *) type); - if (!cdata || SCM_NULLP(cdata->goops_class) || swig_make_func == SCM_EOL ) { + if (!cdata || scm_is_null(cdata->goops_class) || swig_make_func == SCM_EOL ) { return smob; } else { /* the scm_make() C function only handles the creation of gf, @@ -143,7 +152,7 @@ SWIGINTERN unsigned long SWIG_Guile_PointerAddress(SCM object) { SCM smob = SWIG_Guile_GetSmob(object); - if (SCM_NULLP(smob)) return 0; + if (scm_is_null(smob)) return 0; else if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob) || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) { @@ -156,7 +165,7 @@ SWIGINTERN swig_type_info * SWIG_Guile_PointerType(SCM object) { SCM smob = SWIG_Guile_GetSmob(object); - if (SCM_NULLP(smob)) return NULL; + if (scm_is_null(smob)) return NULL; else if (SCM_SMOB_PREDICATE(swig_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob) || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) { @@ -183,8 +192,9 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags) swig_cast_info *cast; swig_type_info *from; SCM smob = SWIG_Guile_GetSmob(s); + int ret = SWIG_ERROR; - if (SCM_NULLP(smob)) { + if (scm_is_null(smob)) { *result = NULL; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; #if SCM_MAJOR_VERSION >= 2 @@ -195,22 +205,36 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags) } else if (SWIG_Guile_IsValidSmob(smob)) { from = (swig_type_info *) SCM_CELL_WORD_2(smob); if (!from) return SWIG_ERROR; + + if ((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) { + if ((SCM_CELL_TYPE(smob) == swig_collectable_tag && SCM_CELL_WORD_1(smob) == 0) || SCM_CELL_TYPE(smob) == swig_tag) { + return SWIG_ERROR_RELEASE_NOT_OWNED; + } + } + if (type) { cast = SWIG_TypeCheckStruct(from, type); if (cast) { int newmemory = 0; *result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob), &newmemory); assert(!newmemory); /* newmemory handling not yet implemented */ - return SWIG_OK; + ret = SWIG_OK; } else { return SWIG_ERROR; } } else { *result = (void *) SCM_CELL_WORD_1(smob); - return SWIG_OK; + ret = SWIG_OK; + } + + if (flags & SWIG_POINTER_DISOWN) { + SWIG_Guile_MarkPointerNoncollectable(smob); + } + if (flags & SWIG_POINTER_CLEAR) { + SCM_SET_CELL_WORD_1(smob, 0); } } - return SWIG_ERROR; + return ret; } SWIGINTERNINLINE void * @@ -221,7 +245,7 @@ SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type, int res = SWIG_Guile_ConvertPtr(s, &result, type, flags); if (!SWIG_IsOK(res)) { /* type mismatch */ - scm_wrong_type_arg((char *) func_name, argnum, s); + scm_wrong_type_arg(func_name, argnum, s); } return result; } @@ -250,7 +274,7 @@ SWIGINTERN void SWIG_Guile_MarkPointerNoncollectable(SCM s) { SCM smob = SWIG_Guile_GetSmob(s); - if (!SCM_NULLP(smob)) { + if (!scm_is_null(smob)) { if (SWIG_Guile_IsValidSmob(smob)) { SCM_SET_CELL_TYPE(smob, swig_tag); } @@ -263,7 +287,7 @@ SWIGINTERN void SWIG_Guile_MarkPointerDestroyed(SCM s) { SCM smob = SWIG_Guile_GetSmob(s); - if (!SCM_NULLP(smob)) { + if (!scm_is_null(smob)) { if (SWIG_Guile_IsValidSmob(smob)) { SCM_SET_CELL_TYPE(smob, swig_destroyed_tag); } @@ -315,13 +339,13 @@ print_swig_aux (SCM swig_smob, SCM port, scm_print_state *pstate, type = (swig_type_info *) SCM_CELL_WORD_2(swig_smob); if (type) { - scm_puts((char *) "#<", port); - scm_puts((char *) attribute, port); - scm_puts((char *) "swig-pointer ", port); - scm_puts((char *) SWIG_TypePrettyName(type), port); - scm_puts((char *) " ", port); + scm_puts("#<", port); + scm_puts(attribute, port); + scm_puts("swig-pointer ", port); + scm_puts(SWIG_TypePrettyName(type), port); + scm_puts(" ", port); scm_intprint((long) SCM_CELL_WORD_1(swig_smob), 16, port); - scm_puts((char *) ">", port); + scm_puts(">", port); /* non-zero means success */ return 1; } else { @@ -354,10 +378,10 @@ print_member_function_swig (SCM swig_smob, SCM port, scm_print_state *pstate) swig_type_info *type; type = (swig_type_info *) SCM_CELL_WORD_2(swig_smob); if (type) { - scm_puts((char *) "#<", port); - scm_puts((char *) "swig-member-function-pointer ", port); - scm_puts((char *) SWIG_TypePrettyName(type), port); - scm_puts((char *) " >", port); + scm_puts("#<", port); + scm_puts("swig-member-function-pointer ", port); + scm_puts(SWIG_TypePrettyName(type), port); + scm_puts(" >", port); /* non-zero means success */ return 1; } else { @@ -401,7 +425,7 @@ ensure_smob_tag(SCM swig_module, SCM variable = scm_module_variable(swig_module, scm_from_locale_symbol(scheme_variable_name)); if (scm_is_false(variable)) { - *tag_variable = scm_make_smob_type((char*)scheme_variable_name, 0); + *tag_variable = scm_make_smob_type(scheme_variable_name, 0); scm_c_module_define(swig_module, scheme_variable_name, scm_from_ulong(*tag_variable)); return 1; @@ -446,7 +470,7 @@ 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_from_locale_keyword((char*) "init-smob")); + swig_keyword = scm_permanent_object(scm_from_locale_keyword("init-smob")); swig_symbol = scm_permanent_object(scm_from_locale_symbol("swig-smob")); #ifdef SWIG_INIT_RUNTIME_MODULE SWIG_INIT_RUNTIME_MODULE @@ -484,21 +508,21 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest, int i; int num_args_passed = 0; for (i = 0; i<reqargs; i++) { - if (!SCM_CONSP(rest)) - scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure")); + if (!scm_is_pair(rest)) + scm_wrong_num_args(scm_from_utf8_string(procname ? procname : "unknown procedure")); *dest++ = SCM_CAR(rest); rest = SCM_CDR(rest); num_args_passed++; } - for (i = 0; i<optargs && SCM_CONSP(rest); i++) { + for (i = 0; i<optargs && scm_is_pair(rest); i++) { *dest++ = SCM_CAR(rest); rest = SCM_CDR(rest); num_args_passed++; } for (; i<optargs; i++) *dest++ = SCM_UNDEFINED; - if (!SCM_NULLP(rest)) - scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure")); + if (!scm_is_null(rest)) + scm_wrong_num_args(scm_from_utf8_string(procname ? procname : "unknown procedure")); return num_args_passed; } diff --git a/Lib/guile/list-vector.i b/Lib/guile/list-vector.i index 057a1da5b..b6530d162 100644 --- a/Lib/guile/list-vector.i +++ b/Lib/guile/list-vector.i @@ -107,7 +107,7 @@ (size_t VECTORLENINPUT, C_TYPE *VECTORINPUT), (int LISTLENINPUT, C_TYPE *LISTINPUT), (size_t LISTLENINPUT, C_TYPE *LISTINPUT) - {if ($2!=NULL) SWIG_free($2);} + {SWIG_free($2);} %enddef @@ -173,7 +173,7 @@ (int *LISTLENOUTPUT, C_TYPE **LISTOUTPUT), (size_t *LISTLENOUTPUT, C_TYPE **LISTOUTPUT) { - if ((*$2)!=NULL) free(*$2); + free(*$2); } %enddef @@ -231,7 +231,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri if ((*$2)!=NULL) { int i; for (i = 0; i < *$1; i++) { - if ((*$2)[i] != NULL) free((*$2)[i]); + free((*$2)[i]); } free(*$2); } @@ -249,7 +249,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri if (($2)!=NULL) { int i; for (i = 0; i< $1; i++) - if (($2)[i] != NULL) free(($2)[i]); + free(($2)[i]); free($2); } } @@ -283,8 +283,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri /* input */ /* Passing data is a little complicated here; just remember: - IGNORE typemaps come first, then IN, then CHECK. But if - IGNORE is given, IN won't be used for this type. + IN typemaps come first, then CHECK. We need to "ignore" one of the parameters because there shall be only one argument on the Scheme side. Here we only @@ -360,7 +359,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri const C_TYPE *PARALLEL_VECTORINPUT, C_TYPE *PARALLEL_LISTINPUT, const C_TYPE *PARALLEL_LISTINPUT - {if ($1!=NULL) SWIG_free($1);} + {SWIG_free($1);} %enddef @@ -422,7 +421,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri %typemap(freearg) C_TYPE **PARALLEL_VECTOROUTPUT, C_TYPE **PARALLEL_LISTOUTPUT { - if ((*$1)!=NULL) free(*$1); + free(*$1); } %enddef @@ -471,7 +470,7 @@ TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02 if (($1)!=NULL) { int i; for (i = 0; i<*_global_list_length; i++) - if (($1)[i] != NULL) SWIG_free(($1)[i]); + SWIG_free(($1)[i]); SWIG_free($1); } } @@ -482,7 +481,7 @@ TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02 if ((*$1)!=NULL) { int i; for (i = 0; i<_global_arraylentemp; i++) - if ((*$1)[i] != NULL) free((*$1)[i]); + free((*$1)[i]); free(*$1); } } diff --git a/Lib/guile/pointer-in-out.i b/Lib/guile/pointer-in-out.i index d8a631ca9..80100305d 100644 --- a/Lib/guile/pointer-in-out.i +++ b/Lib/guile/pointer-in-out.i @@ -37,7 +37,6 @@ Likewise, but make the pointer object not garbage collectable. - func(int **BOTH) func(int **INOUT) This annotation combines INPUT and OUTPUT. @@ -82,8 +81,6 @@ %typemap(argout, doc="<" #SCM_TYPE ">") PTRTYPE *OUTPUT_NONCOLLECTABLE "SWIG_APPEND_VALUE(SWIG_NewPointerObj(*$1, $*descriptor, 0));"; -%typemap(in) PTRTYPE *BOTH = PTRTYPE *INPUT; -%typemap(argout) PTRTYPE *BOTH = PTRTYPE *OUTPUT; %typemap(in) PTRTYPE *INOUT = PTRTYPE *INPUT; %typemap(argout) PTRTYPE *INOUT = PTRTYPE *OUTPUT; diff --git a/Lib/guile/std_auto_ptr.i b/Lib/guile/std_auto_ptr.i new file mode 100644 index 000000000..59d5c0ed8 --- /dev/null +++ b/Lib/guile/std_auto_ptr.i @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * std_auto_ptr.i + * + * SWIG library file for handling std::auto_ptr. + * Memory ownership is passed from the std::auto_ptr C++ layer to the proxy + * class when returning a std::auto_ptr from a function. + * Memory ownership is passed from the proxy class to the std::auto_ptr in the + * C++ layer when passed as a parameter to a wrapped function. + * ----------------------------------------------------------------------------- */ + +%define %auto_ptr(TYPE) +%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + scm_misc_error(FUNC_NAME, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'", SCM_EOL); + } else { + %argument_fail(res, "TYPE *", $symname, $argnum); + } + } + $1.reset((TYPE *)argp); +} + +%typemap (out) std::auto_ptr< TYPE > %{ + %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN)); +%} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0); + $1 = SWIG_CheckState(res); +} + +%template() std::auto_ptr< TYPE >; +%enddef + +namespace std { + template <class T> class auto_ptr {}; +} diff --git a/Lib/guile/std_common.i b/Lib/guile/std_common.i index 5899c5548..979744976 100644 --- a/Lib/guile/std_common.i +++ b/Lib/guile/std_common.i @@ -19,7 +19,7 @@ std::string SWIG_scm2string(SCM x) { char* temp; temp = SWIG_scm2str(x); std::string s(temp); - if (temp) SWIG_free(temp); + SWIG_free(temp); return s; } %} diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index f84e78bc3..6fb9bcab7 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -5,6 +5,7 @@ * ----------------------------------------------------------------------------- */ %include <std_common.i> +%include <exception.i> // ------------------------------------------------------------------------ // std::map @@ -64,7 +65,11 @@ namespace std { val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } +%#ifdef __cpp_lib_map_try_emplace + (($1_type &)$1).insert_or_assign(*k, *x); +%#else (($1_type &)$1)[*k] = *x; +%#endif alist = SCM_CDR(alist); } } else { @@ -98,7 +103,11 @@ namespace std { val = SCM_CAR(val); x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); } +%#ifdef __cpp_lib_map_try_emplace + temp.insert_or_assign(*k, *x); +%#else temp[*k] = *x; +%#endif alist = SCM_CDR(alist); } } else { @@ -239,7 +248,11 @@ namespace std { throw std::out_of_range("key not found"); } void __setitem__(const K& key, const T& x) { +%#ifdef __cpp_lib_map_try_emplace + (*self).insert_or_assign(key, x); +%#else (*self)[key] = x; +%#endif } void __delitem__(const K& key) throw (std::out_of_range) { std::map< K, T, C >::iterator i = self->find(key); @@ -264,1107 +277,4 @@ namespace std { } }; - - // specializations for built-ins - - %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) - - template<class T> class map< K, T, C > { - %typemap(in) map< K, T, C > { - if (scm_is_null($input)) { - $1 = std::map< K, T, C >(); - } else if (scm_is_pair($input)) { - $1 = std::map< K, T, C >(); - SCM alist = $input; - while (!scm_is_null(alist)) { - T* x; - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - if (!CHECK(key)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) != 0) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); - } - (($1_type &)$1)[CONVERT_FROM(key)] = *x; - alist = SCM_CDR(alist); - } - } else { - $1 = *(($&1_type) - SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); - } - } - %typemap(in) const map< K, T, C >& (std::map< K, T, C > temp), - const map< K, T, C >* (std::map< K, T, C > temp) { - if (scm_is_null($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - } else if (scm_is_pair($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - SCM alist = $input; - while (!scm_is_null(alist)) { - T* x; - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - if (!CHECK(key)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) != 0) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - x = (T*) SWIG_MustGetPtr(val,$descriptor(T *),$argnum, 0); - } - temp[CONVERT_FROM(key)] = *x; - alist = SCM_CDR(alist); - } - } else { - $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); - } - } - %typemap(out) map< K, T, C > { - SCM alist = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { - T* val = new T(i->second); - SCM k = CONVERT_TO(i->first); - SCM x = SWIG_NewPointerObj(val,$descriptor(T *), 1); - SCM entry = scm_cons(k,x); - alist = scm_cons(entry,alist); - } - $result = alist; - } - %typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - T* x; - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM key = SCM_CAR(head); - SCM val = SCM_CDR(head); - if (!CHECK(key)) { - $1 = 0; - } else { - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) == 0) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) == 0) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $&1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&, - const map< K, T, C >* { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - T* x; - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM key = SCM_CAR(head); - SCM val = SCM_CDR(head); - if (!CHECK(key)) { - $1 = 0; - } else { - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) == 0) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (SWIG_ConvertPtr(val,(void**) &x, - $descriptor(T *), 0) == 0) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %rename("length") size; - %rename("null?") empty; - %rename("clear!") clear; - %rename("ref") __getitem__; - %rename("set!") __setitem__; - %rename("delete!") __delitem__; - %rename("has-key?") has_key; - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair< const K, T > value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - map(); - map(const map& other); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T& __getitem__(K key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void __setitem__(K key, const T& x) { - (*self)[key] = x; - } - void __delitem__(K key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map< K, T, C >::iterator i = self->find(key); - return i != self->end(); - } - SCM keys() { - SCM result = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { - SCM k = CONVERT_TO(i->first); - result = scm_cons(k,result); - } - return result; - } - } - }; - %enddef - - %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) - template<class K> class map< K, T, C > { - %typemap(in) map< K, T, C > { - if (scm_is_null($input)) { - $1 = std::map< K, T, C >(); - } else if (scm_is_pair($input)) { - $1 = std::map< K, T, C >(); - SCM alist = $input; - while (!scm_is_null(alist)) { - K* k; - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); - if (!CHECK(val)) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - if (!CHECK(val)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - } - (($1_type &)$1)[*k] = CONVERT_FROM(val); - alist = SCM_CDR(alist); - } - } else { - $1 = *(($&1_type) - SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); - } - } - %typemap(in) const map< K, T, C >& (std::map< K, T, C > temp), - const map< K, T, C >* (std::map< K, T, C > temp) { - if (scm_is_null($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - } else if (scm_is_pair($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - SCM alist = $input; - while (!scm_is_null(alist)) { - K* k; - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - k = (K*) SWIG_MustGetPtr(key,$descriptor(K *),$argnum, 0); - if (!CHECK(val)) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - if (!CHECK(val)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - } - temp[*k] = CONVERT_FROM(val); - alist = SCM_CDR(alist); - } - } else { - $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); - } - } - %typemap(out) map< K, T, C > { - SCM alist = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { - K* key = new K(i->first); - SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); - SCM x = CONVERT_TO(i->second); - SCM entry = scm_cons(k,x); - alist = scm_cons(entry,alist); - } - $result = alist; - } - %typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - K* k; - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM val = SCM_CDR(head); - if (SWIG_ConvertPtr(val,(void **) &k, - $descriptor(K *), 0) != 0) { - $1 = 0; - } else { - if (CHECK(val)) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (CHECK(val)) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $&1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&, - const map< K, T, C >* { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - K* k; - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM val = SCM_CDR(head); - if (SWIG_ConvertPtr(val,(void **) &k, - $descriptor(K *), 0) != 0) { - $1 = 0; - } else { - if (CHECK(val)) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (CHECK(val)) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %rename("length") size; - %rename("null?") empty; - %rename("clear!") clear; - %rename("ref") __getitem__; - %rename("set!") __setitem__; - %rename("delete!") __delitem__; - %rename("has-key?") has_key; - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair< const K, T > value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - map(); - map(const map& other); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T __getitem__(const K& key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void __setitem__(const K& key, T x) { - (*self)[key] = x; - } - void __delitem__(const K& key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const K& key) { - std::map< K, T, C >::iterator i = self->find(key); - return i != self->end(); - } - SCM keys() { - SCM result = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { - K* key = new K(i->first); - SCM k = SWIG_NewPointerObj(key,$descriptor(K *), 1); - result = scm_cons(k,result); - } - return result; - } - } - }; - %enddef - - %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, - T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) - template<> class map< K, T, C > { - %typemap(in) map< K, T, C > { - if (scm_is_null($input)) { - $1 = std::map< K, T, C >(); - } else if (scm_is_pair($input)) { - $1 = std::map< K, T, C >(); - SCM alist = $input; - while (!scm_is_null(alist)) { - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - if (!CHECK_K(key)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - if (!CHECK_T(val)) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - if (!CHECK_T(val)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - } - (($1_type &)$1)[CONVERT_K_FROM(key)] = - CONVERT_T_FROM(val); - alist = SCM_CDR(alist); - } - } else { - $1 = *(($&1_type) - SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0)); - } - } - %typemap(in) const map< K, T, C >& (std::map< K, T, C > temp), - const map< K, T, C >* (std::map< K, T, C > temp) { - if (scm_is_null($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - } else if (scm_is_pair($input)) { - temp = std::map< K, T, C >(); - $1 = &temp; - SCM alist = $input; - while (!scm_is_null(alist)) { - SCM entry, key, val; - entry = SCM_CAR(alist); - if (!scm_is_pair(entry)) - SWIG_exception(SWIG_TypeError,"alist expected"); - key = SCM_CAR(entry); - val = SCM_CDR(entry); - if (!CHECK_K(key)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - if (!CHECK_T(val)) { - if (!scm_is_pair(val)) - SWIG_exception(SWIG_TypeError,"alist expected"); - val = SCM_CAR(val); - if (!CHECK_T(val)) - SWIG_exception(SWIG_TypeError, - "map<" #K "," #T "," #C "> expected"); - } - temp[CONVERT_K_FROM(key)] = CONVERT_T_FROM(val); - alist = SCM_CDR(alist); - } - } else { - $1 = ($1_ltype) SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0); - } - } - %typemap(out) map< K, T, C > { - SCM alist = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=$1.rbegin(); i!=$1.rend(); ++i) { - SCM k = CONVERT_K_TO(i->first); - SCM x = CONVERT_T_TO(i->second); - SCM entry = scm_cons(k,x); - alist = scm_cons(entry,alist); - } - $result = alist; - } - %typecheck(SWIG_TYPECHECK_MAP) map< K, T, C > { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM key = SCM_CAR(head); - SCM val = SCM_CDR(head); - if (!CHECK_K(key)) { - $1 = 0; - } else { - if (CHECK_T(val)) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (CHECK_T(val)) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $&1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %typecheck(SWIG_TYPECHECK_MAP) const map< K, T, C >&, - const map< K, T, C >* { - // native sequence? - if (scm_is_null($input)) { - /* an empty sequence can be of any type */ - $1 = 1; - } else if (scm_is_pair($input)) { - // check the first element only - SCM head = SCM_CAR($input); - if (scm_is_pair(head)) { - SCM key = SCM_CAR(head); - SCM val = SCM_CDR(head); - if (!CHECK_K(key)) { - $1 = 0; - } else { - if (CHECK_T(val)) { - $1 = 1; - } else if (scm_is_pair(val)) { - val = SCM_CAR(val); - if (CHECK_T(val)) - $1 = 1; - else - $1 = 0; - } else { - $1 = 0; - } - } - } else { - $1 = 0; - } - } else { - // wrapped map? - std::map< K, T, C >* m; - if (SWIG_ConvertPtr($input,(void **) &m, - $1_descriptor, 0) == 0) - $1 = 1; - else - $1 = 0; - } - } - %rename("length") size; - %rename("null?") empty; - %rename("clear!") clear; - %rename("ref") __getitem__; - %rename("set!") __setitem__; - %rename("delete!") __delitem__; - %rename("has-key?") has_key; - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair< const K, T > value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - map(); - map(const map& other); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - T __getitem__(K key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - return i->second; - else - throw std::out_of_range("key not found"); - } - void __setitem__(K key, T x) { - (*self)[key] = x; - } - void __delitem__(K key) throw (std::out_of_range) { - std::map< K, T, C >::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(K key) { - std::map< K, T, C >::iterator i = self->find(key); - return i != self->end(); - } - SCM keys() { - SCM result = SCM_EOL; - for (std::map< K, T, C >::reverse_iterator i=self->rbegin(); i!=self->rend(); ++i) { - SCM k = CONVERT_K_TO(i->first); - result = scm_cons(k,result); - } - return result; - } - } - }; - %enddef - - - specialize_std_map_on_key(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_key(int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_key(short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_key(long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_key(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_key(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_key(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_key(double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_key(float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_key(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - - specialize_std_map_on_value(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_value(int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_value(short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_value(long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_value(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_value(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_value(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_value(double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_value(float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_value(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(bool,scm_is_bool, - scm_is_true,SWIG_bool2scm, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(int,scm_is_number, - scm_to_long,scm_from_long, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(short,scm_is_number, - scm_to_long,scm_from_long, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(long,scm_is_number, - scm_to_long,scm_from_long, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(double,scm_is_number, - scm_to_double,scm_from_double, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(float,scm_is_number, - scm_to_double,scm_from_double, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - bool,scm_is_bool, - scm_is_true,SWIG_bool2scm); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - int,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - short,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - long,scm_is_number, - scm_to_long,scm_from_long); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - unsigned int,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - unsigned short,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - unsigned long,scm_is_number, - scm_to_ulong,scm_from_ulong); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - double,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - float,scm_is_number, - scm_to_double,scm_from_double); - specialize_std_map_on_both(std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm, - std::string,scm_is_string, - SWIG_scm2string,SWIG_string2scm); } diff --git a/Lib/guile/std_string.i b/Lib/guile/std_string.i index 6513173ee..178c484ce 100644 --- a/Lib/guile/std_string.i +++ b/Lib/guile/std_string.i @@ -30,7 +30,7 @@ namespace std { if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); $1.assign(tempptr); - if (tempptr) SWIG_free(tempptr); + SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); } @@ -40,7 +40,7 @@ namespace std { if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); temp.assign(tempptr); - if (tempptr) SWIG_free(tempptr); + SWIG_free(tempptr); $1 = &temp; } else { SWIG_exception(SWIG_TypeError, "string expected"); @@ -51,7 +51,7 @@ namespace std { if (scm_is_string($input)) { tempptr = SWIG_scm2str($input); $1 = new $*1_ltype(tempptr); - if (tempptr) SWIG_free(tempptr); + SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); } @@ -73,7 +73,7 @@ namespace std { if (scm_is_string($input)) { char *tempptr = SWIG_scm2str($input); $1.assign(tempptr); - if (tempptr) SWIG_free(tempptr); + SWIG_free(tempptr); } else { SWIG_exception(SWIG_TypeError, "string expected"); } @@ -83,4 +83,13 @@ namespace std { $result = SWIG_str02scm($1.c_str()); } + %typemap(throws) string { + scm_throw(scm_from_locale_symbol("swig-exception"), + scm_list_n(SWIG_str02scm($1.c_str()), SCM_UNDEFINED)); + } + + %typemap(throws) const string & { + scm_throw(scm_from_locale_symbol("swig-exception"), + scm_list_n(SWIG_str02scm($1.c_str()), SCM_UNDEFINED)); + } } diff --git a/Lib/guile/std_unique_ptr.i b/Lib/guile/std_unique_ptr.i new file mode 100644 index 000000000..6f907e90c --- /dev/null +++ b/Lib/guile/std_unique_ptr.i @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * std_unique_ptr.i + * + * SWIG library file for handling std::unique_ptr. + * Memory ownership is passed from the std::unique_ptr C++ layer to the proxy + * class when returning a std::unique_ptr from a function. + * Memory ownership is passed from the proxy class to the std::unique_ptr in the + * C++ layer when passed as a parameter to a wrapped function. + * ----------------------------------------------------------------------------- */ + +%define %unique_ptr(TYPE) +%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + scm_misc_error(FUNC_NAME, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'", SCM_EOL); + } else { + %argument_fail(res, "TYPE *", $symname, $argnum); + } + } + $1.reset((TYPE *)argp); +} + +%typemap (out) std::unique_ptr< TYPE > %{ + %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN)); +%} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0); + $1 = SWIG_CheckState(res); +} + +%template() std::unique_ptr< TYPE >; +%enddef + +namespace std { + template <class T> class unique_ptr {}; +} diff --git a/Lib/guile/swigmove.i b/Lib/guile/swigmove.i new file mode 100644 index 000000000..87ab91ead --- /dev/null +++ b/Lib/guile/swigmove.i @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------------- + * swigmove.i + * + * Input typemaps library for implementing full move semantics when passing + * parameters by value. + * ----------------------------------------------------------------------------- */ + +%typemap(in, noblock=1) SWIGTYPE MOVE (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $&1_descriptor, SWIG_POINTER_RELEASE); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + %releasenotowned_fail(res, "$1_type", $symname, $argnum); + } else { + %argument_fail(res, "$1_type", $symname, $argnum); + } + } + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } + SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp); +} diff --git a/Lib/guile/swigrun.i b/Lib/guile/swigrun.i index 4b9ea2c79..e4573eb3b 100644 --- a/Lib/guile/swigrun.i +++ b/Lib/guile/swigrun.i @@ -4,8 +4,6 @@ #ifdef SWIGGUILE_SCM -/* Hook the runtime module initialization - into the shared initialization function SWIG_Guile_Init. */ %runtime %{ /* Hook the runtime module initialization into the shared initialization function SWIG_Guile_Init. */ diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index cfccced88..d9b78fb4f 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -4,17 +4,43 @@ * Guile-specific typemaps * ----------------------------------------------------------------------------- */ +/* These are defined with a view to eventually merging with those defined for other target languages in swigtypemaps.swg and exception.swg */ +#define %set_output(obj) $result = obj +#define %set_varoutput(obj) $result = obj +#define %argument_fail(_code, _type, _name, _argn) scm_wrong_type_arg(FUNC_NAME, _argn, $input) +#define %as_voidptr(ptr) (void*)(ptr) +#define %argument_nullref(_type, _name, _argn) scm_misc_error(FUNC_NAME, "invalid null reference for argument " #_argn " of type '" _type "'", SCM_EOL) +#define %releasenotowned_fail(_code, _type, _name, _argn) scm_misc_error(FUNC_NAME, "cannot release ownership as memory is not owned for argument " #_argn " of type '" _type "'", SCM_EOL) + /* Pointers */ -%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { +%typemap(in) SWIGTYPE *, SWIGTYPE [] { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); } -%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] ""; +%typemap(in) SWIGTYPE & ($1_ltype argp) { + argp = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } + $1 = argp; +} +%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) { + res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + %releasenotowned_fail(res, "$1_type", $symname, $argnum); + } else { + %argument_fail(res, "$1_type", $symname, $argnum); + } + } + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } + $1 = ($1_ltype)argp; + rvrdeleter.reset($1); +} +%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "" %typemap(in) void * { $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0); } -%typemap(freearg) void * ""; +%typemap(freearg) void * "" %typemap(varin) SWIGTYPE * { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0); @@ -29,7 +55,7 @@ } %typemap(varin) SWIGTYPE [] { - scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); + scm_wrong_type_arg(FUNC_NAME, 1, $input); } %typemap(varin) SWIGTYPE [ANY] { @@ -68,31 +94,31 @@ %typemap(throws) SWIGTYPE { $<ype temp = new $ltype($1); - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(SWIG_NewPointerObj(temp, $&descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE & { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(SWIG_NewPointerObj(&$1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE && { - scm_throw(gh_symbol2scm((char *) "swig-exception"), - gh_list(SWIG_NewPointerObj(&$1, $descriptor, 1), + scm_throw(scm_from_locale_symbol("swig-exception"), + scm_list_n(SWIG_NewPointerObj(&$1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE * { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } %typemap(throws) SWIGTYPE [] { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(SWIG_NewPointerObj($1, $descriptor, 1), SCM_UNDEFINED)); } @@ -115,8 +141,9 @@ /* Pass-by-value */ -%typemap(in) SWIGTYPE($&1_ltype argp) { +%typemap(in) SWIGTYPE ($&1_ltype argp) { argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); + if (!argp) { %argument_nullref("$1_type", $symname, $argnum); } $1 = *argp; } @@ -130,7 +157,7 @@ #ifdef __cplusplus { $&1_ltype resultptr; - resultptr = new $1_ltype((const $1_ltype &) $1); + resultptr = new $1_ltype($1); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); } #else @@ -145,8 +172,7 @@ %typemap(varout) SWIGTYPE #ifdef __cplusplus { - $&1_ltype resultptr; - resultptr = new $1_ltype((const $1_ltype&) $1); + $&1_ltype resultptr = ($&1_ltype)&$1; $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); } #else @@ -166,8 +192,8 @@ %typemap(varin) enum SWIGTYPE { if (sizeof(int) != sizeof($1)) { scm_error(scm_from_locale_symbol("swig-error"), - (char *) FUNC_NAME, - (char *) "enum variable '$name' cannot be set", + FUNC_NAME, + "enum variable '$name' cannot be set", SCM_EOL, SCM_BOOL_F); } * (int *) &($1) = scm_to_int($input); @@ -175,7 +201,7 @@ %typemap(out) enum SWIGTYPE { $result = scm_from_long((int)$1); } %typemap(varout) enum SWIGTYPE { $result = scm_from_long((int)$1); } %typemap(throws) enum SWIGTYPE { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(scm_from_long((int)$1), SCM_UNDEFINED)); } @@ -209,8 +235,6 @@ %typemap (argout,doc="$name (of type <" #SCM_NAME ">)") C_NAME *OUTPUT { C_NAME swig_c_value = *$1; SWIG_APPEND_VALUE(C_TO_SCM_EXPR); } - %typemap (in) C_NAME *BOTH = C_NAME *INPUT; - %typemap (argout) C_NAME *BOTH = C_NAME *OUTPUT; %typemap (in) C_NAME *INOUT = C_NAME *INPUT; %typemap (argout) C_NAME *INOUT = C_NAME *OUTPUT; /* Const primitive references. Passed by value */ @@ -224,7 +248,7 @@ /* Throw typemap */ %typemap(throws) C_NAME { C_NAME swig_c_value = $1; - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(C_TO_SCM_EXPR, SCM_UNDEFINED)); } %enddef @@ -252,8 +276,6 @@ {$1 = &temp;} %typemap (argout,doc="$name (of type <" #SCM_NAME ">)") C_NAME *OUTPUT, C_NAME &OUTPUT {SWIG_APPEND_VALUE(C_TO_SCM(*$1));} - %typemap (in) C_NAME *BOTH = C_NAME *INPUT; - %typemap (argout) C_NAME *BOTH = C_NAME *OUTPUT; %typemap (in) C_NAME *INOUT = C_NAME *INPUT; %typemap (argout) C_NAME *INOUT = C_NAME *OUTPUT; %typemap (in) C_NAME &INOUT = C_NAME &INPUT; @@ -268,7 +290,7 @@ } /* Throw typemap */ %typemap(throws) C_NAME { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(C_TO_SCM($1), SCM_UNDEFINED)); } %enddef @@ -314,27 +336,25 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer); {$1 = &temp;} %typemap (argout,doc="$NAME (a string)") char **OUTPUT {SWIG_APPEND_VALUE(SWIG_str02scm(*$1));} - %typemap (in) char **BOTH = char **INPUT; - %typemap (argout) char **BOTH = char **OUTPUT; %typemap (in) char **INOUT = char **INPUT; %typemap (argout) char **INOUT = char **OUTPUT; /* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after the function call. */ -%typemap (freearg) char * "if (must_free$argnum && $1) SWIG_free($1);"; -%typemap (freearg) char **INPUT, char **BOTH "if (must_free$argnum && (*$1)) SWIG_free(*$1);" +%typemap (freearg) char * "if (must_free$argnum) SWIG_free($1);" +%typemap (freearg) char **INPUT, char **INOUT "if (must_free$argnum) SWIG_free(*$1);" %typemap (freearg) char **OUTPUT "SWIG_free(*$1);" /* But this shall not apply if we try to pass a single char by reference. */ -%typemap (freearg) char *OUTPUT, char *BOTH ""; +%typemap (freearg) char *OUTPUT, char *INOUT "" /* If we set a string variable, delete the old result first, unless const. */ %typemap (varin) char * { - if ($1) free($1); + free($1); $1 = ($1_ltype) SWIG_scm2str($input); } @@ -343,19 +363,19 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer); } %typemap(throws) char * { - scm_throw(scm_from_locale_symbol((char *) "swig-exception"), + scm_throw(scm_from_locale_symbol("swig-exception"), scm_list_n(SWIG_str02scm($1), SCM_UNDEFINED)); } /* Void */ -%typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;"; +%typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;" /* SCM is passed through */ typedef unsigned long SCM; -%typemap (in) SCM "$1=$input;"; -%typemap (out) SCM "$result=$1;"; +%typemap (in) SCM "$1=$input;" +%typemap (out) SCM "$result=$1;" %typecheck(SWIG_TYPECHECK_POINTER) SCM "$1=1;"; /* ------------------------------------------------------------ @@ -373,31 +393,26 @@ typedef unsigned long SCM; * taken from typemaps/swigtype.swg * ------------------------------------------------------------ */ -#define %set_output(obj) $result = obj -#define %set_varoutput(obj) $result = obj -#define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input); -#define %as_voidptr(ptr) (void*)(ptr) - -%typemap(in) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($type),$descriptor); +%typemap(in) SWIGTYPE (CLASS::*) { + int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor); if (!SWIG_IsOK(res)) { - %argument_fail(res,"$type",$symname, $argnum); + %argument_fail(res,"$type",$symname, $argnum); } } %typemap(out,noblock=1) SWIGTYPE (CLASS::*) { - %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } %typemap(varin) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($type), $descriptor); + int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($1), $descriptor); if (!SWIG_IsOK(res)) { - scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); + scm_wrong_type_arg(FUNC_NAME, 1, $input); } } %typemap(varout,noblock=1) SWIGTYPE (CLASS::*) { - %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } /* ------------------------------------------------------------ @@ -426,7 +441,7 @@ typedef unsigned long SCM; %typecheck(SWIG_TYPECHECK_BOOL) bool, bool&, const bool& { - $1 = SCM_BOOLP($input) ? 1 : 0; + $1 = scm_is_bool($input) ? 1 : 0; } %typecheck(SWIG_TYPECHECK_DOUBLE) |