comp.lang.ada
 help / color / mirror / Atom feed
* Binding to C
@ 2003-07-21 18:59 chris
  2003-07-21 20:02 ` Martin Krischik
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: chris @ 2003-07-21 18:59 UTC (permalink / raw)


Hi,

I came across the following in libjpeg... what should I map it to?

const char* const* jpeg_message_table

Also does anyone have any advice in general mapping to C.  For the 
jpeg_error_mgr struct, I mapped ptrs to functions to System.Address and 
made the struct a record.  Will this work, or will the corresponding 
type of the struct have to be a System.Address?


Chris

package Low_Jpg.Error is

    package C renames Interfaces.C;

    type Jpeg_Error_Mgr is record
       Error_Exit      : System.Address; -- addr of a handler
       Emit_Message    : System.Address;
       Output_Message  : System.Address;
       Format_Message  : System.Address;
       Reset_Error_Mgr : System.Address;
       Msg_Code        : C.Int;
       Msg_Parm        : System.Address;
       Trace_Level     : C.Int;
       Num_Warnings    : C.Long;
    end record;
    pragma Convention (C, Jpeg_Error_Mgr);

end Low_Jpg.Error;




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

* Re: Binding to C
  2003-07-21 18:59 Binding to C chris
@ 2003-07-21 20:02 ` Martin Krischik
  2003-07-22 17:12   ` chris
  2003-07-27 13:07   ` Matthew Heaney
  2003-07-21 21:07 ` tmoran
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 17+ messages in thread
From: Martin Krischik @ 2003-07-21 20:02 UTC (permalink / raw)


chris wrote:

> Hi,
> 
> I came across the following in libjpeg... what should I map it to?
> 
> const char* const* jpeg_message_table

const works to the left unless it comes first. So:

(const char) (* const)* jpeg_message_table

Try:

type jpeg_message is access constant character;
type jpeg_message_table is access constant jpeg_message;

> 

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Binding to C
  2003-07-21 18:59 Binding to C chris
  2003-07-21 20:02 ` Martin Krischik
@ 2003-07-21 21:07 ` tmoran
  2003-07-21 21:57   ` chris
  2003-07-27 13:04 ` Matthew Heaney
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: tmoran @ 2003-07-21 21:07 UTC (permalink / raw)


>Also does anyone have any advice in general mapping to C.
 Look at some of the Windows binding source code at www.adapower.com
>For the jpeg_error_mgr struct, I mapped ptrs to functions to System.Address
>and made the struct a record.  Will this work, or will the corresponding
>type of the struct have to be a System.Address?
 You almost never need a System.Address.  Use access types.

>   type Jpeg_Error_Mgr is record
>      Error_Exit      : System.Address; -- addr of a handler
>      Emit_Message    : System.Address;
> ...
 Instead:

  type Error_Exit_Ptr is access
  procedure (cinfo   : access Decompress_Cinfo_Type);
  pragma Convention(C, Error_Exit_Ptr);

  type Emit_Message_Ptr is access
  procedure (cinfo    : access Decompress_Cinfo_Type;
             msg_level: Interfaces.C.Int);
  pragma Convention(C, Emit_Message_Ptr);
  ...

  procedure error_exit(cinfo   : access Decompress_Cinfo_Type);
  pragma Export(C, error_exit);

  procedure emit_message(cinfo    : access Decompress_Cinfo_Type;
                         msg_level: Interfaces.C.Int);
  pragma Export(C, Emit_Message);
  ...

  type Jpeg_Error_Mgr is record
    P_Error_Exit: Error_Exit_Ptr;     -- will be set := error_exit'access;
    P_Emit_Message: Emit_Message_Ptr; -- will be set := emit_message'access;
etc.



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

* Re: Binding to C
  2003-07-21 21:07 ` tmoran
