comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Coding access to a C's pointer - pointer
Date: Sat, 6 Jun 2020 19:01:40 +0200
Date: 2020-06-06T19:01:40+02:00	[thread overview]
Message-ID: <rbgi5h$1gub$1@gioia.aioe.org> (raw)
In-Reply-To: dc1dd87e-c7dd-4ed8-a3eb-918362a8f9feo@googlegroups.com

On 06/06/2020 18:23, Bob Goddard wrote:
> I'm trying to shoehorn net-snmp into an Ada conversion and I've hit a roadblock.
> 
> snmp_synch_response requires a pointer to a pointer:
> snmp_synch_response(netsnmp_session *, netsnmp_pdu *, netsnmp_pdu **)

> Just how the heck do you code that? You can't just declare a System.Address.

That depends on the semantics because in C you cannot tell in from out.

Assuming that snmp_synch_response returns a pointer to PDU and that 
netsnmp_session and netsnmp_pdu are record types:

type netsnmp_pdu_Ptr is access all netsnmp_pdu;
paragma Convention (C, netsnmp_pdu_Ptr);

procedure snmp_synch_response
           (  Session  : netsnmp_session;
              Request  : netsnmp_pdu;
              Response : out netsnmp_pdu_Ptr -- Who manages the target?
           );

You must carefully read the documentation and probably the sources to 
determine who manages the returned object.

Some libraries return pointers to internally allocated and freed memory 
others require the caller to deallocate the object at the returned 
point. C is a mess.

> Would I need to drop into C and handle it there?

P.S. Why do not you implement SNMP instead of using alien library? SNMP 
is not rocket science.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2020-06-06 17:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-06 16:23 Coding access to a C's pointer - pointer Bob Goddard
2020-06-06 16:50 ` Luke A. Guest
2020-06-06 16:59 ` Niklas Holsti
2020-06-06 17:01 ` Dmitry A. Kazakov [this message]
2020-06-06 17:34   ` Bob Goddard
2020-06-06 18:48     ` Dmitry A. Kazakov
2020-06-06 20:20 ` Jeffrey R. Carter
2020-06-06 20:51   ` Björn Lundin
2020-06-06 20:55   ` Jeffrey R. Carter
2020-06-07  7:29     ` Dmitry A. Kazakov
replies disabled

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