From: rogermc@iinet.net.au
Subject: Interface To C Struct That Includes An Array
Date: Mon, 17 Sep 2018 05:01:41 -0700 (PDT)
Date: 2018-09-17T05:01:41-07:00 [thread overview]
Message-ID: <b3f11b70-002a-490b-8a67-9df4b2aeecb8@googlegroups.com> (raw)
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: \vB000phoenix.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>)
If I shift the Data characters left by four places and change Length to 12, the resultant Assimp_Path is
Length: 16, Data: \vBphoenix.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 reply other threads:[~2018-09-17 12:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-17 12:01 rogermc [this message]
2018-09-17 12:11 ` Interface To C Struct That Includes An Array rogermc
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