@ 2003-07-21 21:57   ` chris
  0 siblings, 0 replies; 17+ messages in thread
From: chris @ 2003-07-21 21:57 UTC (permalink / raw)


tmoran@acm.org wrote:
>>Also does anyone have any advice in general mapping to C.
> 
>  Look at some of the Windows binding source code at www.adapower.com
> 
>>For the jpeg_error_mgr struct, I mapped ptrs to functions to System.Address
>>and made the struct a record.  Will this work, or will the corresponding
>>type of the struct have to be a System.Address?
> 
>  You almost never need a System.Address.  Use access types.

Thanks, I've converted the small amount done so far to use access types. 
  What about unions?  I don't really care what's in the union, it's 
under the control of the lib, should I put a char_array of size 
JMSG_STR_PARM_MAX in there?


struct jpeg_error_msg {

   ...

   union {
     int i[8];
     char s[JMSG_STR_PARM_MAX];
   } msg_parm;
}

chris
--
to reply change 'spamoff' to 'chris'




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

* Re: Binding to C
  2003-07-21 20:02 ` Martin Krischik
@ 2003-07-22 17:12   ` chris
  2003-07-23 13:47     ` Martin Krischik
  2003-07-27 13:11     ` Matthew Heaney
  2003-07-27 13:07   ` Matthew Heaney
  1 sibling, 2 replies; 17+ messages in thread
From: chris @ 2003-07-22 17:12 UTC (permalink / raw)


Martin Krischik wrote:
> chris wrote:
> 
> 
>>Hi,
>>
>>I came across the following in libjpeg... what should I map it to?
>>
>>const char* const* jpeg_message_table
> 
> 
> const works to the left unless it comes first. So:
> 
> (const char) (* const)* jpeg_message_table

Yuck!  I thought it was

(const char *) (const *) jpeg_message_table;

which is (iirc)

type jpeg_message_table is access constant CStrings.chars_ptr;


I hate C!






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

* Re: Binding to C
  2003-07-22 17:12   ` chris
@ 2003-07-23 13:47     ` Martin Krischik
  2003-07-27 13:11     ` Matthew Heaney
  1 sibling, 0 replies; 17+ messages in thread
From: Martin Krischik @ 2003-07-23 13:47 UTC (permalink / raw)


chris wrote:

> Martin Krischik wrote:
>> chris wrote:
>> 
>> 
>>>Hi,
>>>
>>>I came across the following in libjpeg... what should I map it to?
>>>
>>>const char* const* jpeg_message_table
>> 
>> 
>> const works to the left unless it comes first. So:
>> 
>> (const char) (* const)* jpeg_message_table
> 
> Yuck!  I thought it was
> 
> (const char *) (const *) jpeg_message_table;

The difference is only that the last * is not constant. But for a parameter
to a function this makes no difference to the user of the function.

> which is (iirc)
> 
> type jpeg_message_table is access constant CStrings.chars_ptr;
 
> I hate C!

Met too.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Binding to C
  2003-07-21 18:59 Binding to C chris
  2003-07-21 20:02 ` Martin Krischik
  2003-07-21 21:07 ` tmoran
@ 2003-07-27 13:04 ` Matthew Heaney
  2003-07-28 20:52 ` Freejack
  2003-08-09 11:29 ` Patrice Freydiere
  4 siblings, 0 replies; 17+ messages in thread
From: Matthew Heaney @ 2003-07-27 13:04 UTC (permalink / raw)


"chris" <spamoff.danx@ntlworld.com> wrote in message
news:MxXSa.2290$l63.28380@newsfep4-glfd.server.ntli.net...
>
> I came across the following in libjpeg... what should I map it to?
>
> const char* const* jpeg_message_table

This is a pointer to a constant array, comprising pointers to constant
strings.

You could use the types in Interfaces.C.*.  Here's another way to do it:

type char_array is array (Natural) of aliased Character;
pragma Convention (C, char_array);
pragma Suppress (Index_Check, On => char_array);

type const_char_ptr is access constant char_array;
for const_char'Storage_Size use 0;
pragma Convention (C, const_char_ptr);

type string_array is array (Natural) of aliased const_char_ptr;
pragma Convention (C, string_array);
pragma Suppress (Index_Check, On => string_array);

type const_string_ptr is access constant string_array;
for const_string_ptr'Storage_Size use 0;
pragma Convention (C, const_string_ptr);

JPEG_Message_Table : const_string_ptr;  -- voila!

-Matt





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

* Re: Binding to C
  2003-07-21 20:02 ` Martin Krischik
  2003-07-22 17:12   ` chris
