comp.lang.ada
 help / color / mirror / Atom feed
* program error (exception access violation) in windows
@ 2006-09-26 23:18 ldb
  2006-09-27  2:22 ` tmoran
  2006-09-27 12:51 ` Martin Krischik
  0 siblings, 2 replies; 3+ messages in thread
From: ldb @ 2006-09-26 23:18 UTC (permalink / raw)


> raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION

We have tried, in numerous ways, to come up with an ada library that
can be used by c programs. The ada program needs to return a pretty
large and ugly dynamic structure. For the sake of discussion, think of
it as an array of structs (with pointers to dynamic sub-arrays).

I've gotten it to work flawlessly under linux using shared libraries. I
use a combination of importing malloc() and the
Ada.Address_To_Access_Conversions package. In this way, I can malloc
the correctly sized eventual c data-structure, and use the created
access from that package to populate the data structure. When I return
the address of that to C, everything appears to work fine. I can free
it like any other C data structure.

It seems to fail (sometimes) when I move it to windows (using a c
program and my ada-based dll), resulting in the above exception. When I
remove the free calls, in c, everything works fine (and memory leaks).
I have a 'minimal' program that uses a simple array of integers, and it
seems to work fine, but for our main program, it still crashes.
Tommorow, I'm going to rip apart our program to see if I can find a
minimal example of the crashing behavior.

We've tried numerous different ways of allocating the memory in ada,
and free'ing it in C. We even got a smiliar error when we tried
allocating it in Ada, and free'ing it in Ada through another C call to
the ada library. We are about to change our interface from Ada to
single elements, only, and have C wrapper functions that do all the
allocating and query for each single value to populate the data
structure.

Has anyone heard of issues like this? Or have a possible guess as to
what is going on?




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: program error (exception access violation) in windows
  2006-09-26 23:18 program error (exception access violation) in windows ldb
@ 2006-09-27  2:22 ` tmoran
  2006-09-27 12:51 ` Martin Krischik
  1 sibling, 0 replies; 3+ messages in thread
From: tmoran @ 2006-09-27  2:22 UTC (permalink / raw)


> raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
  Memory allocation is clearly very compiler dependent.  I guess you
are using some variety of Gnat?  What does a stack traceback show?
Does the Linux version run with the same series of allocations
and pass successfully through the point where the Windows version
finds itself with a null pointer?
  Are you sure this exception is being raised by your Ada program's
attempt to reference through a null pointer, or might it be something
down inside the run-time system that could be different in Linux
vs Windows Gnat?

> We've tried numerous different ways of allocating the memory in ada,
> and free'ing it in C. We even got a smiliar error when we tried
> allocating it in Ada, and free'ing it in Ada through another C call to
> the ada library.
  If you do all the allocation and deallocation within your Ada
program, and none in the C program, do you still have problems?
How about if you don't use any Ada "new" or Unchecked_Deallocation,
but always make explicit calls to C routines.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: program error (exception access violation) in windows
  2006-09-26 23:18 program error (exception access violation) in windows ldb
  2006-09-27  2:22 ` tmoran
@ 2006-09-27 12:51 ` Martin Krischik
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Krischik @ 2006-09-27 12:51 UTC (permalink / raw)


ldb schrieb:
>> raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
> 
> We have tried, in numerous ways, to come up with an ada library that
> can be used by c programs. The ada program needs to return a pretty
> large and ugly dynamic structure. For the sake of discussion, think of
> it as an array of structs (with pointers to dynamic sub-arrays).
> 
> I've gotten it to work flawlessly under linux using shared libraries. I
> use a combination of importing malloc() and the
> Ada.Address_To_Access_Conversions package. In this way, I can malloc
> the correctly sized eventual c data-structure, and use the created
> access from that package to populate the data structure. When I return
> the address of that to C, everything appears to work fine. I can free
> it like any other C data structure.
> 
> It seems to fail (sometimes) when I move it to windows (using a c
> program and my ada-based dll), resulting in the above exception. When I
> remove the free calls, in c, everything works fine (and memory leaks).
> I have a 'minimal' program that uses a simple array of integers, and it
> seems to work fine, but for our main program, it still crashes.
> Tommorow, I'm going to rip apart our program to see if I can find a
> minimal example of the crashing behavior.
> 
> We've tried numerous different ways of allocating the memory in ada,
> and free'ing it in C. We even got a smiliar error when we tried
> allocating it in Ada, and free'ing it in Ada through another C call to
> the ada library. We are about to change our interface from Ada to
> single elements, only, and have C wrapper functions that do all the
> allocating and query for each single value to populate the data
> structure.
> 
> Has anyone heard of issues like this? Or have a possible guess as to
> what is going on?

I once worked with C. Now I used gnat wich internaly uses malloc and 
free anyway. Still I went thrue the trouble of localising all the memory 
management on one side. Also I did not just provide a malloc and free 
c-likes but OO "contructors" and "destructors" constructs.

Ok, you end up with lots of Xxxx_New and Xxxx_Delete functions but all 
worked fine in the end.

Martin



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-09-27 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-26 23:18 program error (exception access violation) in windows ldb
2006-09-27  2:22 ` tmoran
2006-09-27 12:51 ` Martin Krischik

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