From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:1883:: with SMTP id 125-v6mr19306026ioy.35.1537186293005; Mon, 17 Sep 2018 05:11:33 -0700 (PDT) X-Received: by 2002:aca:5349:: with SMTP id h70-v6mr158974oib.4.1537186292846; Mon, 17 Sep 2018 05:11:32 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.215.MISMATCH!x188-v6no28325ite.0!news-out.google.com!c63-v6ni35ith.0!nntp.google.com!x81-v6no29140ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 17 Sep 2018 05:11:32 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=121.45.194.120; posting-account=3BDb0woAAAAxEpy0UNGOioOboBRjpqqT NNTP-Posting-Host: 121.45.194.120 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Interface To C Struct That Includes An Array From: rogermc@iinet.net.au Injection-Date: Mon, 17 Sep 2018 12:11:33 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:54338 Date: 2018-09-17T05:11:32-07:00 List-Id: On Monday, 17 September 2018 22:01:43 UTC+10, rog...@iinet.net.au wrote: > I'm having problems interfacing the following record to C. > > type API_String is record > Length : Interfaces.C.size_t := 0; > Data : API_String_Data_Array := (others => Interfaces.C.char'Val (0)); > end record; > pragma Convention (C_Pass_By_Copy, API_String); > > In general it seems OK, however, the following function in which Assimp_Path'Access is returned > from a C function produces a strange result > > Result := API_Get_Material_Texture (Material'Access, Tex_Type, unsigned (Tex_Index), Assimp_Path'Access); > > The returned Assimp_Path is Length: 16, Data: B000phoenix.pcx0000 > in which B is a series of four small zeros inside a rectangle. > I haven't been able to find a syntactical explanation for the four small zeros inside a rectangle. > > The expected Assimp_Path is Length: 11, Data: phoenix.pcx > Memory inspection indicates that the Length 16 includes both the expected length and character string. > > (gdb) print Assimp_Path > $8 = (length => 16, data => (0 => 11, 0, 0, 0, 112, 104, 111, 101, 110, 105, 120, 46, 112, 99, 120, 0 ) > CORRECTION: > If I shift the Data characters left by four places and change Length to 12, the resultant Assimp_Path is > Length: 12, Data: Bphoenix.pcx > > The C interface is: > > function API_Get_Material_Texture (aMaterial : access API_Material_Tex; > Tex_Type : AI_Texture_Type; > Index : Interfaces.C.unsigned; > Path : access Assimp_Types.API_String := null; > Mapping : access AI_Texture_Mapping := null; > UV_Index : access Interfaces.C.unsigned := null; > Blend : access Interfaces.C.C_float := null; > Op : access AI_Texture_Op := null; > Map_Mode : access AI_Texture_Map_Mode := null) > return Assimp_Types.API_Return; > pragma Import (C, API_Get_Material_Texture, "aiGetMaterialTexture"); > > Any positive advice or explanation will be appreciated. > Roger