@ 2003-07-27 13:07   ` Matthew Heaney
  1 sibling, 0 replies; 17+ messages in thread
From: Matthew Heaney @ 2003-07-27 13:07 UTC (permalink / raw)



"Martin Krischik" <krischik@users.sourceforge.net> wrote in message
news:13934627.ulbWRIerNL@linux1.krischik.com...
>
> Try:
>
> type jpeg_message is access constant character;
> type jpeg_message_table is access constant jpeg_message;

This is not a very useful binding, as a message table is an array of
strings.  I showed the correct binding in my previous post.






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

* Re: Binding to C
  2003-07-22 17:12   ` chris
  2003-07-23 13:47     ` Martin Krischik
@ 2003-07-27 13:11     ` Matthew Heaney
  1 sibling, 0 replies; 17+ messages in thread
From: Matthew Heaney @ 2003-07-27 13:11 UTC (permalink / raw)



"chris" <spamoff.danx@ntlworld.com> wrote in message
news:f3fTa.342$xe6.5412@newsfep4-glfd.server.ntli.net...
> Martin Krischik wrote:
>
> type jpeg_message_table is access constant CStrings.chars_ptr;

Not quite:

type string_array is array (Natural) of aliased CStrings.chars_ptr;
pragma Convention (C, string_array);

type Table_Type is access constant string_array;
pragma Convention (C, Table_Type);
for Table_Type'Storage_Size use 0;

JPEG_Message_Table : Table_Type;






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

* Re: Binding to C
  2003-07-21 18:59 Binding to C chris
                   ` (2 preceding siblings ...)
  2003-07-27 13:04 ` Matthew Heaney
@ 2003-07-28 20:52 ` Freejack
  2003-07-29 19:21   ` chris
  2003-08-09 11:29 ` Patrice Freydiere
  4 siblings, 1 reply; 17+ messages in thread
From: Freejack @ 2003-07-28 20:52 UTC (permalink / raw)


On Mon, 21 Jul 2003 14:59:30 -0400, chris wrote:

> Hi,
> 
> I came across the following in libjpeg... what should I map it to?
> 
> const char* const* jpeg_message_table
> 
> Also does anyone have any advice in general mapping to C.  For the
> jpeg_error_mgr struct, I mapped ptrs to functions to System.Address and
> made the struct a record.  Will this work, or will the corresponding
> type of the struct have to be a System.Address?

I'd like to add a question...

Has anyone done any sort of specific tutorial on Interfaces.C or
interfacing with C from Ada in general.

This seems to be a question that get's asked a lot in this newsgroup. I
know I could use some good helper docs (along with the LRM) on this
particular subject.

I'm currently trying to create a thin binding to the SleepyCat Berkely DB
library, and I'm spending most of my time looking at other bindings to
figure out what goes where.
Some of the bindings are very good, but it is a bit frustrating at times.

NiCad



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

* Re: Binding to C
  2003-07-28 20:52 ` Freejack
@ 2003-07-29 19:21   ` chris
  0 siblings, 0 replies; 17+ messages in thread
From: chris @ 2003-07-29 19:21 UTC (permalink / raw)


Freejack wrote:

> I'd like to add a question...
> 
> Has anyone done any sort of specific tutorial on Interfaces.C or
> interfacing with C from Ada in general.

I looked at the Big book of Ada Linux Programming which has binding 
stuff in it, but it's not an indepth tutorial.  There's also some stuff 
in The Lovelace Tutorial iirc.




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

* Re: Binding to C
  2003-07-21 18:59 Binding to C chris
                   ` (3 preceding siblings ...)
  2003-07-28 20:52 ` Freejack
@ 2003-08-09 11:29 ` Patrice Freydiere
  2003-08-09 13:09   ` Jeffrey Creem
  2003-08-11 23:49   ` chris
  4 siblings, 2 replies; 17+ messages in thread
From: Patrice Freydiere @ 2003-08-09 11:29 UTC (permalink / raw)



Chris, if you are looking for building a complete full Jpeg binding, 
your can browse the AGP project (ada game programming)
it contains a jpeg binding, and a PNG binding.

so it can gives you some ideas for C binding from ADA.

