From: Simon Wright <simon@pushface.org>
Subject: Re: Convert between C "void*" pointer and an access
Date: Thu, 12 Oct 2017 09:05:00 +0100
Date: 2017-10-12T09:05:00+01:00 [thread overview]
Message-ID: <lywp403i6r.fsf@pushface.org> (raw)
In-Reply-To: orm7v8$1gr$1@gioia.aioe.org
Victor Porton <porton@narod.ru> writes:
> I NEED to convert between access to tagged records (and access to
> class-wide types) and C void* pointers.
>
> I need this because it is C's way to pass objects by using void* and I
> need to pass Ada objects to C functions (not just C objects).
What we think you need to do is to pass a class-wide pointer to a C
function so that it can do something with it.
One would hope that you could say e.g.
type T is tagged null record;
type T_P is access all T'Class with Convention => C;
procedure Put (Obj : T_P) -- <<< warning here
with
Import,
Convention => C,
External_Name => "demo_put";
function Get return T_P -- <<< warning here
with
Import,
Convention => C,
External_Name => "demo_get";
type U is new T with null record;
O : aliased U;
begin
Put (O'Access);
declare
Ret : constant T_P := Get;
begin
Put_Line ("ret's class is " & Ada.Tags.Expanded_Name (Ret'Tag));
end;
and that the compiler would refuse to compile the code if it couldn't
map the type's conventions as specified.
Trying this on macOS results in warnings
class_pointers.adb:6:19: warning: "Put.Obj" involves a tagged type which
does not correspond to any C type
class_pointers.adb:11:13: warning: return type of "Get" does not
correspond to C type
but the resulting executable works as expected. (You would have expected
a similar warning on the type definition; perhaps this is a bug?)
In the past I've had success by specifying the size of the classwide
type (this doesn't suppress the warnings).
next prev parent reply other threads:[~2017-10-12 8:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-11 21:52 Convert between C "void*" pointer and an access Victor Porton
2017-10-11 22:32 ` Randy Brukardt
2017-10-11 23:03 ` Victor Porton
2017-10-12 7:57 ` Dmitry A. Kazakov
2017-10-12 8:05 ` Simon Wright [this message]
2017-10-29 14:50 ` David Thompson
2017-10-11 22:58 ` Victor Porton
2017-10-11 23:12 ` Victor Porton
2017-10-12 1:01 ` Victor Porton
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox