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
commit e512358bc9
7 changed files with 86 additions and 35 deletions

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.}