comp.lang.ada
 help / color / mirror / Atom feed
From: gwinn@ma.ultranet.com (Joe Gwinn)
Subject: Re: Urgent question: malloc and ada...
Date: 1998/04/09
Date: 1998-04-09T00:00:00+00:00	[thread overview]
Message-ID: <gwinn-0904982253200001@d183.dial-5.cmb.ma.ultra.net> (raw)
In-Reply-To: 352A79C2.15FB7483@nathan.gmd.de


In article <352A79C2.15FB7483@nathan.gmd.de>, Guido Tesch
<tesch@nathan.gmd.de> 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




  reply	other threads:[~1998-04-09  0:00 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-07  0:00 Urgent question: malloc and ada Guido Tesch
1998-04-09  0:00 ` Joe Gwinn [this message]
1998-04-10  0:00   ` Urgent question: malloc and ada...READ/NEW/FOLLOWUP Larry Kilgallen
1998-04-12  0:00     ` Joe Gwinn
1998-04-14  0:00       ` Robert Dewar
1998-04-16  0:00         ` Joe Gwinn
1998-04-17  0:00           ` Robert Dewar
1998-04-18  0:00             ` Joe Gwinn
1998-04-18  0:00               ` Robert Dewar
1998-04-25  0:00                 ` Joe Gwinn
1998-04-26  0:00                   ` Robert Dewar
1998-04-26  0:00                     ` Jonathan Guthrie
1998-04-26  0:00                       ` Robert Dewar
1998-04-26  0:00                       ` Simon Wright
1998-04-26  0:00                         ` Larry Kilgallen
1998-04-27  0:00                           ` Stephen Leake
1998-04-30  0:00                       ` Robert I. Eachus
1998-04-30  0:00                         ` Urgent question: malloc and ada Larry Kilgallen
1998-05-01  0:00                           ` Robert Dewar
1998-05-01  0:00                             ` Charles Hixson
1998-05-02  0:00                               ` Jonathan Guthrie
1998-05-02  0:00                             ` Corey Minyard
1998-05-06  0:00                             ` Robert I. Eachus
1998-05-12  0:00                               ` Craig T. Spannring
1998-05-12  0:00                                 ` Robert Dewar
     [not found]                           ` <matthew_heaney-ya023680003004981723000001@news.ni.net>
1998-05-01  0:00                             ` Robert Dewar
1998-05-01  0:00                               ` Larry Kilgallen
1998-05-02  0:00                                 ` Robert Dewar
1998-05-02  0:00                                   ` Jonathan Guthrie
1998-05-03  0:00                                     ` Robert Dewar
1998-05-03  0:00                                     ` Richard Kenner
1998-05-03  0:00                                       ` Jonathan Guthrie
1998-05-03  0:00                                         ` Robert Dewar
1998-05-03  0:00                                         ` Richard Kenner
1998-05-03  0:00                                   ` Larry Kilgallen
1998-05-01  0:00                       ` Urgent question: malloc and ada...READ/NEW/FOLLOWUP Fergus Henderson
1998-05-01  0:00                     ` Joe Gwinn
1998-05-02  0:00                       ` Larry Kilgallen
1998-05-05  0:00                       ` Robert Dewar
1998-04-10  0:00   ` Urgent question: malloc and ada Robert Dewar
1998-04-12  0:00     ` Joe Gwinn
1998-04-12  0:00       ` Enumeration Types (was: Urgent question: malloc and ada) Matthew Heaney
1998-04-13  0:00         ` Mark A Biggar
replies disabled

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