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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,976a050e0f89277c X-Google-Attributes: gid103376,public From: gwinn@ma.ultranet.com (Joe Gwinn) Subject: Re: Urgent question: malloc and ada... Date: 1998/04/09 Message-ID: #1/1 X-Deja-AN: 342619238 References: <352A79C2.15FB7483@nathan.gmd.de> X-Ultra-Time: 10 Apr 1998 02:52:35 GMT X-Complaints-To: abuse@ultra.net Organization: Gwinn Instruments Newsgroups: comp.lang.ada Date: 1998-04-09T00:00:00+00:00 List-Id: In article <352A79C2.15FB7483@nathan.gmd.de>, Guido Tesch wrote: > Hi there. > > I have a serious problem with interfacing between Ada and C. In a C > program, I allocate a lot of memory via malloc (more than one MB). When > I run the Ada program that interfaces with the C stuff, I get a > segmentation fault exactly at a point, where a subprocedure is called, > before even the first code line of this procedure is touched. My guess > is that the memory management from C and Ada do not work together when > doing big mallocs, and that some portion of my Ada program code had been > overwritten by C's mallocs. > > Do you have experiences with this kind of stuff? Could you tell me if > I'm right and how to solve this ugly problem? You don't have any reason to believe that this is a malloc versus Ada question, based on your description. In my experience, the fastest way to resolve such a problem is to debug the Ada and C programs with an assembly-level debugger, which can see things as they truely are. Put a breakpoint just before the fatal subroutine jump, and single-step into the subroutine. The cause should become blindingly obvious at that point. Don't assume that the Ada and C compilers have generated correct assembly code, or that they agree on how C-Ada subroutine interfaces work, in exact detail. It sounds like you are calling Ada from C; this is difficult to impossible with Ada83, and better with Ada95, but is often tricky. Ada83 really expected to be on top, to be the main(), and it was often easier to call C from an Ada main than to call Ada from a C main. C may well not be setting the stack and registers up to Ada's liking. Or vica versa. In Ada83, some compilers allowed one to declare Ada procedures as interrupt routines, with minimal expectations of the environment from which they will be called, and one can in fact call such routines from C, although passing parameters is difficult. Some compilers also allowed one to say that an Ada procedure would be called from some foreign language; this is like the ISR case, except one could have parameters. And so on. Joe Gwinn