Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Pray to God, but keep rowing to shore. -- Russian Proverb


devel / comp.lang.ada / Upcasting interfaces with CPP convention in GNAT

SubjectAuthor
* Upcasting interfaces with CPP convention in GNATKura
`* Re: Upcasting interfaces with CPP convention in GNATJ-P. Rosen
 `* Re: Upcasting interfaces with CPP convention in GNATKura
  `- Re: Upcasting interfaces with CPP convention in GNATKura

1
Upcasting interfaces with CPP convention in GNAT

<c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10237&group=comp.lang.ada#10237

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:460a:b0:778:959e:877b with SMTP id br10-20020a05620a460a00b00778959e877bmr392589qkb.13.1698927609496;
Thu, 02 Nov 2023 05:20:09 -0700 (PDT)
X-Received: by 2002:a05:6870:6193:b0:1e9:8db0:383 with SMTP id
a19-20020a056870619300b001e98db00383mr8912117oah.1.1698927609235; Thu, 02 Nov
2023 05:20:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 2 Nov 2023 05:20:08 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=67.77.21.19; posting-account=ahMziQoAAAAL0iwU2Gxnh6xZxKmkLfTD
NNTP-Posting-Host: 67.77.21.19
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com>
Subject: Upcasting interfaces with CPP convention in GNAT
From: kuraitou@gmail.com (Kura)
Injection-Date: Thu, 02 Nov 2023 12:20:09 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3985
 by: Kura - Thu, 2 Nov 2023 12:20 UTC

Hi all,

I'm trying to figure out how to correctly perform an upcast in GNAT using
interface types that have the CPP convention. I have two types corresponding to
C++ classes: IBase and IDerived each with corresponding access types suffixed
with _Ptr. The library that I'm wrapping returns a pointer to some concrete
implementation of IDerived, but the moment I convert it to an IBase_Ptr to pass
it to functions within the library, the program segfaults while performing some
kind of tag check. I've found information on this topic to be very sparse, and
the GNAT manual has no discussion about allowed conversions or examples showing
how to do this. This seems like it should be an allowed conversion and the
program works as expected if I either replace the usage of Base_Ptr with
Derived_Ptr within the function wrapper specification (not feasible because
there are many types deriving from Base_Ptr and adding overloads would affect
its vtable) or use Unchecked_Conversion between the two pointer types (unsure
if this is safe). I'm also aware I could lay out the vtables manually and do
away with tagged types, but I would like to avoid that if possible.

Here is a minimal example that segfaults, all compiled with the same toolchain
on windows/mingw64:

--==== repro.adb ==============================================================
with Wrap; use Wrap;
procedure Repro is
P : IDerived_Ptr := GetDerivedInstance;
Q : IBase_Ptr := IBase_Ptr (P);
begin
null;
end Repro;

--==== wrap.ads ===============================================================
package Wrap is
type IBase is interface;
pragma Convention (C_Plus_Plus, IBase);
type IBase_Ptr is access all IBase'Class;

type IDerived is interface and IBase;
pragma Convention (C_Plus_Plus, IDerived);
type IDerived_Ptr is access all IDerived'Class;

function GetDerivedInstance return IDerived_Ptr
with Import => True, Convention => C_Plus_Plus,
External_Name => "GetDerivedInstance";
end Wrap;

--==== lib.cpp ================================================================
class IBase {};
class IDerived : public IBase {};
class Impl : public IDerived {
public:
Impl() = default;
};

extern "C"
IDerived* GetDerivedInstance() {
return new Impl();
} --==== end example ============================================================

Error and stack trace:

Thread 1 received signal SIGSEGV, Segmentation fault.
ada.tags.offset_to_top (this=(system.address) 0x6591710) at a-tags.adb:806
806 a-tags.adb: No such file or directory.
(gdb) bt
#0 ada.tags.offset_to_top (this=(system.address) 0x6591710) at a-tags.adb:806
#1 ada.tags.base_address (this=(system.address) 0x6591710) at a-tags.adb:286
#2 ada.tags.displace (this=(system.address) 0x6591710, t=0x7ff7fe8301c8
<wrap__ibaseT+8> (wrap.ibase)) at a-tags.adb:354
#3 0x00007ff7fe82649c in repro () at C:\repro\src\repro.adb:5

Any ideas?

Re: Upcasting interfaces with CPP convention in GNAT

<ui0an7$27m9p$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10238&group=comp.lang.ada#10238

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rosen@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: Upcasting interfaces with CPP convention in GNAT
Date: Thu, 2 Nov 2023 15:11:54 +0100
Organization: Adalog
Lines: 18
Message-ID: <ui0an7$27m9p$1@dont-email.me>
References: <c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 2 Nov 2023 14:11:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b2e86e5f858097cd9582e1b007117101";
logging-data="2349369"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HBGZxKV+p1ELSakFdOYkP"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aWDIlSVLs361Imyk2Ulr4yo04NE=
In-Reply-To: <c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com>
Content-Language: en-US, fr
 by: J-P. Rosen - Thu, 2 Nov 2023 14:11 UTC

Le 02/11/2023 à 13:20, Kura a écrit :
> type IBase is interface;
> pragma Convention (C_Plus_Plus, IBase);
> type IBase_Ptr is access all IBase'Class;
>
> type IDerived is interface and IBase;
> pragma Convention (C_Plus_Plus, IDerived);
> type IDerived_Ptr is access all IDerived'Class;
I don't know if this is the cause of your problem, but you should give
convention C_Plus_Plus to the pointer types too (IBase_Ptr and
IDerived_Ptr).

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr

Re: Upcasting interfaces with CPP convention in GNAT

<1709521b-d44d-4a2e-8833-cb642e706954n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10239&group=comp.lang.ada#10239

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a0c:f84b:0:b0:671:4350:edfa with SMTP id g11-20020a0cf84b000000b006714350edfamr230330qvo.0.1698937705786;
Thu, 02 Nov 2023 08:08:25 -0700 (PDT)
X-Received: by 2002:a9d:6b1a:0:b0:6bc:fb26:499e with SMTP id
g26-20020a9d6b1a000000b006bcfb26499emr5444727otp.2.1698937705576; Thu, 02 Nov
2023 08:08:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 2 Nov 2023 08:08:24 -0700 (PDT)
In-Reply-To: <ui0an7$27m9p$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=67.77.21.19; posting-account=ahMziQoAAAAL0iwU2Gxnh6xZxKmkLfTD
NNTP-Posting-Host: 67.77.21.19
References: <c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com> <ui0an7$27m9p$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1709521b-d44d-4a2e-8833-cb642e706954n@googlegroups.com>
Subject: Re: Upcasting interfaces with CPP convention in GNAT
From: kuraitou@gmail.com (Kura)
Injection-Date: Thu, 02 Nov 2023 15:08:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 14
 by: Kura - Thu, 2 Nov 2023 15:08 UTC

On Thursday, November 2, 2023 at 10:11:55 AM UTC-4, J-P. Rosen wrote:
> Le 02/11/2023 à 13:20, Kura a écrit :
> > type IBase is interface;
> > pragma Convention (C_Plus_Plus, IBase);
> > type IBase_Ptr is access all IBase'Class;
> >
> > type IDerived is interface and IBase;
> > pragma Convention (C_Plus_Plus, IDerived);
> > type IDerived_Ptr is access all IDerived'Class;
> I don't know if this is the cause of your problem, but you should give
> convention C_Plus_Plus to the pointer types too (IBase_Ptr and
> IDerived_Ptr).

That did not solve my problem, but thank you for the tip.

Re: Upcasting interfaces with CPP convention in GNAT

<7b6646b4-0bed-49b1-98ee-7f08670593efn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10243&group=comp.lang.ada#10243

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:5541:0:b0:417:9e0f:fb30 with SMTP id o1-20020ac85541000000b004179e0ffb30mr406403qtr.12.1699045986226;
Fri, 03 Nov 2023 14:13:06 -0700 (PDT)
X-Received: by 2002:a05:6808:209d:b0:3a1:f2a4:3d7 with SMTP id
s29-20020a056808209d00b003a1f2a403d7mr9148596oiw.1.1699045986027; Fri, 03 Nov
2023 14:13:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 3 Nov 2023 14:13:05 -0700 (PDT)
In-Reply-To: <1709521b-d44d-4a2e-8833-cb642e706954n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=67.77.21.19; posting-account=ahMziQoAAAAL0iwU2Gxnh6xZxKmkLfTD
NNTP-Posting-Host: 67.77.21.19
References: <c00659fa-312b-4dcc-872f-0fabfde55c0dn@googlegroups.com>
<ui0an7$27m9p$1@dont-email.me> <1709521b-d44d-4a2e-8833-cb642e706954n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7b6646b4-0bed-49b1-98ee-7f08670593efn@googlegroups.com>
Subject: Re: Upcasting interfaces with CPP convention in GNAT
From: kuraitou@gmail.com (Kura)
Injection-Date: Fri, 03 Nov 2023 21:13:06 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Kura - Fri, 3 Nov 2023 21:13 UTC

I was able to work around the issue by using abstract tagged null records
instead of interfaces - no other changes necessary. It seems that interfaces
can only be at the very top of a hierarchy even if you're only extending
another interface.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor