comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Messing with access types...
Date: Mon, 28 Dec 2020 20:53:54 +0100	[thread overview]
Message-ID: <rsdd4f$s52$1@gioia.aioe.org> (raw)
In-Reply-To: rsd9oh$pc3$1@dont-email.me

On 2020-12-28 19:56, Marek wrote:

> I think I'll try another approach: just write extra layer in C, which
> will direct communicate with host and will provide prepared data for Ada
> part.

The standard approach is somewhat different:

1. Thin Ada bindings mapping to C, mostly 1-to-1 with minor adjustments, 
e.g.

- replacing BOOL with Ada Boolean
- translating C strings into Ada Strings
- replacing C pointer parameters with Ada out or in out, as appropriate
- making proper functions where C cannot, e.g. returning string results 
where C API uses a buffer to store string copy. The buffer is made 
local, C function is called to fill it. Then the contents is converted 
to Ada string and returned out.

2. On top of that you do thick Ada bindings:

- reasonable interfaces
- all implementation types made private
- return codes replaced with exceptions
- C's malloc/free pairs wrapped by Ada controlled types
- similarly resources seizing/releasing pairs go into controlled types
- messages/events loops encapsulated into Ada tasks
- these tasks are wrapped by a controlled type (AKA active object)

You do not need to change anything on the C side. You can incrementally 
advance #2 as far as you feel necessary since you can always fall back 
to #1.

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

      reply	other threads:[~2020-12-28 19:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28  9:44 Messing with access types Marek
2020-12-28 10:14 ` Dmitry A. Kazakov
2020-12-28 11:43   ` Marek
2020-12-28 13:56     ` Dmitry A. Kazakov
2020-12-28 18:56       ` Marek
2020-12-28 19:53         ` Dmitry A. Kazakov [this message]
replies disabled

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