work around broken gc during global init

This commit is contained in:
Jacek Sieka 2021-02-18 14:52:06 +01:00 committed by zah
parent 4e2ffe3f6d
commit 293a987c51
1 changed files with 9 additions and 3 deletions

View File

@ -227,9 +227,15 @@ proc makeFieldReadersTable(RecordType, Reader: distinct type):
proc fieldReadersTable*(RecordType, Reader: distinct type): proc fieldReadersTable*(RecordType, Reader: distinct type):
ptr seq[FieldReader[RecordType, Reader]] = ptr seq[FieldReader[RecordType, Reader]] =
mixin readValue mixin readValue
var tbl {.global.} = makeFieldReadersTable(RecordType, Reader)
{.gcsafe.}: # careful: https://github.com/nim-lang/Nim/issues/17085
return addr(tbl) # TODO why is this even here? one could just return the function pointer
# to the field reader directly instead of going through this seq etc
var tbl {.threadvar.}: ref seq[FieldReader[RecordType, Reader]]
if tbl == nil:
tbl = new typeof(tbl)
tbl[] = makeFieldReadersTable(RecordType, Reader)
return addr(tbl[])
proc findFieldReader*(fieldsTable: FieldReadersTable, proc findFieldReader*(fieldsTable: FieldReadersTable,
fieldName: string, fieldName: string,