Search code examples
cjava-native-interfaceswig

error: array type 'va_list' (aka '__builtin_va_list') is not assignable


What should i do to make it assignable? I have auto-generated the JNI function from this function which was in header file. Here is the function declaration in header file *

char* stringFormatV(const char* format, va_list args);

    SWIGEXPORT jstring JNICALL Java_jnisourceJNI_stringFormatV(JNIEnv
        *jenv, jclass jcls, jstring jarg1, jlong jarg2) {
              jstring jresult = 0 ;
              char *arg1 = (char *) 0 ;
              va_list arg2 ;
              va_list *argp2 ;
              char *result = 0 ;

              (void)jenv;
              (void)jcls;
              arg1 = 0;
              if (jarg1) {
                arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0);
                if (!arg1) return 0;
              }
              argp2 = *(va_list **)&jarg2; 
              if (!argp2) {
                SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null va_list");
                return 0;
              }
              arg2 = *argp2; //here is the problem
              result = (char *)stringFormatV((char const *)arg1,arg2);
              if (result) jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
              if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);
              return jresult;
            }

at this line compiler gives error

arg2 = *argp2; //here is the problem


Solution

  • You might want to read the variable length argument documentation. Especially the section about wrapping va_list which states

    As far as we know, there is no obvious way to wrap these functions with SWIG.

    In short, it's not really possible.

    The only solution I can see is to provide a variable-argument function which SWIG generate a function for, and this vararg function calls the real stringFormatV function.