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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dc8f36bc68388cb3,start X-Google-Attributes: gid103376,public From: Shayne Flint Subject: 'image fails in Ada callback from Java Date: 1997/12/29 Message-ID: <34A77493.5C93@ainslie-software.com>#1/1 X-Deja-AN: 310972379 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: Ainslie Software Pty Limited Mime-Version: 1.0 Reply-To: shayne@ainslie-software.com Newsgroups: comp.lang.ada Date: 1997-12-29T00:00:00+00:00 List-Id: I have a fustrating problem when using Ada with Java. I am using Gnat 3.10p and JDK 1.1.5 on Windows NT4sp3. The problem also applies to Gnat 3.09 and JDK 1.1.4. I am using the Java Native Interface (JNI) from Ada via a set of bindings I have built. I am able to do most things including the use of Ada to handle Java events. My problem is that an Ada callback procedure, setup to handle a Java event, aborts the program when it uses the 'image attribute. If the callback is called from Ada or another Java method things work as expected. It is only when the callback is called by Java in response to an event that things go wrong. I have built the following three tests to help diagnose the problem. CASE ONE: "C", "Java" and "Java Events" --------------------------------------- This test is an all "C" and "Java" implementation (no Ada at all). The C main calls JNI to create a window and button, and to setup the Java side so that a C function is called when the button is clicked. This test works OK. "C Side" "Java side (class MyListener)" ======== ============================== C1. create window via JNI C2. create button via JNI C3. register C function 'callback' as Java native method in Java class MyListener (extends ActionListener). C4. create instance of Java class MyListener C5. add MyListener instance to button J1. user Clicks Button J2. actionPerformed in MyListener called J3. actionPerformed calls NativeMethod (ie. C function 'callback') CASE TWO: "Ada" and "Java" (no java events) ------------------------------------------- The second test uses an Ada main which calls Java to test its ability to callback to Ada without anything to do with Java events. This test works as expected. ie. The use of 'image within the Ada callback routine works properly. "Ada Side" "Java side (class TestClass)" ========== ============================== A1. register Ada procedure 'callback' as Java native method in Java class TestClass A2. create instance of Java class TestClass A3. call java Native method in TestClass J1. NativeMethod implemented by Ada procedure displays parameters using 'image CASE THREE: "Ada", "Java" and "Java Events" ------------------------------------------- The third case is an Ada and Java implementation of the first test described above (the C code was replaced by Ada). In this case things work as expected until the Ada callback procedure attempts to use 'image. When this happens, the program aborts with the error message shown below. "Ada Side" "Java side (class MyListener)" ========== ============================== C1. create window via JNI C2. create button via JNI C3. register Ada procedure 'callback' as Java native method in Java class MyListener (extends ActionListener) C4. create instance of Java class MyListener C5. add MyListener instance to button J1. user Clicks Button J2. actionPerformed in MyListener called J3. actionPerformed calls NativeMethod (ie. Ada procedure 'callback') This Ada procedure fails when it attempts to use 'image. The error is as follows (displayed in a pop up window with OK and CANCEL buttons) The instruction at "0x0040cd30" referenced memory at "0x00000018". The memory could not be "read" Does anyone have any idea what is going on here? Maybe some input on how 'image is implemented by Gnat would be a good start. thanks. ------------------------------------------------------------------ -- Shayne Flint, MIEAust, CPEng shayne@ainslie-software.com -- Ainslie Software Pty Limited http://www.ainslie-software.com -- -- ShapeDB, a database and form drawing add-on for Visio ------------------------------------------------------------------