hope this help.
Patrice

ps: when i started writing the simplejpeglib binding for ADA.
i had a lot of interfacing problems du to the portability macros of the
jpeglib. (it's surely possible, but when i've started my binding, my C
interfacing Skills from ADA was poor).
So i decided in my design to build a simple C interface to make Ada
binding easier. This permit me to be "C structure independent" and provide a
more easy upgrade of the jpeglib.


On Mon, 21 Jul 2003 20:59:30 +0200, chris wrote:

> Hi,
> 
> I came across the following in libjpeg... what should I map it to?
> 
> const char* const* jpeg_message_table
> 
> Also does anyone have any advice in general mapping to C.  For the 
> jpeg_error_mgr struct, I mapped ptrs to functions to System.Address and 
> made the struct a record.  Will this work, or will the corresponding 
> type of the struct have to be a System.Address?
> 
> 
> Chris
> 
> package Low_Jpg.Error is
> 
>     package C renames Interfaces.C;
> 
>     type Jpeg_Error_Mgr is record
>        Error_Exit      : System.Address; -- addr of a handler
>        Emit_Message    : System.Address;
>        Output_Message  : System.Address;
>        Format_Message  : System.Address;
>        Reset_Error_Mgr : System.Address;
>        Msg_Code        : C.Int;
>        Msg_Parm        : System.Address;
>        Trace_Level     : C.Int;
>        Num_Warnings    : C.Long;
>     end record;
>     pragma Convention (C, Jpeg_Error_Mgr);
> 
> end Low_Jpg.Error;




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

* Re: Binding to C
  2003-08-09 11:29 ` Patrice Freydiere
@ 2003-08-09 13:09   ` Jeffrey Creem
  2003-08-09 13:54     ` Patrice Freydiere
  2003-08-11 23:49   ` chris
  1 sibling, 1 reply; 17+ messages in thread
From: Jeffrey Creem @ 2003-08-09 13:09 UTC (permalink / raw)



"Patrice Freydiere" <frett27@free.fr> wrote in message
news:pan.2003.08.09.11.28.57.794916@free.fr...
>
> Chris, if you are looking for building a complete full Jpeg binding,
> your can browse the AGP project (ada game programming)
> it contains a jpeg binding, and a PNG binding.
>

How about a link?? AGP is hardly a unique search term.





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

* Re: Binding to C
  2003-08-09 13:09   ` Jeffrey Creem
@ 2003-08-09 13:54     ` Patrice Freydiere
  0 siblings, 0 replies; 17+ messages in thread
From: Patrice Freydiere @ 2003-08-09 13:54 UTC (permalink / raw)



Jeffrey, 
i havn't found a web site for Agp , the only link i have is this 

http://www.gnuada.org/alt.html

you'll find a Href to the sources.

Patrice

#
# The Ada Game Package (AGP). The package agp95_v0.1_x11.tar.gz (1719 kB) is targeted for XFree86, the package  agp95_v0.1_fb.tar.gz (1719 kB)  for the GNU/Linux framebuffer console. There is also a partial binding to the Linux framebuffer console (17 kB). These packages compile with gnat-3.11p. If you want to use gnat-3.12p, you have to download this fix package.The software is GPLed, the authors are Wesley Y. Pan and Weston T. Pan.


On Sat, 09 Aug 2003 13:09:21 +0000, Jeffrey Creem wrote:

> 
> "Patrice Freydiere" <frett27@free.fr> wrote in message
> news:pan.2003.08.09.11.28.57.794916@free.fr...
>>
>> Chris, if you are looking for building a complete full Jpeg binding,
>> your can browse the AGP project (ada game programming)
>> it contains a jpeg binding, and a PNG binding.
>>
> 
> How about a link?? AGP is hardly a unique search term.




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

* Re: Binding to C
  2003-08-09 11:29 ` Patrice Freydiere
  2003-08-09 13:09   ` Jeffrey Creem
@ 2003-08-11 23:49   ` chris
  2003-08-12  6:40     ` Patrice Freydiere
  1 sibling, 1 reply; 17+ messages in thread
From: chris @ 2003-08-11 23:49 UTC (permalink / raw)


