Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!ifistg!abel.ifistg.uucp!greitman From: greitman@abel.ifistg.uucp Newsgroups: comp.lang.eiffel Subject: Problems with interfacing Eiffel and C Message-ID: <3953@ifi.informatik.uni-stuttgart.de> Date: 9 Aug 90 09:24:15 GMT Sender: news@ifistg.uucp Reply-To: greitman@abel.ifistg.uucp () Organization: IPVR/ISE, Univ. Stuttgart, W.Germany Lines: 210 I'm writing interface classes between Eiffel and Sun's XView-Toolkit (part of Open Windows Version 2.0 Beta). I'm working with a SPARC Station 1 under the Operating System SunOS Version 4.0.3c. There appeared some problems which are described in the following. 1. I have to pass the address of Eiffel features to "C". Here is my Eiffel feature with the appropriate "c"-call: left_mouse_down_add_me(button: XV_BUTTON) is external c_left_mouse_down_add_me(button: XV_BUTTON): INTEGER language "C"; do self := button; dummy := c_left_mouse_down_add_me(@self); -- pass the address of self to the "C" function. end; -- left_mouse_down_add_me In "C" the variable containing this address has the type OBJPTR. Then in the "C" -file I have the definition: static OBJPTR static_obj; and in file c_left_mouse_down_add_me in this file the assignment: static_obj = (OBJPTR) *obj; /* The notify procedure should be added to the Eiffel event left_mouse_down. It should be possible to write the action which should be executed at the event entry in Eiffel. int c_left_mouse_down_add_me(obj) int *obj; { int result; Xv_object *handle; static_obj = (OBJPTR) *obj; handle = (Xv_object *)eif_attr((OBJPTR)static_obj, "handle"); result = (int)xv_set(handle, PANEL_NOTIFY_PROC, left_mouse_down, NULL); return(result); } The function eif_attr in file _eifc.c doesn't return a correct value at the assignment index = search(Objptr, a_name, 0); int32 eif_attr (Objptr, a_name) OBJPTR Objptr; char *a_name; { DATUM index; index = search (Objptr, a_name, 0); if (index) return ((int32)(*(Access (Objptr)+index-1))); else ATTR_ERROR; } Function search in file _eifc.c stops with segmentation fault after the position: if (!strcmp (a_name, Attr_names [dtype][i])) return i+1. It looks like an initialization of Attr_names to "0" although it seems to be an array. Before this position I have following values: Objptr = (OBJPTR)0x6e2d0 a_name = (char *)0x58127 "handle" flag = 0 (!Objptr ||!a_name) = 0 dtype = 4 Object_size[dtype] = 1048577 nb_attr = 3 !flag = 1 i = 0 Attr_names[4][0]] =I/O Error, Cannot read memory, address 0x4 out of bounds. Attr_names[dtype][i] =I/O Error, Cannot read memory, address 0x4 out of bounds. Attr_names is of type int and it is initialized with value "0". I've got all these values running the debugger gdb on my root class. static unsigned int search (Objptr, a_name, flag) OBJPTR Objptr; char *a_name; int flag; { extern int16 obj_nb; register int16 i; char *tmp; char field_name [825]; int32 nb_attr, pos; int16 dtype; RESET; if (!Objptr || !a_name) return ((int32) 0); dtype = DType (Objptr); nb_attr = Object_size [dtype]; if (!flag) { for (i = 0; i < nb_attr; i++) if (!strcmp (a_name, Attr_names [dtype][i])) return i+1; } else { for (i =0; i < nb_attr; i++) { strcpy (field_name, Attr_names [dtype][i]); if (field_name [strlen (field_name)-1] == ' ') { tmp = Strtok (field_name, " "); for (pos=1; tmp != NULL; pos++) { if (!strcmp (a_name, tmp)) return ((i<<7) + pos + 1); tmp = Strtok (NULL, " "); } } } } } 2. Where do I find the definition of such types like OBJPTR, DATUM, DType, Attr_names, Attr_names[dtype][i], Strotok, etc ? 3. If you compile the file _eifc.c with Debug-Option (-g) you get two warnings (illegal combination of pointer and integer, op = ) in function search. static unsigned int search (Objptr, a_name, flag) OBJPTR Objptr; char *a_name; int flag; { extern int16 obj_nb; register int16 i; char *tmp; char field_name [825]; int32 nb_attr, pos; int16 dtype; RESET; if (!Objptr || !a_name) return ((int32) 0); dtype = DType (Objptr); nb_attr = Object_size [dtype]; if (!flag) { for (i = 0; i < nb_attr; i++) if (!strcmp (a_name, Attr_names [dtype][i])) return i+1; /* line 77 warning: illegal combination of pointer and integer, op = */ } else { for (i =0; i < nb_attr; i++) { strcpy (field_name, Attr_names [dtype][i]); if (field_name [strlen (field_name)-1] == ' ') { tmp = Strtok (field_name, " "); for (pos=1; tmp != NULL; pos++) { if (!strcmp (a_name, tmp)) return ((i<<7) + pos + 1); tmp = Strtok (NULL, " "); /* line 80 warning: illegal combination of pointer an dinteger, op = */ } } } } } 4. The documentation in the book "Eiffel: The Language Version2.2" about interfacing between Eiffel and "C" is absolutely insufficient. With only this information it is nearly impossible to write such interface classes. But we are dependant on such self written classes because the Eiffel Graphics Library Classes are not sufficient for our needs. Furthermore some parts like menus don't work at all. 5. Furtheron the graphical browser "GOOD" does not run at all. We have tested "GOOD" using Sun Open Windows Version 1.0 (X11 R3) and Open Windows Version 2.0 Beta (X11 R4) as well as MIT X11 R4. With all versions of X Windows "GOOD" crashed with segmentation fault. As "GOOD" is a very interesting tool especially to inspect the library classes delivered with the Eiffel system we hope that the next release of Eiffel will contain a running browser. 6. Another question during writing our interface classes is, wheather there are mechanisms to free data structures allacotated in "C" language parts based on the Eiffel garbage collection mechanism. This is a major problem because Eiffel has no facilities to write user defined destructor mechanisms. I hope that someone out there in netland or maybe at ISE can help us to solve the problems stated above. My request to ISE: If this is a known bug please patch it immediately and send us these patches. Many thanks in advance. Best regards Christiane Greitmann und Michael Ryba Stuttgart University Research Institut for Parallel and Distributed Supercomputers Department of Integrated Systems Design