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:
Jacek Sieka
2017-04-13 04:57:10 +08:00
committed by Andreas Rumpf
parent 926563f0e6
commit e512358bc9
7 changed files with 86 additions and 35 deletions

View File

@@ -988,7 +988,7 @@ proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope) =
if typ.kind == tyObject: genTypeInfoAux(m, typ, origType, name)
else: genTypeInfoAuxBase(m, typ, origType, name, rope("0"))
var tmp = getNimNode(m)
if not isImportedCppType(typ):
if not isImportedType(typ):
genObjectFields(m, typ, origType, typ.n, tmp)
addf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, tmp])
var t = typ.sons[0]

View File

@@ -38,8 +38,10 @@ type
epoll_data* {.importc: "union epoll_data",
header: "<sys/epoll.h>", pure, final.} = object # TODO: This is actually a union.
#thePtr* {.importc: "ptr".}: pointer
fd* {.importc: "fd".}: cint # \
#u32*: uint32
fd* {.importc: "fd".}: cint
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
epoll_event* {.importc: "struct epoll_event", header: "<sys/epoll.h>", pure, final.} = object

View File

@@ -18,13 +18,25 @@ type
const
NCCS* = when defined(macosx): 20 else: 32
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_cc*: array[NCCS, cuchar] # control characters
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
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_cc*: array[NCCS, cuchar] # control characters
# cc characters

View File

@@ -47,15 +47,26 @@ type
dMon, dTue, dWed, dThu, dFri, dSat, dSun
when defined(posix) and not defined(JS):
type
TimeImpl {.importc: "time_t", header: "<time.h>".} = int
Time* = distinct TimeImpl ## distinct type that represents a time
## measured as number of seconds since the epoch
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: int ## Seconds.
tv_usec: int ## Microseconds.
Timeval {.importc: "struct timeval",
header: "<sys/select.h>".} = object ## struct timeval
tv_sec: clong ## Seconds.
tv_usec: clong ## Microseconds.
else:
type
TimeImpl {.importc: "time_t", header: "<time.h>".} = int
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: int ## Seconds.
tv_usec: int ## Microseconds.
# we cannot import posix.nim here, because posix.nim depends on times.nim.
# Ok, we could, but I don't want circular dependencies.
@@ -1103,7 +1114,7 @@ when not defined(JS):
when defined(freebsd) or defined(netbsd) or defined(openbsd) or
defined(macosx):
type
StructTM {.importc: "struct tm", final.} = object
StructTM {.importc: "struct tm".} = object
second {.importc: "tm_sec".},
minute {.importc: "tm_min".},
hour {.importc: "tm_hour".},
@@ -1116,7 +1127,7 @@ when not defined(JS):
gmtoff {.importc: "tm_gmtoff".}: clong
else:
type
StructTM {.importc: "struct tm", final.} = object
StructTM {.importc: "struct tm".} = object
second {.importc: "tm_sec".},
minute {.importc: "tm_min".},
hour {.importc: "tm_hour".},
@@ -1126,6 +1137,9 @@ when not defined(JS):
weekday {.importc: "tm_wday".},
yearday {.importc: "tm_yday".},
isdst {.importc: "tm_isdst".}: cint
when defined(linux) and defined(amd64):
gmtoff {.importc: "tm_gmtoff".}: clong
zone {.importc: "tm_zone".}: cstring
type
TimeInfoPtr = ptr StructTM
Clock {.importc: "clock_t".} = distinct int

View File

@@ -26,8 +26,14 @@ proc c_memset(p: pointer, value: cint, size: csize): pointer {.
proc c_strcmp(a, b: cstring): cint {.
importc: "strcmp", header: "<string.h>", noSideEffect.}
type
C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object
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
when defined(windows):
const

View File

@@ -102,12 +102,21 @@ else:
SysLock {.importc: "pthread_mutex_t", pure, final,
header: """#include <sys/types.h>
#include <pthread.h>""".} = object
when defined(linux) and defined(amd64):
abi: array[40 div sizeof(clong), clong]
SysLockAttr {.importc: "pthread_mutexattr_t", pure, final
header: """#include <sys/types.h>
#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,
header: """#include <sys/types.h>
#include <pthread.h>""".} = object
when defined(linux) and defined(amd64):
abi: array[48 div sizeof(clonglong), clonglong]
SysLockType = distinct cint
proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {.

View File

@@ -177,18 +177,28 @@ else:
else:
type Time = int
when defined(linux) and defined(amd64):
type
SysThread* {.importc: "pthread_t",
header: "<sys/types.h>" .} = distinct culong
Pthread_attr {.importc: "pthread_attr_t",
header: "<sys/types.h>".} = object
abi: array[56 div sizeof(clong), clong]
ThreadVarSlot {.importc: "pthread_key_t",
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
SysThread* {.importc: "pthread_t", header: "<sys/types.h>",
final, pure.} = object
Pthread_attr {.importc: "pthread_attr_t",
header: "<sys/types.h>", final, pure.} = object
Timespec {.importc: "struct timespec",
header: "<time.h>", final, pure.} = object
Timespec {.importc: "struct timespec", header: "<time.h>".} = object
tv_sec: Time
tv_nsec: clong
{.deprecated: [TSysThread: SysThread, Tpthread_attr: PThreadAttr,
Ttimespec: Timespec].}
Ttimespec: Timespec, TThreadVarSlot: ThreadVarSlot].}
proc pthread_attr_init(a1: var PthreadAttr) {.
importc, header: pthreadh.}
@@ -205,11 +215,6 @@ else:
proc pthread_cancel(a1: SysThread): cint {.
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 {.
importc: "pthread_getspecific", header: pthreadh.}
proc pthread_key_create(a1: ptr ThreadVarSlot,
@@ -234,6 +239,9 @@ else:
importc: "pthread_attr_setstack", header: pthreadh.}
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 cpusetIncl(cpu: cint; s: var CpuSet) {.
importc: "CPU_SET", header: schedh.}