mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-19 06:01:11 +00:00
libc changes: unify c and libc types; Add [^]T where appropriate
This commit is contained in:
123
core/c/c.odin
123
core/c/c.odin
@@ -1,35 +1,96 @@
|
||||
package c
|
||||
|
||||
import b "core:builtin"
|
||||
import builtin "core:builtin"
|
||||
|
||||
char :: builtin.u8 // assuming -funsigned-char
|
||||
short :: builtin.i16
|
||||
int :: builtin.i32
|
||||
long :: builtin.i32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.i64
|
||||
longlong :: builtin.i64
|
||||
|
||||
uchar :: builtin.u8
|
||||
ushort :: builtin.u16
|
||||
uint :: builtin.u32
|
||||
ulong :: builtin.u32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.u64
|
||||
ulonglong :: builtin.u64
|
||||
|
||||
bool :: builtin.bool
|
||||
|
||||
size_t :: builtin.uint
|
||||
ssize_t :: builtin.int
|
||||
wchar_t :: builtin.u16 when (ODIN_OS == "windows") else builtin.u32
|
||||
|
||||
float :: builtin.f32
|
||||
double :: builtin.f64
|
||||
complex_float :: builtin.complex64
|
||||
complex_double :: builtin.complex128
|
||||
|
||||
// 7.20.1 Integer types
|
||||
int8_t :: builtin.i8
|
||||
uint8_t :: builtin.u8
|
||||
int16_t :: builtin.i16
|
||||
uint16_t :: builtin.u16
|
||||
int32_t :: builtin.i32
|
||||
uint32_t :: builtin.u32
|
||||
int64_t :: builtin.i64
|
||||
uint64_t :: builtin.u64
|
||||
|
||||
// These are all the same in multiple libc's for multiple architectures.
|
||||
int_least8_t :: builtin.i8
|
||||
uint_least8_t :: builtin.u8
|
||||
int_least16_t :: builtin.i16
|
||||
uint_least16_t :: builtin.u16
|
||||
int_least32_t :: builtin.i32
|
||||
uint_least32_t :: builtin.u32
|
||||
int_least64_t :: builtin.i64
|
||||
uint_least64_t :: builtin.u64
|
||||
|
||||
// Same on Windows, Linux, and FreeBSD
|
||||
when ODIN_ARCH == "386" || ODIN_ARCH == "amd64" {
|
||||
int_fast8_t :: builtin.i8
|
||||
uint_fast8_t :: builtin.u8
|
||||
int_fast16_t :: builtin.i32
|
||||
uint_fast16_t :: builtin.u32
|
||||
int_fast32_t :: builtin.i32
|
||||
uint_fast32_t :: builtin.u32
|
||||
int_fast64_t :: builtin.i64
|
||||
uint_fast64_t :: builtin.u64
|
||||
} else {
|
||||
int_fast8_t :: builtin.i8
|
||||
uint_fast8_t :: builtin.u8
|
||||
int_fast16_t :: builtin.i32
|
||||
uint_fast16_t :: builtin.u32
|
||||
int_fast32_t :: builtin.i32
|
||||
uint_fast32_t :: builtin.u32
|
||||
int_fast64_t :: builtin.i64
|
||||
uint_fast64_t :: builtin.u64
|
||||
}
|
||||
|
||||
intptr_t :: builtin.int
|
||||
uintptr_t :: builtin.uintptr
|
||||
ptrdiff_t :: distinct intptr_t
|
||||
|
||||
intmax_t :: builtin.i64
|
||||
uintmax_t :: builtin.u64
|
||||
|
||||
// Copy C's rules for type promotion here by forcing the type on the literals.
|
||||
INT8_MAX :: int(0x7f)
|
||||
INT16_MAX :: int(0x7fff)
|
||||
INT32_MAX :: int(0x7fffffff)
|
||||
INT64_MAX :: longlong(0x7fffffffffffffff)
|
||||
|
||||
UINT8_MAX :: int(0xff)
|
||||
UINT16_MAX :: int(0xffff)
|
||||
UINT32_MAX :: uint(0xffffffff)
|
||||
UINT64_MAX :: ulonglong(0xffffffffffffffff)
|
||||
|
||||
INT8_MIN :: ~INT8_MAX
|
||||
INT16_MIN :: ~INT16_MAX
|
||||
INT32_MIN :: ~INT32_MAX
|
||||
INT64_MIN :: ~INT64_MAX
|
||||
|
||||
NULL :: rawptr(uintptr(0))
|
||||
|
||||
NDEBUG :: !ODIN_DEBUG
|
||||
|
||||
CHAR_BIT :: 8
|
||||
|
||||
bool :: b.bool
|
||||
char :: b.u8
|
||||
byte :: b.byte
|
||||
schar :: b.i8
|
||||
uchar :: b.u8
|
||||
short :: b.i16
|
||||
ushort :: b.u16
|
||||
int :: b.i32
|
||||
uint :: b.u32
|
||||
|
||||
long :: b.i32 when (ODIN_OS == "windows" || size_of(b.rawptr) == 4) else b.i64
|
||||
ulong :: b.u32 when (ODIN_OS == "windows" || size_of(b.rawptr) == 4) else b.u64
|
||||
|
||||
longlong :: b.i64
|
||||
ulonglong :: b.u64
|
||||
float :: b.f32
|
||||
double :: b.f64
|
||||
complex_float :: b.complex64
|
||||
complex_double :: b.complex128
|
||||
|
||||
#assert(size_of(b.uintptr) == size_of(b.int))
|
||||
|
||||
size_t :: b.uint
|
||||
ssize_t :: b.int
|
||||
ptrdiff_t :: b.int
|
||||
uintptr_t :: b.uintptr
|
||||
intptr_t :: b.int
|
||||
|
||||
wchar_t :: b.u16 when (ODIN_OS == "windows") else b.u32
|
||||
|
||||
@@ -82,34 +82,34 @@ foreign libc {
|
||||
remove :: proc(filename: cstring) -> int ---
|
||||
rename :: proc(old, new: cstring) -> int ---
|
||||
tmpfile :: proc() -> ^FILE ---
|
||||
tmpnam :: proc(s: ^char) -> ^char ---
|
||||
tmpnam :: proc(s: [^]char) -> [^]char ---
|
||||
|
||||
// 7.21.5 File access functions
|
||||
fclose :: proc(stream: ^FILE) -> int ---
|
||||
fflush :: proc(stream: ^FILE) -> int ---
|
||||
fopen :: proc(filename, mode: cstring) -> ^FILE ---
|
||||
freopen :: proc(filename, mode: cstring, stream: ^FILE) -> ^FILE ---
|
||||
setbuf :: proc(stream: ^FILE, buf: ^char) ---
|
||||
setvbuf :: proc(stream: ^FILE, buf: ^char, mode: int, size: size_t) -> int ---
|
||||
setbuf :: proc(stream: ^FILE, buf: [^]char) ---
|
||||
setvbuf :: proc(stream: ^FILE, buf: [^]char, mode: int, size: size_t) -> int ---
|
||||
|
||||
// 7.21.6 Formatted input/output functions
|
||||
fprintf :: proc(stream: ^FILE, format: cstring, #c_vararg args: ..any) -> int ---
|
||||
fscanf :: proc(stream: ^FILE, format: cstring, #c_vararg args: ..any) -> int ---
|
||||
printf :: proc(format: cstring, #c_vararg args: ..any) -> int ---
|
||||
scanf :: proc(format: cstring, #c_vararg args: ..any) -> int ---
|
||||
snprintf :: proc(s: ^char, format: cstring, #c_vararg args: ..any) -> int ---
|
||||
snprintf :: proc(s: [^]char, format: cstring, #c_vararg args: ..any) -> int ---
|
||||
sscanf :: proc(s, format: cstring, #c_vararg args: ..any) -> int ---
|
||||
vfprintf :: proc(stream: ^FILE, format: cstring, arg: ^va_list) -> int ---
|
||||
vfscanf :: proc(stream: ^FILE, format: cstring, arg: ^va_list) -> int ---
|
||||
vprintf :: proc(format: cstring, arg: ^va_list) -> int ---
|
||||
vscanf :: proc(format: cstring, arg: ^va_list) -> int ---
|
||||
vsnprintf :: proc(s: ^char, n: size_t, format: cstring, arg: ^va_list) -> int ---
|
||||
vsprintf :: proc(s: ^char, format: cstring, arg: ^va_list) -> int ---
|
||||
vsnprintf :: proc(s: [^]char, n: size_t, format: cstring, arg: ^va_list) -> int ---
|
||||
vsprintf :: proc(s: [^]char, format: cstring, arg: ^va_list) -> int ---
|
||||
vsscanf :: proc(s, format: cstring, arg: ^va_list) -> int ---
|
||||
|
||||
// 7.21.7 Character input/output functions
|
||||
fgetc :: proc(stream: ^FILE) -> int ---
|
||||
fgets :: proc(s: ^char, n: int, stream: ^FILE) -> ^char ---
|
||||
fgets :: proc(s: [^]char, n: int, stream: ^FILE) -> [^]char ---
|
||||
fputc :: proc(s: cstring, stream: ^FILE) -> int ---
|
||||
getc :: proc(stream: ^FILE) -> int ---
|
||||
getchar :: proc() -> int ---
|
||||
|
||||
@@ -58,12 +58,12 @@ foreign libc {
|
||||
atoi :: proc(nptr: cstring) -> int ---
|
||||
atol :: proc(nptr: cstring) -> long ---
|
||||
atoll :: proc(nptr: cstring) -> longlong ---
|
||||
strtod :: proc(nptr: cstring, endptr: ^^char) -> double ---
|
||||
strtof :: proc(nptr: cstring, endptr: ^^char) -> float ---
|
||||
strtol :: proc(nptr: cstring, endptr: ^^char, base: int) -> long ---
|
||||
strtoll :: proc(nptr: cstring, endptr: ^^char, base: int) -> longlong ---
|
||||
strtoul :: proc(nptr: cstring, endptr: ^^char, base: int) -> ulong ---
|
||||
strtoull :: proc(nptr: cstring, endptr: ^^char, base: int) -> ulonglong ---
|
||||
strtod :: proc(nptr: cstring, endptr: ^[^]char) -> double ---
|
||||
strtof :: proc(nptr: cstring, endptr: ^[^]char) -> float ---
|
||||
strtol :: proc(nptr: cstring, endptr: ^[^]char, base: int) -> long ---
|
||||
strtoll :: proc(nptr: cstring, endptr: ^[^]char, base: int) -> longlong ---
|
||||
strtoul :: proc(nptr: cstring, endptr: ^[^]char, base: int) -> ulong ---
|
||||
strtoull :: proc(nptr: cstring, endptr: ^[^]char, base: int) -> ulonglong ---
|
||||
|
||||
// 7.22.2 Pseudo-random sequence generation functions
|
||||
rand :: proc() -> int ---
|
||||
@@ -82,7 +82,7 @@ foreign libc {
|
||||
at_quick_exit :: proc(func: proc "c" ()) -> int ---
|
||||
exit :: proc(status: int) -> ! ---
|
||||
_Exit :: proc(status: int) -> ! ---
|
||||
getenv :: proc(name: cstring) -> ^char ---
|
||||
getenv :: proc(name: cstring) -> [^]char ---
|
||||
quick_exit :: proc(status: int) -> ! ---
|
||||
system :: proc(cmd: cstring) -> int ---
|
||||
|
||||
@@ -101,9 +101,9 @@ foreign libc {
|
||||
// 7.22.7 Multibyte/wide character conversion functions
|
||||
mblen :: proc(s: cstring, n: size_t) -> int ---
|
||||
mbtowc :: proc(pwc: ^wchar_t, s: cstring, n: size_t) -> int ---
|
||||
wctomb :: proc(s: ^char, wc: wchar_t) -> int ---
|
||||
wctomb :: proc(s: [^]char, wc: wchar_t) -> int ---
|
||||
|
||||
// 7.22.8 Multibyte/wide string conversion functions
|
||||
mbstowcs :: proc(pwcs: ^wchar_t, s: cstring, n: size_t) -> size_t ---
|
||||
wcstombs :: proc(s: ^char, pwcs: ^wchar_t, n: size_t) -> size_t ---
|
||||
wcstombs :: proc(s: [^]char, pwcs: ^wchar_t, n: size_t) -> size_t ---
|
||||
}
|
||||
|
||||
@@ -13,31 +13,31 @@ foreign libc {
|
||||
// 7.24.2 Copying functions
|
||||
memcpy :: proc(s1, s2: rawptr, n: size_t) -> rawptr ---
|
||||
memmove :: proc(s1, s2: rawptr, n: size_t) -> rawptr ---
|
||||
strcpy :: proc(s1: ^char, s2: cstring) -> ^char ---
|
||||
strncpy :: proc(s1: ^char, s2: cstring, n: size_t) -> ^char ---
|
||||
strcpy :: proc(s1: [^]char, s2: cstring) -> [^]char ---
|
||||
strncpy :: proc(s1: [^]char, s2: cstring, n: size_t) -> [^]char ---
|
||||
|
||||
// 7.24.3 Concatenation functions
|
||||
strcat :: proc(s1: ^char, s2: cstring) -> ^char ---
|
||||
strncat :: proc(s1: ^char, s2: cstring, n: size_t) -> ^char ---
|
||||
strcat :: proc(s1: [^]char, s2: cstring) -> [^]char ---
|
||||
strncat :: proc(s1: [^]char, s2: cstring, n: size_t) -> [^]char ---
|
||||
|
||||
// 7.24.4 Comparison functions
|
||||
memcmp :: proc(s1, s2: rawptr, n: size_t) -> int ---
|
||||
strcmp :: proc(s1, s2: cstring) -> int ---
|
||||
strcoll :: proc(s1, s2: cstring) -> int ---
|
||||
strncmp :: proc(s1, s2: cstring, n: size_t) -> int ---
|
||||
strxfrm :: proc(s1: ^char, s2: cstring, n: size_t) -> size_t ---
|
||||
strxfrm :: proc(s1: [^]char, s2: cstring, n: size_t) -> size_t ---
|
||||
|
||||
// 7.24.5 Search functions
|
||||
memchr :: proc(s: rawptr, c: int, n: size_t) -> rawptr ---
|
||||
strchr :: proc(s: cstring, c: int) -> ^char ---
|
||||
strchr :: proc(s: cstring, c: int) -> [^]char ---
|
||||
strcspn :: proc(s1, s2: cstring) -> size_t ---
|
||||
strpbrk :: proc(s1, s2: cstring) -> ^char ---
|
||||
strrchr :: proc(s: ^char, c: int) -> ^char ---
|
||||
strcpn :: proc(s1, s2: cstring) -> ^char ---
|
||||
strtok :: proc(s1: ^char, s2: cstring) -> ^char ---
|
||||
strpbrk :: proc(s1, s2: cstring) -> [^]char ---
|
||||
strrchr :: proc(s: [^]char, c: int) -> [^]char ---
|
||||
strcpn :: proc(s1, s2: cstring) -> [^]char ---
|
||||
strtok :: proc(s1: [^]char, s2: cstring) -> [^]char ---
|
||||
|
||||
// 7.24.6 Miscellaneous functions
|
||||
memset :: proc(s: rawptr, c: int, n: size_t) -> rawptr ---
|
||||
strerror :: proc(errnum: int) -> ^char ---
|
||||
strerror :: proc(errnum: int) -> [^]char ---
|
||||
strlen :: proc(s: cstring) -> size_t ---
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ when ODIN_OS == "windows" {
|
||||
@(link_name="_timespec64_get") timespec_get :: proc(ts: ^timespec, base: int) -> int ---
|
||||
|
||||
// 7.27.3 Time conversion functions
|
||||
asctime :: proc(timeptr: ^tm) -> ^char ---
|
||||
@(link_name="_ctime64") ctime :: proc(timer: ^time_t) -> ^char ---
|
||||
asctime :: proc(timeptr: ^tm) -> [^]char ---
|
||||
@(link_name="_ctime64") ctime :: proc(timer: ^time_t) -> [^]char ---
|
||||
@(link_name="_gmtime64") gmtime :: proc(timer: ^time_t) -> ^tm ---
|
||||
@(link_name="_localtime64") localtime :: proc(timer: ^time_t) -> ^tm ---
|
||||
strftime :: proc(s: ^char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---
|
||||
strftime :: proc(s: [^]char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---
|
||||
}
|
||||
|
||||
CLOCKS_PER_SEC :: 1000
|
||||
@@ -54,11 +54,11 @@ when ODIN_OS == "linux" || ODIN_OS == "freebsd" {
|
||||
timespec_get :: proc(ts: ^timespec, base: int) -> int ---
|
||||
|
||||
// 7.27.3 Time conversion functions
|
||||
asctime :: proc(timeptr: ^tm) -> ^char ---
|
||||
ctime :: proc(timer: ^time_t) -> ^char ---
|
||||
asctime :: proc(timeptr: ^tm) -> [^]char ---
|
||||
ctime :: proc(timer: ^time_t) -> [^]char ---
|
||||
gmtime :: proc(timer: ^time_t) -> ^tm ---
|
||||
localtime :: proc(timer: ^time_t) -> ^tm ---
|
||||
strftime :: proc(s: ^char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---
|
||||
strftime :: proc(s: [^]char, maxsize: size_t, format: cstring, timeptr: ^tm) -> size_t ---
|
||||
}
|
||||
|
||||
CLOCKS_PER_SEC :: 1000000
|
||||
|
||||
@@ -1,82 +1,80 @@
|
||||
package libc
|
||||
|
||||
import builtin "core:builtin"
|
||||
import "core:c"
|
||||
|
||||
char :: builtin.u8 // assuming -funsigned-char
|
||||
short :: builtin.i16
|
||||
int :: builtin.i32
|
||||
long :: builtin.i32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.i64
|
||||
longlong :: builtin.i64
|
||||
char :: c.char // assuming -funsigned-char
|
||||
short :: c.short
|
||||
int :: c.int
|
||||
long :: c.long
|
||||
longlong :: c.longlong
|
||||
|
||||
uchar :: builtin.u8
|
||||
ushort :: builtin.u16
|
||||
uint :: builtin.u32
|
||||
ulong :: builtin.u32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.u64
|
||||
ulonglong :: builtin.u64
|
||||
uchar :: c.uchar
|
||||
ushort :: c.ushort
|
||||
uint :: c.uint
|
||||
ulong :: c.ulong
|
||||
ulonglong :: c.ulonglong
|
||||
|
||||
bool :: distinct builtin.b8
|
||||
bool :: c.bool
|
||||
|
||||
size_t :: builtin.uint
|
||||
wchar_t :: builtin.u16 when (ODIN_OS == "windows") else builtin.u32
|
||||
size_t :: c.size_t
|
||||
ssize_t :: c.ssize_t
|
||||
wchar_t :: c.wchar_t
|
||||
|
||||
float :: builtin.f32
|
||||
double :: builtin.f64
|
||||
float :: c.float
|
||||
double :: c.double
|
||||
|
||||
// 7.20.1 Integer types
|
||||
int8_t :: builtin.i8
|
||||
uint8_t :: builtin.u8
|
||||
int16_t :: builtin.i16
|
||||
uint16_t :: builtin.u16
|
||||
int32_t :: builtin.i32
|
||||
uint32_t :: builtin.u32
|
||||
int64_t :: builtin.i64
|
||||
uint64_t :: builtin.u64
|
||||
int8_t :: c.int8_t
|
||||
uint8_t :: c.uint8_t
|
||||
int16_t :: c.int16_t
|
||||
uint16_t :: c.uint16_t
|
||||
int32_t :: c.int32_t
|
||||
uint32_t :: c.uint32_t
|
||||
int64_t :: c.int64_t
|
||||
uint64_t :: c.uint64_t
|
||||
|
||||
// These are all the same in multiple libc's for multiple architectures.
|
||||
int_least8_t :: builtin.i8
|
||||
uint_least8_t :: builtin.u8
|
||||
int_least16_t :: builtin.i16
|
||||
uint_least16_t :: builtin.u16
|
||||
int_least32_t :: builtin.i32
|
||||
uint_least32_t :: builtin.u32
|
||||
int_least64_t :: builtin.i64
|
||||
uint_least64_t :: builtin.u64
|
||||
int_least8_t :: c.int_least8_t
|
||||
uint_least8_t :: c.uint_least8_t
|
||||
int_least16_t :: c.int_least16_t
|
||||
uint_least16_t :: c.uint_least16_t
|
||||
int_least32_t :: c.int_least32_t
|
||||
uint_least32_t :: c.uint_least32_t
|
||||
int_least64_t :: c.int_least64_t
|
||||
uint_least64_t :: c.uint_least64_t
|
||||
|
||||
// Same on Windows, Linux, and FreeBSD
|
||||
when ODIN_ARCH == "386" || ODIN_ARCH == "amd64" {
|
||||
int_fast8_t :: builtin.i8
|
||||
uint_fast8_t :: builtin.u8
|
||||
int_fast16_t :: builtin.i32
|
||||
uint_fast16_t :: builtin.u32
|
||||
int_fast32_t :: builtin.i32
|
||||
uint_fast32_t :: builtin.u32
|
||||
int_fast64_t :: builtin.i64
|
||||
uint_fast64_t :: builtin.u64
|
||||
}
|
||||
int_fast8_t :: c.int_fast8_t
|
||||
uint_fast8_t :: c.uint_fast8_t
|
||||
int_fast16_t :: c.int_fast16_t
|
||||
uint_fast16_t :: c.uint_fast16_t
|
||||
int_fast32_t :: c.int_fast32_t
|
||||
uint_fast32_t :: c.uint_fast32_t
|
||||
int_fast64_t :: c.int_fast64_t
|
||||
uint_fast64_t :: c.uint_fast64_t
|
||||
|
||||
intptr_t :: builtin.int
|
||||
uintptr_t :: builtin.uintptr
|
||||
ptrdiff_t :: distinct intptr_t
|
||||
intptr_t :: c.intptr_t
|
||||
uintptr_t :: c.uintptr_t
|
||||
ptrdiff_t :: c.ptrdiff_t
|
||||
|
||||
intmax_t :: builtin.i64
|
||||
uintmax_t :: builtin.u64
|
||||
intmax_t :: c.intmax_t
|
||||
uintmax_t :: c.uintmax_t
|
||||
|
||||
// Copy C's rules for type promotion here by forcing the type on the literals.
|
||||
INT8_MAX :: int(0x7f)
|
||||
INT16_MAX :: int(0x7fff)
|
||||
INT32_MAX :: int(0x7fffffff)
|
||||
INT64_MAX :: longlong(0x7fffffffffffffff)
|
||||
INT8_MAX :: c.INT8_MAX
|
||||
INT16_MAX :: c.INT16_MAX
|
||||
INT32_MAX :: c.INT32_MAX
|
||||
INT64_MAX :: c.INT64_MAX
|
||||
|
||||
UINT8_MAX :: int(0xff)
|
||||
UINT16_MAX :: int(0xffff)
|
||||
UINT32_MAX :: uint(0xffffffff)
|
||||
UINT64_MAX :: ulonglong(0xffffffffffffffff)
|
||||
UINT8_MAX :: c.UINT8_MAX
|
||||
UINT16_MAX :: c.UINT16_MAX
|
||||
UINT32_MAX :: c.UINT32_MAX
|
||||
UINT64_MAX :: c.UINT64_MAX
|
||||
|
||||
INT8_MIN :: ~INT8_MAX
|
||||
INT16_MIN :: ~INT16_MAX
|
||||
INT32_MIN :: ~INT32_MAX
|
||||
INT64_MIN :: ~INT64_MAX
|
||||
INT8_MIN :: c.INT8_MIN
|
||||
INT16_MIN :: c.INT16_MIN
|
||||
INT32_MIN :: c.INT32_MIN
|
||||
INT64_MIN :: c.INT64_MIN
|
||||
|
||||
NULL :: rawptr(uintptr(0))
|
||||
|
||||
NDEBUG :: !ODIN_DEBUG
|
||||
|
||||
CHAR_BIT :: 8
|
||||
|
||||
@@ -11,9 +11,9 @@ when ODIN_OS == "windows" {
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
// 7.28.1 Restartable multibyte/wide character conversion functions
|
||||
mbrtoc16 :: proc(pc16: ^char16_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbrtoc16 :: proc(pc16: [^]char16_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
c16rtomb :: proc(s: ^char, c16: char16_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbrtoc32 :: proc(pc32: ^char32_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbrtoc32 :: proc(pc32: [^]char32_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
c32rtomb :: proc(s: ^char, c32: char32_t, ps: ^mbstate_t) -> size_t ---
|
||||
}
|
||||
|
||||
|
||||
@@ -11,24 +11,24 @@ when ODIN_OS == "windows" {
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
// 7.29.2 Formatted wide character input/output functions
|
||||
fwprintf :: proc(stream: ^FILE, format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
fwscanf :: proc(stream: ^FILE, format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
swprintf :: proc(stream: ^FILE, n: size_t, format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
swscanf :: proc(s, format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
vfwprintf :: proc(stream: ^FILE, format: ^wchar_t, arg: va_list) -> int ---
|
||||
vfwscanf :: proc(stream: ^FILE, format: ^wchar_t, arg: va_list) -> int ---
|
||||
vswprintf :: proc(s: ^wchar_t, n: size_t, format: ^wchar_t, arg: va_list) -> int ---
|
||||
vswscanf :: proc(s, format: ^wchar_t, arg: va_list) -> int ---
|
||||
vwprintf :: proc(format: ^wchar_t, arg: va_list) -> int ---
|
||||
vwscanf :: proc(format: ^wchar_t, arg: va_list) -> int ---
|
||||
wprintf :: proc(format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
wscanf :: proc(format: ^wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
fwprintf :: proc(stream: ^FILE, format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
fwscanf :: proc(stream: ^FILE, format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
swprintf :: proc(stream: ^FILE, n: size_t, format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
swscanf :: proc(s, format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
vfwprintf :: proc(stream: ^FILE, format: [^]wchar_t, arg: va_list) -> int ---
|
||||
vfwscanf :: proc(stream: ^FILE, format: [^]wchar_t, arg: va_list) -> int ---
|
||||
vswprintf :: proc(s: [^]wchar_t, n: size_t, format: [^]wchar_t, arg: va_list) -> int ---
|
||||
vswscanf :: proc(s, format: [^]wchar_t, arg: va_list) -> int ---
|
||||
vwprintf :: proc(format: [^]wchar_t, arg: va_list) -> int ---
|
||||
vwscanf :: proc(format: [^]wchar_t, arg: va_list) -> int ---
|
||||
wprintf :: proc(format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
wscanf :: proc(format: [^]wchar_t, #c_vararg arg: ..any) -> int ---
|
||||
|
||||
// 7.29.3 Wide character input/output functions
|
||||
fwgetc :: proc(stream: ^FILE) -> wint_t ---
|
||||
fgetws :: proc(s: ^wchar_t, n: int, stream: ^FILE) -> wchar_t ---
|
||||
fgetws :: proc(s: [^]wchar_t, n: int, stream: ^FILE) -> wchar_t ---
|
||||
fputwc :: proc(c: wchar_t, stream: ^FILE) -> wint_t ---
|
||||
fputws :: proc(s: ^wchar_t, stream: ^FILE) -> int ---
|
||||
fputws :: proc(s: [^]wchar_t, stream: ^FILE) -> int ---
|
||||
fwide :: proc(stream: ^FILE, mode: int) -> int ---
|
||||
getwc :: proc(stream: ^FILE) -> wint_t ---
|
||||
getwchar :: proc() -> wint_t ---
|
||||
@@ -37,46 +37,46 @@ foreign libc {
|
||||
ungetwc :: proc(c: wchar_t, stream: ^FILE) -> wint_t ---
|
||||
|
||||
// 7.29.4 General wide string utilities
|
||||
wcstod :: proc(nptr: ^wchar_t, endptr: ^^wchar_t) -> double ---
|
||||
wcstof :: proc(nptr: ^wchar_t, endptr: ^^wchar_t) -> float ---
|
||||
wcstol :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> long ---
|
||||
wcstoll :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> longlong ---
|
||||
wcstoul :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> ulong ---
|
||||
wcstoull :: proc(nptr: ^wchar_t, endptr: ^^wchar_t, base: int) -> ulonglong ---
|
||||
wcstod :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t) -> double ---
|
||||
wcstof :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t) -> float ---
|
||||
wcstol :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t, base: int) -> long ---
|
||||
wcstoll :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t, base: int) -> longlong ---
|
||||
wcstoul :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t, base: int) -> ulong ---
|
||||
wcstoull :: proc(nptr: [^]wchar_t, endptr: ^[^]wchar_t, base: int) -> ulonglong ---
|
||||
|
||||
// 7.29.4.2 Wide string copying functions
|
||||
wcscpy :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---
|
||||
wcsncpy :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wmemcpy :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wmemmove :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wcscpy :: proc(s1, s2: [^]wchar_t) -> [^]wchar_t ---
|
||||
wcsncpy :: proc(s1, s2: [^]wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
wmemcpy :: proc(s1, s2: [^]wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
wmemmove :: proc(s1, s2: [^]wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
|
||||
// 7.29.4.3 Wide string concatenation functions
|
||||
wcscat :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---
|
||||
wcsncat :: proc(s1, s2: ^wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wcscat :: proc(s1, s2: [^]wchar_t) -> [^]wchar_t ---
|
||||
wcsncat :: proc(s1, s2: [^]wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
|
||||
// 7.29.4.4 Wide string comparison functions
|
||||
wcscmp :: proc(s1, s2: ^wchar_t) -> int ---
|
||||
wcscoll :: proc(s1, s2: ^wchar_t) -> int ---
|
||||
wcsncmp :: proc(s1, s2: ^wchar_t, n: size_t) -> int ---
|
||||
wcsxfrm :: proc(s1, s2: ^wchar_t, n: size_t) -> size_t ---
|
||||
wmemcmp :: proc(s1, s2: ^wchar_t, n: size_t) -> int ---
|
||||
wcscmp :: proc(s1, s2: [^]wchar_t) -> int ---
|
||||
wcscoll :: proc(s1, s2: [^]wchar_t) -> int ---
|
||||
wcsncmp :: proc(s1, s2: [^]wchar_t, n: size_t) -> int ---
|
||||
wcsxfrm :: proc(s1, s2: [^]wchar_t, n: size_t) -> size_t ---
|
||||
wmemcmp :: proc(s1, s2: [^]wchar_t, n: size_t) -> int ---
|
||||
|
||||
// 7.29.4.5 Wide string search functions
|
||||
wcschr :: proc(s: ^wchar_t, c: wchar_t) -> ^wchar_t ---
|
||||
wcscspn :: proc(s1, s2: ^wchar_t) -> size_t ---
|
||||
wcspbrk :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---
|
||||
wcsrchr :: proc(s: ^wchar_t, c: wchar_t) -> ^wchar_t ---
|
||||
wcsspn :: proc(s1, s2: ^wchar_t) -> size_t ---
|
||||
wcsstr :: proc(s1, s2: ^wchar_t) -> ^wchar_t ---
|
||||
wcstok :: proc(s1, s2: ^wchar_t, ptr: ^^wchar_t) -> ^wchar_t ---
|
||||
wmemchr :: proc(s: ^wchar_t, c: wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wcschr :: proc(s: [^]wchar_t, c: wchar_t) -> [^]wchar_t ---
|
||||
wcscspn :: proc(s1, s2: [^]wchar_t) -> size_t ---
|
||||
wcspbrk :: proc(s1, s2: [^]wchar_t) -> [^]wchar_t ---
|
||||
wcsrchr :: proc(s: [^]wchar_t, c: wchar_t) -> [^]wchar_t ---
|
||||
wcsspn :: proc(s1, s2: [^]wchar_t) -> size_t ---
|
||||
wcsstr :: proc(s1, s2: [^]wchar_t) -> [^]wchar_t ---
|
||||
wcstok :: proc(s1, s2: [^]wchar_t, ptr: ^[^]wchar_t) -> [^]wchar_t ---
|
||||
wmemchr :: proc(s: [^]wchar_t, c: wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
|
||||
// 7.29.4.6 Miscellaneous functions
|
||||
wcslen :: proc(s: ^wchar_t) -> size_t ---
|
||||
wmemset :: proc(s: ^wchar_t, c: wchar_t, n: size_t) -> ^wchar_t ---
|
||||
wcslen :: proc(s: [^]wchar_t) -> size_t ---
|
||||
wmemset :: proc(s: [^]wchar_t, c: wchar_t, n: size_t) -> [^]wchar_t ---
|
||||
|
||||
// 7.29.5 Wide character time conversion functions
|
||||
wcsftime :: proc(s: ^wchar_t, maxsize: size_t, format: ^wchar_t, timeptr: ^tm) -> size_t ---
|
||||
wcsftime :: proc(s: [^]wchar_t, maxsize: size_t, format: [^]wchar_t, timeptr: ^tm) -> size_t ---
|
||||
|
||||
// 7.29.6.1 Single-byte/wide character conversion functions
|
||||
btowc :: proc(c: int) -> wint_t ---
|
||||
@@ -87,12 +87,12 @@ foreign libc {
|
||||
|
||||
// 7.29.6.3 Restartable multibyte/wide character conversion functions
|
||||
mbrlen :: proc(s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbrtowc :: proc(pwc: ^wchar_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbrtowc :: proc(pwc: [^]wchar_t, s: cstring, n: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
wcrtomb :: proc(s: ^char, wc: wchar_t, ps: ^mbstate_t) -> size_t ---
|
||||
|
||||
// 7.29.6.4 Restartable multibyte/wide string conversion functions
|
||||
mbsrtowcs :: proc(dst: ^wchar_t, src: ^cstring, len: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
wcsrtombs :: proc(dst: ^char, src: ^^wchar_t, len: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
mbsrtowcs :: proc(dst: [^]wchar_t, src: ^cstring, len: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
wcsrtombs :: proc(dst: ^char, src: ^[^]wchar_t, len: size_t, ps: ^mbstate_t) -> size_t ---
|
||||
}
|
||||
|
||||
// Large enough and aligned enough for any wide-spread in-use libc.
|
||||
|
||||
@@ -3,8 +3,15 @@ package mem
|
||||
import "core:runtime"
|
||||
import "core:intrinsics"
|
||||
|
||||
set :: proc "contextless" (data: rawptr, value: byte, len: int) -> rawptr {
|
||||
return runtime.memset(data, i32(value), len)
|
||||
set :: proc "contextless" (data: rawptr, value: byte, len: int) -> rawptr #no_bounds_check {
|
||||
if data != nil && len != 0 {
|
||||
b := byte(value)
|
||||
p := ([^]byte)(data)[:len]
|
||||
for v in &p {
|
||||
v = b
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
zero :: proc "contextless" (data: rawptr, len: int) -> rawptr {
|
||||
return set(data, 0, len)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
@(link_name="memset")
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
//+build linux, darwin, freebsd
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
import "core:intrinsics"
|
||||
|
||||
@(link_name="memset")
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
|
||||
if ptr == nil || len == 0 {
|
||||
return ptr
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr #no_bounds_check {
|
||||
if ptr != nil && len != 0 {
|
||||
b := byte(val)
|
||||
p := ([^]byte)(ptr)[:len]
|
||||
for v in &p {
|
||||
v = b
|
||||
}
|
||||
}
|
||||
b := byte(val)
|
||||
|
||||
p_start := uintptr(ptr)
|
||||
p_end := p_start + uintptr(max(len, 0))
|
||||
for p := p_start; p < p_end; p += 1 {
|
||||
(^byte)(p)^ = b
|
||||
}
|
||||
|
||||
return ptr
|
||||
}
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
//+build wasm32
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
@(link_name="memset")
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
|
||||
if ptr == nil || len == 0 {
|
||||
return ptr;
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr #no_bounds_check {
|
||||
if ptr != nil && len != 0 {
|
||||
b := byte(val)
|
||||
p := ([^]byte)(ptr)[:len]
|
||||
for v in &p {
|
||||
v = b
|
||||
}
|
||||
}
|
||||
b := byte(val);
|
||||
|
||||
p_start := uintptr(ptr);
|
||||
p_end := p_start + uintptr(max(len, 0));
|
||||
for p := p_start; p < p_end; p += 1 {
|
||||
(^byte)(p)^ = b;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
return ptr
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
@require foreign import "system:int64.lib"
|
||||
@@ -5,40 +6,39 @@ package runtime
|
||||
foreign import kernel32 "system:Kernel32.lib"
|
||||
|
||||
windows_trap_array_bounds :: proc "contextless" () -> ! {
|
||||
DWORD :: u32;
|
||||
ULONG_PTR :: uint;
|
||||
DWORD :: u32
|
||||
ULONG_PTR :: uint
|
||||
|
||||
EXCEPTION_ARRAY_BOUNDS_EXCEEDED :: 0xC000008C;
|
||||
EXCEPTION_ARRAY_BOUNDS_EXCEEDED :: 0xC000008C
|
||||
|
||||
foreign kernel32 {
|
||||
RaiseException :: proc "stdcall" (dwExceptionCode, dwExceptionFlags, nNumberOfArguments: DWORD, lpArguments: ^ULONG_PTR) -> ! ---
|
||||
}
|
||||
|
||||
RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, nil);
|
||||
RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, nil)
|
||||
}
|
||||
|
||||
windows_trap_type_assertion :: proc "contextless" () -> ! {
|
||||
windows_trap_array_bounds();
|
||||
windows_trap_array_bounds()
|
||||
}
|
||||
|
||||
@(private, require, link_name="_fltused") _fltused: i32 = 0x9875;
|
||||
@(private, require, link_name="_fltused") _fltused: i32 = 0x9875
|
||||
|
||||
@(private, require, link_name="_tls_index") _tls_index: u32;
|
||||
@(private, require, link_name="_tls_array") _tls_array: u32;
|
||||
@(private, require, link_name="_tls_index") _tls_index: u32
|
||||
@(private, require, link_name="_tls_array") _tls_array: u32
|
||||
|
||||
|
||||
|
||||
@(link_name="memcpy")
|
||||
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
if dst == nil || src == nil || len == 0 || dst == src {
|
||||
return dst;
|
||||
return dst
|
||||
}
|
||||
d := uintptr(dst);
|
||||
s := uintptr(src);
|
||||
n := uintptr(len);
|
||||
d := ([^]byte)(dst)
|
||||
s := ([^]byte)(src)
|
||||
|
||||
for i in 0..<n {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
for i in 0..<len {
|
||||
d[i] = s[i]
|
||||
}
|
||||
|
||||
return dst;
|
||||
@@ -47,57 +47,35 @@ memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
@(link_name="memmove")
|
||||
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
if dst == nil || src == nil || len == 0 || dst == src {
|
||||
return dst;
|
||||
return dst
|
||||
}
|
||||
|
||||
d := uintptr(dst);
|
||||
s := uintptr(src);
|
||||
n := uintptr(len);
|
||||
d := ([^]byte)(dst)
|
||||
s := ([^]byte)(src)
|
||||
|
||||
if s < d && d < s+n {
|
||||
if s < d && d < s[len:] {
|
||||
// Overlap
|
||||
for i := n-1; n >= 0; i -= 1 {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
for i := len-1; len >= 0; i -= 1 {
|
||||
d[i] = s[i]
|
||||
}
|
||||
|
||||
} else {
|
||||
for i in 0..<n {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
for i in 0..<len {
|
||||
d[i] = s[i]
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
return dst
|
||||
}
|
||||
|
||||
@(link_name="memset")
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
|
||||
if ptr == nil || len == 0 {
|
||||
return ptr;
|
||||
if ptr != nil && len != 0 {
|
||||
b := byte(val)
|
||||
p := ([^]byte)(ptr)[:len]
|
||||
for v in &p {
|
||||
v = b
|
||||
}
|
||||
}
|
||||
d := uintptr(ptr);
|
||||
b := byte(val);
|
||||
for i in 0..<uintptr(len) {
|
||||
(^byte)(d+i)^ = b;
|
||||
}
|
||||
return ptr;
|
||||
return ptr
|
||||
}
|
||||
|
||||
// @(link_name="memcmp")
|
||||
// memcmp :: proc "c" (dst, src: rawptr, len: int) -> i32 {
|
||||
// if dst == nil || src == nil {
|
||||
// return 0;
|
||||
// }
|
||||
// if dst == src {
|
||||
// return 0;
|
||||
// }
|
||||
// d, s := uintptr(dst), uintptr(src);
|
||||
// n := uintptr(len);
|
||||
|
||||
// for i := uintptr(0); i < n; i += 1 {
|
||||
// x, y := (^byte)(d+i)^, (^byte)(s+i)^;
|
||||
// if x != y {
|
||||
// return x < y ? -1 : +1;
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//+private
|
||||
package runtime
|
||||
|
||||
foreign import kernel32 "system:Kernel32.lib"
|
||||
@@ -51,19 +52,14 @@ memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
}
|
||||
|
||||
// @(link_name="memset")
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
|
||||
if ptr == nil || len == 0 {
|
||||
return ptr
|
||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr #no_bounds_check {
|
||||
if ptr != nil && len != 0 {
|
||||
b := byte(val)
|
||||
p := ([^]byte)(ptr)[:len]
|
||||
for v in &p {
|
||||
v = b
|
||||
}
|
||||
}
|
||||
|
||||
b := byte(val)
|
||||
|
||||
p_start := uintptr(ptr)
|
||||
p_end := p_start + uintptr(max(len, 0))
|
||||
for p := p_start; p < p_end; p += 1 {
|
||||
(^byte)(p)^ = b
|
||||
}
|
||||
|
||||
return ptr
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user