From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,af5912fc4c056886,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-01 02:14:11 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: jadmoka@hotmail.com (Fatme Mokaddem) Newsgroups: comp.lang.ada Subject: using an ada package in java (with JGnat) Date: 1 Apr 2003 02:14:10 -0800 Organization: http://groups.google.com/ Message-ID: <7243325c.0304010214.ce7de23@posting.google.com> NNTP-Posting-Host: 63.100.219.179 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1049192051 12990 127.0.0.1 (1 Apr 2003 10:14:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 1 Apr 2003 10:14:11 GMT Xref: archiver1.google.com comp.lang.ada:35853 Date: 2003-04-01T10:14:11+00:00 List-Id: 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?