mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
add a simple sizeof checker to compare nim & c types
This commit is contained in:
@@ -701,7 +701,10 @@ proc getTypeDescAux(m: BModule, typ: PType, check: var IntSet): Rope =
|
||||
idTablePut(m.typeCache, t, result) # always call for sideeffects:
|
||||
let recdesc = if t.kind != tyTuple: getRecordDesc(m, t, result, check)
|
||||
else: getTupleDesc(m, t, result, check)
|
||||
if not isImportedType(t): add(m.s[cfsTypes], recdesc)
|
||||
if not isImportedType(t):
|
||||
add(m.s[cfsTypes], recdesc)
|
||||
elif tfIncompleteStruct notin t.flags:
|
||||
addf(m.s[cfsTypeInfo], "NIM_CHECK_SIZE($1, $2);$n", [result, rope(getSize(t))])
|
||||
of tySet:
|
||||
result = getTypeName(t.lastSon) & "Set"
|
||||
idTablePut(m.typeCache, t, result)
|
||||
|
||||
@@ -459,3 +459,11 @@ typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == siz
|
||||
#elif defined(__FreeBSD__)
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Compile with -t:-DNIM_CHECK_ABI to enable */
|
||||
#ifdef NIM_CHECK_ABI
|
||||
# define NIM_CHECK_SIZE(typ, sz) \
|
||||
_Static_assert(sizeof(typ) == sz, "Nim & C disagree on type size")
|
||||
#else
|
||||
# define NIM_CHECK_SIZE(typ, sz)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user