From: rogermc@iinet.net.au
Subject: Re: Interface To C Struct That Includes An Array
Date: Mon, 17 Sep 2018 05:11:32 -0700 (PDT)
Date: 2018-09-17T05:11:32-07:00 [thread overview]
Message-ID: <db833530-94f5-43a7-8ebe-4f45cf55c30d@googlegroups.com> (raw)
In-Reply-To: <b3f11b70-002a-490b-8a67-9df4b2aeecb8@googlegroups.com>
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 <repeats 1009 times>)
>
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
next prev parent reply other threads:[~2018-09-17 12:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-17 12:01 Interface To C Struct That Includes An Array rogermc
2018-09-17 12:11 ` rogermc [this message]
2018-09-17 15:25 ` Lucretia
2018-09-17 22:35 ` Roger
2018-09-18 0:45 ` Roger
2018-09-18 1:19 ` rogermc
2018-09-17 12:26 ` gautier_niouzes
2018-09-17 13:28 ` Roger
2018-09-17 13:55 ` gautier_niouzes
2018-09-17 14:03 ` Roger
2018-09-17 15:24 ` Lucretia
2018-09-17 23:06 ` Roger
2018-09-17 16:29 ` Jeffrey R. Carter
2018-09-17 22:57 ` Roger
2018-09-18 0:53 ` Roger
2018-09-18 4:18 ` Roger
2018-09-18 8:19 ` rakusu_klein
2018-09-18 11:54 ` rogermc
2018-09-18 12:21 ` Egil H H
2018-09-18 12:24 ` rogermc
2018-09-18 18:55 ` rakusu_klein
2018-09-18 21:28 ` rogermc
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox