Menu

#1013 [lua] SWIG_check_num_args too strict

open
lua (25)
5
2022-03-07
2009-05-15
Sebastian
No

We moved from SWIG version 1.3.31 to 1.3.39 and found out, that SWIG now introduced the following sanity check:

SWIG_check_num_args

By doing so we can not write any wraper code anymore taking variable number of arguments.

For example, we wrote some typemap

%typemap\(in\) \(int n, double\* x\) \(double\*\) \{
    double \*y;
    double m, key;
    int n, k=0;
    const char \*text;
    size\_t nbytes;
    int i;
/\* get number of arguments \*/
    n = lua\_gettop\(L\)-1;
    $1 = n;
    y = new double\[n\];
/\* loop through each argument \*/
    for \(i = 0; i < n; i++\) \{
        y\[i\]= lua\_tonumber\(L, i+2\);
        \}
    nbytes = n\*sizeof\(double\);
    $2 = \(double\*\) lua\_newuserdata\(L, nbytes\);
    for \(k=0; k<n; k++\) \{
        $2\[k\] = y\[k\];
        \}
    delete y;
\}

This typemap wraps a method

void Read(int n, double * data);

which is interpreted in Lua as

void Read(double data1, double data2 , ... );

Off course we could use

%varargs

but this produces horrible wrapper code (think of 3000 possible arguments - for each combination an individual wrapper routine would be created).

Is it possible to make this configurable somehow?

For now we switched back to 1.3.31

Discussion

  • Olly Betts

    Olly Betts - 2012-05-18
    • summary: SWIG_check_num_args to strict --> [lua] SWIG_check_num_args too strict
     
  • Olly Betts

    Olly Betts - 2022-03-01

    You can put this in your interface file:

    %{
    #undef SWIG_check_num_args
    #define SWIG_check_num_args(func_name,a,b)
    %}
    

    It's rather a crude solution though, and disables it for all wrapped functions in the module.

     
  • Olly Betts

    Olly Betts - 2022-03-07

    https://github.com/swig/swig/pull/189 includes an "unlimited args" setting which I think would provide a cleaner solution to this.

     

Log in to post a comment.