Skip to content

Commit

Permalink
Fix handling of extern static arrays
Browse files Browse the repository at this point in the history
Related to #26
  • Loading branch information
Dicebot committed Jan 25, 2016
1 parent 9380ef7 commit a35b6ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
21 changes: 17 additions & 4 deletions dstep/translator/Type.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import dstep.translator.IncludeHandler;
import dstep.translator.Translator;
import dstep.translator.Output;

import std.conv;

string translateType (Type type, bool rewriteIdToObjcObject = true, bool applyConst = true)
in
{
Expand Down Expand Up @@ -56,7 +58,9 @@ body
handleInclude(type);
break;

case CXType_ConstantArray: result = translateConstantArray(type, rewriteIdToObjcObject); break;
case CXType_ConstantArray:
case CXType_IncompleteArray:
result = translateArray(type, rewriteIdToObjcObject); break;
case CXType_Unexposed: result = translateUnexposed(type, rewriteIdToObjcObject); break;

default: result = translateType(type.kind, rewriteIdToObjcObject);
Expand Down Expand Up @@ -156,17 +160,26 @@ body
return translateType(type.kind, rewriteIdToObjcObject);
}

string translateConstantArray (Type type, bool rewriteIdToObjcObject)
string translateArray (Type type, bool rewriteIdToObjcObject)
in
{
assert(type.kind == CXTypeKind.CXType_ConstantArray);
assert(type.kind == CXTypeKind.CXType_ConstantArray
|| type.kind == CXTypeKind.CXType_IncompleteArray);
}
body
{
auto array = type.array;
auto elementType = translateType(array.elementType, rewriteIdToObjcObject);

return elementType ~ '[' ~ array.size.toString ~ ']';
if (array.size >= 0)
return elementType ~ '[' ~ array.size.toString ~ ']';
else
// extern static arrays (which are normally present in bindings)
// have same ABI as extern dynamic arrays, size is only checked
// against declaration in header. As it is not possible in D
// to define static array with ABI of dynamic one, only way is to
// abandon the size information
return elementType ~ "[]";
}

string translatePointer (Type type, bool rewriteIdToObjcObject, bool applyConst)
Expand Down
2 changes: 1 addition & 1 deletion test_files/arrays.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ extern (C):
extern __gshared int[4] a;
extern __gshared int[3][2] b;
extern __gshared int[4][3][2] c;
extern __gshared <unimplemented> sys_errlist;
extern __gshared const char*[] sys_errlist;
1 change: 0 additions & 1 deletion test_files/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ int a[4];
int b[2][3];
int c[2][3][4];

// issue 26
extern const char *const sys_errlist[];

0 comments on commit a35b6ea

Please sign in to comment.