From: Freejack <freejack@nospam.net>
Subject: Re: Importing C structs?
Date: Wed, 30 Jul 2003 21:26:26 GMT
Date: 2003-07-30T21:26:26+00:00 [thread overview]
Message-ID: <pan.2003.07.30.21.32.25.223472.1022@nospam.net> (raw)
In-Reply-To: ddWVa.1313$Kx1.14581@newsfep4-glfd.server.ntli.net
On Wed, 30 Jul 2003 16:52:49 -0400, chris wrote:
> Make an Ada record corresponding to that type. Map it's fields to
> things from interfaces.c and other records. Then use
>
> pragma Convention(C, DBType);
>
> I think!
>
> This is from my ongoing work on a libjpeg binding...
>
> type Jpeg_Error_Mgr is record
> Error_Exit : Error_Exit_Handler; Emit_Message :
> Emit_Message_Handler; Output_Message :
> Output_Message_Handler; Format_Message :
> Format_Message_Handler; Reset_Error_Mgr :
> Reset_Error_Handler; Msg_Code : C.Int; Msg_Parm
> : System.Address; Trace_Level : C.Int;
> Num_Warnings : C.Long;
> Jpeg_Message_Table : Jpeg_Message_TableT; Last_Jpeg_Message :
> C.Int;
> Addon_Message_Table : Jpeg_Message_TableT; First_Addon_Message :
> C.Int;
> Last_Addon_Message : C.Int;
> end record;
>
> pragma Convention (C, Jpeg_Error_Mgr);
> HTH,
> Chris
I've been toying with the idea of creating a generic procedure for these
types of situations. I dont know if Ada will let me get away with it
though.
i.e.
with Interfaces.C;
with Interfaces.C....blah blah blah;
generic
type foo is new private(<>);
type bar is new private(<>);
package dooh_dah is
package Some_C renames Interfaces.C.blah;
private
function cast_to_C(foo : in Ada_Type) return Is_Success;
-- etc..etc..etc...
end dooh_dah;
Now, I realize that the Interfaces library provides a limited set of
functions and procedures for performing some of the operations I'm
talking about here. But as far as I know everything has to be set up
explicitly. I'm hoping theres a way to have the compiler do an automatic
cast (or export) to a C function depending the execution context.
But that type of programming is a little ways down the road. I dont have
a need for this yet, but maybe later.
Freejack.
next prev parent reply other threads:[~2003-07-30 21:26 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-30 20:03 Importing C structs? Freejack
2003-07-30 20:52 ` chris
2003-07-30 21:26 ` Freejack [this message]
2003-07-30 23:50 ` tmoran
2003-07-31 10:53 ` chris
2003-08-04 14:33 ` Andreas Almroth
2003-08-04 15:16 ` Samuel Tardieu
2003-08-04 20:07 ` Randy Brukardt
2003-07-31 17:14 ` Warren W. Gay VE3WWG
2003-08-12 0:02 ` chris
2003-07-31 18:17 ` Xenos
2003-07-31 19:16 ` Simon Wright
2003-07-31 20:17 ` Samuel Tardieu
2003-07-31 20:40 ` Xenos
2003-07-30 23:14 ` Ching Bon Lam
2003-07-31 0:07 ` tmoran
2003-07-31 5:35 ` Matthew Heaney
2003-07-31 7:46 ` Freejack
2003-07-31 9:27 ` Martin Dowie
2003-07-31 21:41 ` Freejack
2003-08-01 7:39 ` Martin Dowie
2003-07-31 17:34 ` Matthew Heaney
2003-07-31 11:29 ` Ching Bon Lam
2003-07-31 16:59 ` Matthew Heaney
2003-07-31 17:32 ` Warren W. Gay VE3WWG
2003-07-31 17:13 ` Matthew Heaney
2003-07-31 17:40 ` Randy Brukardt
2003-07-31 5:21 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox