comp.lang.ada
 help / color / mirror / Atom feed
* C lib returns char** - How in ADA?
@ 2002-05-30  6:34 Jeremy Cowgar
  2002-05-30  7:42 ` sk
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jeremy Cowgar @ 2002-05-30  6:34 UTC (permalink / raw)


Greetings,

I am trying to interface to a C library. Some functions are working
already, but I am at a stand still because I cann figure out how to
interface this one function:

char **ldap_get_values(...)

The return is what I am having problems with, it is an array of strings.

Can anyone help me out with this and let me know what it should look like
in the .ads and on the implementing .adb side?

Thanks!

Jeremy



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

* Re: C lib returns char** - How in ADA?
  2002-05-30  6:34 C lib returns char** - How in ADA? Jeremy Cowgar
@ 2002-05-30  7:42 ` sk
  2002-05-30  7:56 ` sk
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-05-30  7:42 UTC (permalink / raw)


Hi,

Have a look at package Interfaces.C.Strings in the
references manual. The package which provides :

type char_array_access is access all char_array;
type chars_ptr is private;
type chars_ptr_array is array (size_t range <>) of chars_ptr;

which appears to be what you are looking for.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: C lib returns char** - How in ADA?
  2002-05-30  6:34 C lib returns char** - How in ADA? Jeremy Cowgar
  2002-05-30  7:42 ` sk
@ 2002-05-30  7:56 ` sk
  2002-05-30  7:57 ` tmoran
  2002-05-30 16:32 ` Pascal Obry
  3 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-05-30  7:56 UTC (permalink / raw)



Hi, 

I mistakenly hit the send before finishing ...

Have a look at package Interfaces.C.Strings in the
references manual. The package provides :

type char_array_access is access all char_array;
type chars_ptr is private;
type chars_ptr_array is array (size_t range <>) of chars_ptr;

which appears to be what you are looking for.

+++

Then look at Interfaces.C.Pointers.

It gets tricky since you are importing a non-Ada object, but

    package IC  renames Interfaces.C;
    package ICS renames Interfaces.C.Strings;
    package ICP is new Interfaces.C.Pointers (
        Index => IC.Size_t,
        Element => ICS.Chars_Ptr,
        Element_Array => ICS.Chars_Ptr_Array,
        Default_Terminator => ???????
    );

Cannot remember what <???????> should be,

   ICP.Copy_Terminated_Array (...)

should get the foreign data structure into your
application.

Its been a while since I played with this, so details
are fuzzy .. except that I quickly found a hack to
replace the way you are supposed to do it described 
above :-)

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: C lib returns char** - How in ADA?
  2002-05-30  6:34 C lib returns char** - How in ADA? Jeremy Cowgar
  2002-05-30  7:42 ` sk
  2002-05-30  7:56 ` sk
@ 2002-05-30  7:57 ` tmoran
  2002-05-30 16:32 ` Pascal Obry
  3 siblings, 0 replies; 7+ messages in thread
From: tmoran @ 2002-05-30  7:57 UTC (permalink / raw)


> char **ldap_get_values(...)
> Can anyone help me out with this and let me know what it should look like
> in the .ads and on the implementing .adb side?
  Your mention of "the implementing .adb side" suggests you are trying
to make an Ada function callable from C.  OTOH, asking about a C lib
suggests the C function exists already and you are trying to call it
from Ada.  Assuming the latter is the case, using Interfaces.C.Strings
you could do something like:

with Interfaces.C.Strings,
     Ada.Text_Io;
procedure ppc is
  use type Interfaces.C.Strings.Chars_Ptr;

  subtype Indefinite_List_Of_Chars_Ptr
    is Interfaces.C.Strings.Chars_Ptr_Array(Interfaces.C.Size_T);
  type Ptr_To_Indefinite_List is access all Indefinite_List_Of_Chars_Ptr;

  function Ldap_Get_Values(Dummy : Integer) return Ptr_To_Indefinite_List;
  pragma Import(Stdcall, Ldap_Get_Values, "ldap_get_values");

  P : Ptr_To_Indefinite_List;
begin
  P := Ldap_Get_Values(Dummy => 0);
  for I in Interfaces.C.Size_T loop
    exit when P(I) = Interfaces.C.Strings.Null_Ptr;
    Ada.Text_Io.Put_Line(Interfaces.C.Strings.Value(P(I)));
  end loop;
end ppc;



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

* Re: C lib returns char** - How in ADA?
  2002-05-30  6:34 C lib returns char** - How in ADA? Jeremy Cowgar
                   ` (2 preceding siblings ...)
  2002-05-30  7:57 ` tmoran
@ 2002-05-30 16:32 ` Pascal Obry
  2002-05-31  0:28   ` Jeremy Cowgar
  3 siblings, 1 reply; 7+ messages in thread
From: Pascal Obry @ 2002-05-30 16:32 UTC (permalink / raw)



Jeremy Cowgar <develop@cowgar.com> writes:

> Greetings,
> 
> I am trying to interface to a C library. Some functions are working
> already, but I am at a stand still because I cann figure out how to
> interface this one function:
> 
> char **ldap_get_values(...)

Hum, are you working on a binding to OpenLDAP ? If so I'm sure some of us will
like to have something like that :) Will this work be Open Source ?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: C lib returns char** - How in ADA?
  2002-05-30 16:32 ` Pascal Obry
