comp.lang.ada
 help / color / mirror / Atom feed
* using an ada package in java (with JGnat)
@ 2003-04-01 10:14 Fatme Mokaddem
  0 siblings, 0 replies; only message in thread
From: Fatme Mokaddem @ 2003-04-01 10:14 UTC (permalink / raw)


Hello, 

I have a package written in ada and I am trying to use it in a java
program. I added to the package the function to_ada_string which takes
as input a java string and returns an Ada string. This function was
provided in the examples that come with the JGnat compiler. But it's
giving me a runtime "storage_error" when I try to call it from my java
program.

Here is the code I am using: 

package body A 

  function To_Ada_String(x : in Java.Lang.String.Ref) return String is
     Bytes : Java.Byte_Arr; 
  begin 
     Bytes := Java.Lang.String.getBytes(x); 
     declare 
        Result : String(1..Bytes.all'Length); 
     begin 
        for i in Result'range loop 
           Result(i) := Character'Val(Bytes(Bytes.all'First+i-1)); 
        end loop; 
        return Result; 
     end; 
  end To_Ada_String; 

  function adaMethod(input: java.Lang.String.ref) return
java.Lang.String.ref
  begin 
      return(to_java_string(to_ada_string(input)); 
  end adaMethod; 

  -- other methods... 
  -- ... ... 
end A; 

(to_java_string takes an ada string and returns a java string, and it
works fine by itself)

inside the java code, I am calling it in the following way: 

String s = new String("anyString"); 
s = A.adaMethod(s); 

I think that the main problem in is allocating space for an ada String
"Result" since when I replace "Bytes.all'Length" by a constant integer
(e.g. String(1..5) everything works fine.

Can anyone help?



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-04-01 10:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-01 10:14 using an ada package in java (with JGnat) Fatme Mokaddem

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox