This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cni converting String args[]


* littlejohn@paranoici.org (littlejohn@paranoici.org) ha scritto:
> * Andrew Haley (aph@redhat.com) ha scritto:
> >  >       arguments[i] = (char *) elements(argsElements[i]->getBytes());
> > 
> > If you want chars, you'll need an encoding -- elements returns a
> > jchar*.  Try JvGetStringUTFRegion.
> 
>  ok, I'll let you know

jint A::init(JArray< ::java::lang::String *> *args) {

  int argc = 0;
  char* arguments[argc];

  if (args != NULL) // It's a very bad day otherwise
  {
    argc = args->length;
    arguments[argc];

    /*
    * convert the JArray<String*>*  in char**
    * so in a way suitable for VLC_Init
    */
    ::java::lang::String** argsElements = elements(args);

    for (int i = 0; i < argc; i++) {
      ::java::lang::System::out->println(argsElements[i]->length());
      JvGetStringUTFRegion(argsElements[i], 0,
      argsElements[i]->length(), arguments[i]);
      printf("library: %s\n", arguments[i]);
    }
  }
  return 0;
}

 does not work. If i issue the command:

% A --help --helpp

 i get
6 (the length of --help)
library: --help (the printf)
7 (the length of --helpp)
Exception in thread "main" java.lang.NullPointerException

 debugging with gdb, I see a strange thing. Maybe related to the
gc. On the second iteration, just after the JvGetStringUTFRegion the
arguments array is:

(gdb) print arguments 
$1 = {0x0, 0x0}

 I can understand why.

 lj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]