@ 2002-05-31  0:28   ` Jeremy Cowgar
  2002-05-31 18:46     ` Pascal Obry
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremy Cowgar @ 2002-05-31  0:28 UTC (permalink / raw)


On Thu, 30 May 2002 12:32:54 -0400, Pascal Obry wrote:

> Jeremy Cowgar <develop@cowgar.com> writes:
> 
> Hum, are you working on a binding to OpenLDAP ? If so I'm sure some of
> us will like to have something like that :) Will this work be Open
> Source ?
> 
> Pascal.
> 

Pascal,

Yes, it is a binding to LDAP. I need it for one of the projects I am
working on currently. I am pretty new to ADA, in fact just learning it. A
person in irc (irc.openprojects.net #ada) wrote the base ldap interface
to get me started. It is working great.

Because I am new to Ada, I hope you will not be hard on the coding, but
yes, I will release it into open source, and maybe some who use it can
correct the many errors and non-ada'ish things about it.

I will post a message here when it is ready for some type of public
consumtion as to where to download it.

Thanks for the intrest.

Jeremy



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

* Re: C lib returns char** - How in ADA?
  2002-05-31  0:28   ` Jeremy Cowgar
@ 2002-05-31 18:46     ` Pascal Obry
  0 siblings, 0 replies; 7+ messages in thread
From: Pascal Obry @ 2002-05-31 18:46 UTC (permalink / raw)



Jeremy Cowgar <develop@cowgar.com> writes:

> Pascal,
> 
> Yes, it is a binding to LDAP. I need it for one of the projects I am
> working on currently. I am pretty new to ADA, in fact just learning it. A
> person in irc (irc.openprojects.net #ada) wrote the base ldap interface
> to get me started. It is working great.

Is that OpenLDAP ?

> Because I am new to Ada, I hope you will not be hard on the coding, but
> yes, I will release it into open source, and maybe some who use it can
> correct the many errors and non-ada'ish things about it.

I certainly will. An idea would be to integrate this into AWS if you don't
mind. AWS (Ada Web Server) is missing an API to use LDAP services and this
is a quite common need for Web development.

> I will post a message here when it is ready for some type of public
> consumtion as to where to download it.

Thanks. Please consider putting that into AdaPower.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

end of thread, other threads:[~2002-05-31 18:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-30  6:34 C lib returns char** - How in ADA? Jeremy Cowgar
2002-05-30  7:42 ` sk
2002-05-30  7:56 ` sk
2002-05-30  7:57 ` tmoran
2002-05-30 16:32 ` Pascal Obry
2002-05-31  0:28   ` Jeremy Cowgar
2002-05-31 18:46     ` Pascal Obry

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