Member function pointer typemap tweaks

Use sizeof variable name rather than variable type.
Workaround Visual C++ unable to parse some complex C++11 types, such as
  sizeof(short (Funcs::*)(bool) const &&)
This commit is contained in:
William S Fulton 2021-04-24 10:38:50 +01:00
commit 13158bda9a
5 changed files with 19 additions and 19 deletions

View file

@ -258,7 +258,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO
if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
C_word ptr = C_block_item($input,0); C_word ptr = C_block_item($input,0);
if (C_swig_is_string(ptr)) { if (C_swig_is_string(ptr)) {
SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type)); SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1));
} else { } else {
snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name)); snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
@ -293,7 +293,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO
if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
C_word ptr = C_block_item($input,0); C_word ptr = C_block_item($input,0);
if (C_swig_is_string(ptr)) { if (C_swig_is_string(ptr)) {
SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type)); SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1));
} else { } else {
snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name)); snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);

View file

@ -378,26 +378,26 @@ typedef unsigned long SCM;
#define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input); #define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input);
#define %as_voidptr(ptr) (void*)(ptr) #define %as_voidptr(ptr) (void*)(ptr)
%typemap(in) SWIGTYPE (CLASS::*) { %typemap(in) 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)) { if (!SWIG_IsOK(res)) {
%argument_fail(res,"$type",$symname, $argnum); %argument_fail(res,"$type",$symname, $argnum);
} }
} }
%typemap(out,noblock=1) SWIGTYPE (CLASS::*) { %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::*) { %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)) { if (!SWIG_IsOK(res)) {
scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); scm_wrong_type_arg((char *) FUNC_NAME, 1, $input);
} }
} }
%typemap(varout,noblock=1) SWIGTYPE (CLASS::*) { %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));
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------

View file

@ -237,13 +237,13 @@ $1=($1_ltype)&temp;%}
// therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written // therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*) %typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*)
%{ %{
if (!SWIG_IsOK(SWIG_ConvertMember(L,$input,(void*)(&$1),sizeof($type),$descriptor))) if (!SWIG_IsOK(SWIG_ConvertMember(L,$input,(void*)(&$1),sizeof($1),$descriptor)))
SWIG_fail_ptr("$symname",$argnum,$descriptor); SWIG_fail_ptr("$symname",$argnum,$descriptor);
%} %}
%typemap(out) SWIGTYPE (CLASS::*) %typemap(out) SWIGTYPE (CLASS::*)
%{ %{
SWIG_NewMemberObj(L,(void*)(&$1),sizeof($type),$descriptor); SWIG_arg++; SWIG_NewMemberObj(L,(void*)(&$1),sizeof($1),$descriptor); SWIG_arg++;
%} %}

View file

@ -95,7 +95,7 @@
"sv_setiv(SvRV($result), PTR2IV(&$1));"; "sv_setiv(SvRV($result), PTR2IV(&$1));";
%typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) { %typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) {
SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor); SWIG_MakePackedObj($result, (void *) &$1, sizeof($1), $1_descriptor);
} }
%typemap(varout) SWIGTYPE *const = SWIGTYPE *; %typemap(varout) SWIGTYPE *const = SWIGTYPE *;

View file

@ -562,29 +562,29 @@
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%typemap(in) SWIGTYPE (CLASS::*) { %typemap(in) 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)) { if (!SWIG_IsOK(res)) {
%argument_fail(res,"$type",$symname, $argnum); %argument_fail(res,"$type",$symname, $argnum);
} }
} }
%typemap(out,noblock=1) SWIGTYPE (CLASS::*) { %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::*) { %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)) { if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name"); %variable_fail(res, "$type", "$name");
} }
} }
%typemap(varout,noblock=1) SWIGTYPE (CLASS::*) { %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));
} }
%typemap(constcode,noblock=1) SWIGTYPE (CLASS::*) { %typemap(constcode,noblock=1) SWIGTYPE (CLASS::*) {
%set_constant("$symname", SWIG_NewMemberObj(%as_voidptr(&$value), sizeof($type), $descriptor)); %set_constant("$symname", SWIG_NewMemberObj(%as_voidptr(&$value), sizeof($value), $descriptor));
} }
#if defined(SWIG_DIRECTOR_TYPEMAPS) #if defined(SWIG_DIRECTOR_TYPEMAPS)
@ -592,13 +592,13 @@
/* directorin */ /* directorin */
%typemap(directorin,noblock=1) SWIGTYPE (CLASS::*) { %typemap(directorin,noblock=1) SWIGTYPE (CLASS::*) {
$input = SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor); $input = SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor);
} }
/* directorout */ /* directorout */
%typemap(directorout) SWIGTYPE (CLASS::*) { %typemap(directorout) SWIGTYPE (CLASS::*) {
int swig_res = SWIG_ConvertMember($input,%as_voidptr(&$result), sizeof($type), $descriptor); int swig_res = SWIG_ConvertMember($input,%as_voidptr(&$result), sizeof($result), $descriptor);
if (!SWIG_IsOK(swig_res)) { if (!SWIG_IsOK(swig_res)) {
%dirout_fail(swig_res,"$type"); %dirout_fail(swig_res,"$type");
} }