Patrice Freydiere wrote:

> so it can gives you some ideas for C binding from ADA.

Thanks.


> ps: when i started writing the simplejpeglib binding for ADA.
> i had a lot of interfacing problems du to the portability macros of the
> jpeglib. (it's surely possible, but when i've started my binding, my C
> interfacing Skills from ADA was poor).
> So i decided in my design to build a simple C interface to make Ada
> binding easier. This permit me to be "C structure independent" and provide a
> more easy upgrade of the jpeglib.

This is a problem... and I haven't found a *convienant* way to solve 
this (other than wrapping it up as you and Warren pointed out - thanks). 
  Macros change this, that and the other.  My ada code would need to be 
changed at the spec level on different platforms, compilers, etc... 
yuck.  A more experienced Ada developer could probably organise it 
better, but

All I really want to do now is *decode* and encode (at various 
qualities) a jpeg (in RBG).  Later things might get more complicated, 
but for now that's it.  I'm going to look at your lib again now I've got 
a bit more time.




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

* Re: Binding to C
  2003-08-11 23:49   ` chris
@ 2003-08-12  6:40     ` Patrice Freydiere
  2003-08-12 11:58       ` chris
  0 siblings, 1 reply; 17+ messages in thread
From: Patrice Freydiere @ 2003-08-12  6:40 UTC (permalink / raw)


On Tue, 12 Aug 2003 00:49:20 +0100, chris wrote:

> Patrice Freydiere wrote:
> 
>> so it can gives you some ideas for C binding from ADA.
> 
> Thanks.
> 
> 
>> ps: when i started writing the simplejpeglib binding for ADA.
>> i had a lot of interfacing problems du to the portability macros of the
>> jpeglib. (it's surely possible, but when i've started my binding, my C
>> interfacing Skills from ADA was poor).
>> So i decided in my design to build a simple C interface to make Ada
>> binding easier. This permit me to be "C structure independent" and provide a
>> more easy upgrade of the jpeglib.
> 
> This is a problem... and I haven't found a *convienant* way to solve 
> this (other than wrapping it up as you and Warren pointed out - thanks). 
>   Macros change this, that and the other.  My ada code would need to be 
> changed at the spec level on different platforms, compilers, etc... 
> yuck.  A more experienced Ada developer could probably organise it 
> better, but
> 
> All I really want to do now is *decode* and encode (at various 
> qualities) a jpeg (in RBG).  Later things might get more complicated, 
> but for now that's it.  I'm going to look at your lib again now I've got 
> a bit more time.

chris, it's difficult to add a quality parameter to SimpleJpegLib.
The SimpleJpegLib, gives you the RGB values of an encoded JPEG File.

Patrice




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

* Re: Binding to C
  2003-08-12  6:40     ` Patrice Freydiere
@ 2003-08-12 11:58       ` chris
  0 siblings, 0 replies; 17+ messages in thread
From: chris @ 2003-08-12 11:58 UTC (permalink / raw)


Patrice Freydiere wrote:
> 
> chris, it's difficult to add a quality parameter to SimpleJpegLib.
> The SimpleJpegLib, gives you the RGB values of an encoded JPEG File.

So it will decode, but quality varied encoding is out.  That's actually 
ok for this project.  The first iteration deals with getting an image 
into the processing lib (and gui front end).




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

end of thread, other threads:[~2003-08-12 11:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-21 18:59 Binding to C chris
2003-07-21 20:02 ` Martin Krischik
2003-07-22 17:12   ` chris
2003-07-23 13:47     ` Martin Krischik
2003-07-27 13:11     ` Matthew Heaney
2003-07-27 13:07   ` Matthew Heaney
2003-07-21 21:07 ` tmoran
2003-07-21 21:57   ` chris
2003-07-27 13:04 ` Matthew Heaney
2003-07-28 20:52 ` Freejack
2003-07-29 19:21   ` chris
2003-08-09 11:29 ` Patrice Freydiere
2003-08-09 13:09   ` Jeffrey Creem
2003-08-09 13:54     ` Patrice Freydiere
2003-08-11 23:49   ` chris
2003-08-12  6:40     ` Patrice Freydiere
2003-08-12 11:58       ` chris

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