Linux abi take 3 (#5692)
* avoid generating object fields for imported types * fix some abi/type issues for linux_amd64
This commit is contained in:
parent
926563f0e6
commit
e512358bc9
7 changed files with 86 additions and 35 deletions
|
|
@ -988,7 +988,7 @@ proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope) =
|
||||||
if typ.kind == tyObject: genTypeInfoAux(m, typ, origType, name)
|
if typ.kind == tyObject: genTypeInfoAux(m, typ, origType, name)
|
||||||
else: genTypeInfoAuxBase(m, typ, origType, name, rope("0"))
|
else: genTypeInfoAuxBase(m, typ, origType, name, rope("0"))
|
||||||
var tmp = getNimNode(m)
|
var tmp = getNimNode(m)
|
||||||
if not isImportedCppType(typ):
|
if not isImportedType(typ):
|
||||||
genObjectFields(m, typ, origType, typ.n, tmp)
|
genObjectFields(m, typ, origType, typ.n, tmp)
|
||||||
addf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, tmp])
|
addf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, tmp])
|
||||||
var t = typ.sons[0]
|
var t = typ.sons[0]
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,10 @@ type
|
||||||
epoll_data* {.importc: "union epoll_data",
|
epoll_data* {.importc: "union epoll_data",
|
||||||
header: "<sys/epoll.h>", pure, final.} = object # TODO: This is actually a union.
|
header: "<sys/epoll.h>", pure, final.} = object # TODO: This is actually a union.
|
||||||
#thePtr* {.importc: "ptr".}: pointer
|
#thePtr* {.importc: "ptr".}: pointer
|
||||||
fd* {.importc: "fd".}: cint # \
|
fd* {.importc: "fd".}: cint
|
||||||
#u32*: uint32
|
when defined(linux) and defined(amd64):
|
||||||
|
u32: uint32 # this field ensures that binary size is right - it cannot be
|
||||||
|
# used because its offset is wrong
|
||||||
#u64*: uint64
|
#u64*: uint64
|
||||||
|
|
||||||
epoll_event* {.importc: "struct epoll_event", header: "<sys/epoll.h>", pure, final.} = object
|
epoll_event* {.importc: "struct epoll_event", header: "<sys/epoll.h>", pure, final.} = object
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,19 @@ type
|
||||||
const
|
const
|
||||||
NCCS* = when defined(macosx): 20 else: 32
|
NCCS* = when defined(macosx): 20 else: 32
|
||||||
|
|
||||||
type
|
when defined(linux) and defined(amd64):
|
||||||
|
type
|
||||||
|
Termios* {.importc: "struct termios", header: "<termios.h>".} = object
|
||||||
|
c_iflag*: Cflag # input mode flags
|
||||||
|
c_oflag*: Cflag # output mode flags
|
||||||
|
c_cflag*: Cflag # control mode flags
|
||||||
|
c_lflag*: Cflag # local mode flags
|
||||||
|
c_line*: cuchar
|
||||||
|
c_cc*: array[NCCS, cuchar] # control characters
|
||||||
|
c_ispeed*: Speed
|
||||||
|
c_ospeed*: Speed
|
||||||
|
else:
|
||||||
|
type
|
||||||
Termios* {.importc: "struct termios", header: "<termios.h>".} = object
|
Termios* {.importc: "struct termios", header: "<termios.h>".} = object
|
||||||
c_iflag*: Cflag # input mode flags
|
c_iflag*: Cflag # input mode flags
|
||||||
c_oflag*: Cflag # output mode flags
|
c_oflag*: Cflag # output mode flags
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,17 @@ type
|
||||||
dMon, dTue, dWed, dThu, dFri, dSat, dSun
|
dMon, dTue, dWed, dThu, dFri, dSat, dSun
|
||||||
|
|
||||||
when defined(posix) and not defined(JS):
|
when defined(posix) and not defined(JS):
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
type
|
||||||
|
TimeImpl {.importc: "time_t", header: "<time.h>".} = clong
|
||||||
|
Time* = distinct TimeImpl ## distinct type that represents a time
|
||||||
|
## measured as number of seconds since the epoch
|
||||||
|
|
||||||
|
Timeval {.importc: "struct timeval",
|
||||||
|
header: "<sys/select.h>".} = object ## struct timeval
|
||||||
|
tv_sec: clong ## Seconds.
|
||||||
|
tv_usec: clong ## Microseconds.
|
||||||
|
else:
|
||||||
type
|
type
|
||||||
TimeImpl {.importc: "time_t", header: "<time.h>".} = int
|
TimeImpl {.importc: "time_t", header: "<time.h>".} = int
|
||||||
Time* = distinct TimeImpl ## distinct type that represents a time
|
Time* = distinct TimeImpl ## distinct type that represents a time
|
||||||
|
|
@ -1103,7 +1114,7 @@ when not defined(JS):
|
||||||
when defined(freebsd) or defined(netbsd) or defined(openbsd) or
|
when defined(freebsd) or defined(netbsd) or defined(openbsd) or
|
||||||
defined(macosx):
|
defined(macosx):
|
||||||
type
|
type
|
||||||
StructTM {.importc: "struct tm", final.} = object
|
StructTM {.importc: "struct tm".} = object
|
||||||
second {.importc: "tm_sec".},
|
second {.importc: "tm_sec".},
|
||||||
minute {.importc: "tm_min".},
|
minute {.importc: "tm_min".},
|
||||||
hour {.importc: "tm_hour".},
|
hour {.importc: "tm_hour".},
|
||||||
|
|
@ -1116,7 +1127,7 @@ when not defined(JS):
|
||||||
gmtoff {.importc: "tm_gmtoff".}: clong
|
gmtoff {.importc: "tm_gmtoff".}: clong
|
||||||
else:
|
else:
|
||||||
type
|
type
|
||||||
StructTM {.importc: "struct tm", final.} = object
|
StructTM {.importc: "struct tm".} = object
|
||||||
second {.importc: "tm_sec".},
|
second {.importc: "tm_sec".},
|
||||||
minute {.importc: "tm_min".},
|
minute {.importc: "tm_min".},
|
||||||
hour {.importc: "tm_hour".},
|
hour {.importc: "tm_hour".},
|
||||||
|
|
@ -1126,6 +1137,9 @@ when not defined(JS):
|
||||||
weekday {.importc: "tm_wday".},
|
weekday {.importc: "tm_wday".},
|
||||||
yearday {.importc: "tm_yday".},
|
yearday {.importc: "tm_yday".},
|
||||||
isdst {.importc: "tm_isdst".}: cint
|
isdst {.importc: "tm_isdst".}: cint
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
gmtoff {.importc: "tm_gmtoff".}: clong
|
||||||
|
zone {.importc: "tm_zone".}: cstring
|
||||||
type
|
type
|
||||||
TimeInfoPtr = ptr StructTM
|
TimeInfoPtr = ptr StructTM
|
||||||
Clock {.importc: "clock_t".} = distinct int
|
Clock {.importc: "clock_t".} = distinct int
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,15 @@ proc c_memset(p: pointer, value: cint, size: csize): pointer {.
|
||||||
proc c_strcmp(a, b: cstring): cint {.
|
proc c_strcmp(a, b: cstring): cint {.
|
||||||
importc: "strcmp", header: "<string.h>", noSideEffect.}
|
importc: "strcmp", header: "<string.h>", noSideEffect.}
|
||||||
|
|
||||||
type
|
when defined(linux) and defined(amd64):
|
||||||
|
type
|
||||||
|
C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>", bycopy.} = object
|
||||||
|
abi: array[200 div sizeof(clong), clong]
|
||||||
|
else:
|
||||||
|
type
|
||||||
C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object
|
C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object
|
||||||
|
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
const
|
const
|
||||||
SIGABRT = cint(22)
|
SIGABRT = cint(22)
|
||||||
|
|
|
||||||
|
|
@ -102,12 +102,21 @@ else:
|
||||||
SysLock {.importc: "pthread_mutex_t", pure, final,
|
SysLock {.importc: "pthread_mutex_t", pure, final,
|
||||||
header: """#include <sys/types.h>
|
header: """#include <sys/types.h>
|
||||||
#include <pthread.h>""".} = object
|
#include <pthread.h>""".} = object
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
abi: array[40 div sizeof(clong), clong]
|
||||||
|
|
||||||
SysLockAttr {.importc: "pthread_mutexattr_t", pure, final
|
SysLockAttr {.importc: "pthread_mutexattr_t", pure, final
|
||||||
header: """#include <sys/types.h>
|
header: """#include <sys/types.h>
|
||||||
#include <pthread.h>""".} = object
|
#include <pthread.h>""".} = object
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
abi: array[4 div sizeof(cint), cint] # actually a cint
|
||||||
|
|
||||||
SysCond {.importc: "pthread_cond_t", pure, final,
|
SysCond {.importc: "pthread_cond_t", pure, final,
|
||||||
header: """#include <sys/types.h>
|
header: """#include <sys/types.h>
|
||||||
#include <pthread.h>""".} = object
|
#include <pthread.h>""".} = object
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
abi: array[48 div sizeof(clonglong), clonglong]
|
||||||
|
|
||||||
SysLockType = distinct cint
|
SysLockType = distinct cint
|
||||||
|
|
||||||
proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {.
|
proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {.
|
||||||
|
|
|
||||||
|
|
@ -177,18 +177,28 @@ else:
|
||||||
else:
|
else:
|
||||||
type Time = int
|
type Time = int
|
||||||
|
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
type
|
type
|
||||||
SysThread* {.importc: "pthread_t", header: "<sys/types.h>",
|
SysThread* {.importc: "pthread_t",
|
||||||
final, pure.} = object
|
header: "<sys/types.h>" .} = distinct culong
|
||||||
Pthread_attr {.importc: "pthread_attr_t",
|
Pthread_attr {.importc: "pthread_attr_t",
|
||||||
header: "<sys/types.h>", final, pure.} = object
|
header: "<sys/types.h>".} = object
|
||||||
|
abi: array[56 div sizeof(clong), clong]
|
||||||
Timespec {.importc: "struct timespec",
|
ThreadVarSlot {.importc: "pthread_key_t",
|
||||||
header: "<time.h>", final, pure.} = object
|
header: "<sys/types.h>".} = distinct cuint
|
||||||
|
else:
|
||||||
|
type
|
||||||
|
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = object
|
||||||
|
Pthread_attr {.importc: "pthread_attr_t",
|
||||||
|
header: "<sys/types.h>".} = object
|
||||||
|
ThreadVarSlot {.importc: "pthread_key_t",
|
||||||
|
header: "<sys/types.h>".} = object
|
||||||
|
type
|
||||||
|
Timespec {.importc: "struct timespec", header: "<time.h>".} = object
|
||||||
tv_sec: Time
|
tv_sec: Time
|
||||||
tv_nsec: clong
|
tv_nsec: clong
|
||||||
{.deprecated: [TSysThread: SysThread, Tpthread_attr: PThreadAttr,
|
{.deprecated: [TSysThread: SysThread, Tpthread_attr: PThreadAttr,
|
||||||
Ttimespec: Timespec].}
|
Ttimespec: Timespec, TThreadVarSlot: ThreadVarSlot].}
|
||||||
|
|
||||||
proc pthread_attr_init(a1: var PthreadAttr) {.
|
proc pthread_attr_init(a1: var PthreadAttr) {.
|
||||||
importc, header: pthreadh.}
|
importc, header: pthreadh.}
|
||||||
|
|
@ -205,11 +215,6 @@ else:
|
||||||
proc pthread_cancel(a1: SysThread): cint {.
|
proc pthread_cancel(a1: SysThread): cint {.
|
||||||
importc: "pthread_cancel", header: pthreadh.}
|
importc: "pthread_cancel", header: pthreadh.}
|
||||||
|
|
||||||
type
|
|
||||||
ThreadVarSlot {.importc: "pthread_key_t", pure, final,
|
|
||||||
header: "<sys/types.h>".} = object
|
|
||||||
{.deprecated: [TThreadVarSlot: ThreadVarSlot].}
|
|
||||||
|
|
||||||
proc pthread_getspecific(a1: ThreadVarSlot): pointer {.
|
proc pthread_getspecific(a1: ThreadVarSlot): pointer {.
|
||||||
importc: "pthread_getspecific", header: pthreadh.}
|
importc: "pthread_getspecific", header: pthreadh.}
|
||||||
proc pthread_key_create(a1: ptr ThreadVarSlot,
|
proc pthread_key_create(a1: ptr ThreadVarSlot,
|
||||||
|
|
@ -234,6 +239,9 @@ else:
|
||||||
importc: "pthread_attr_setstack", header: pthreadh.}
|
importc: "pthread_attr_setstack", header: pthreadh.}
|
||||||
|
|
||||||
type CpuSet {.importc: "cpu_set_t", header: schedh.} = object
|
type CpuSet {.importc: "cpu_set_t", header: schedh.} = object
|
||||||
|
when defined(linux) and defined(amd64):
|
||||||
|
abi: array[1024 div (8 * sizeof(culong)), culong]
|
||||||
|
|
||||||
proc cpusetZero(s: var CpuSet) {.importc: "CPU_ZERO", header: schedh.}
|
proc cpusetZero(s: var CpuSet) {.importc: "CPU_ZERO", header: schedh.}
|
||||||
proc cpusetIncl(cpu: cint; s: var CpuSet) {.
|
proc cpusetIncl(cpu: cint; s: var CpuSet) {.
|
||||||
importc: "CPU_SET", header: schedh.}
|
importc: "CPU_SET", header: schedh.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue