cgen: make `bool`s take up a single byte, not 4 (#9352)

pull/9365/head
spaceface 2021-03-18 15:23:29 +01:00 committed by GitHub
parent 4ae2c22c18
commit 624c1f3bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -260,19 +260,19 @@ fn map_eq_string(a voidptr, b voidptr) bool {
}
fn map_eq_int_1(a voidptr, b voidptr) bool {
return unsafe { *&byte(a) == *&byte(b) }
return unsafe { C.memcmp(a, b, 1) == 0 }
}
fn map_eq_int_2(a voidptr, b voidptr) bool {
return unsafe { *&u16(a) == *&u16(b) }
return unsafe { C.memcmp(a, b, 2) == 0 }
}
fn map_eq_int_4(a voidptr, b voidptr) bool {
return unsafe { *&u32(a) == *&u32(b) }
return unsafe { C.memcmp(a, b, 4) == 0 }
}
fn map_eq_int_8(a voidptr, b voidptr) bool {
return unsafe { *&u64(a) == *&u64(b) }
return unsafe { C.memcmp(a, b, 8) == 0 }
}
fn map_clone_string(dest voidptr, pkey voidptr) {
@ -284,25 +284,25 @@ fn map_clone_string(dest voidptr, pkey voidptr) {
fn map_clone_int_1(dest voidptr, pkey voidptr) {
unsafe {
*&byte(dest) = *&byte(pkey)
C.memcpy(dest, pkey, 1)
}
}
fn map_clone_int_2(dest voidptr, pkey voidptr) {
unsafe {
*&u16(dest) = *&u16(pkey)
C.memcpy(dest, pkey, 2)
}
}
fn map_clone_int_4(dest voidptr, pkey voidptr) {
unsafe {
*&u32(dest) = *&u32(pkey)
C.memcpy(dest, pkey, 4)
}
}
fn map_clone_int_8(dest voidptr, pkey voidptr) {
unsafe {
*&u64(dest) = *&u64(pkey)
C.memcpy(dest, pkey, 8)
}
}

View File

@ -295,7 +295,8 @@ pub fn (mut s TcpSocket) set_option_bool(opt SocketOption, value bool) ? {
// if opt !in opts_bool {
// return err_option_wrong_type
// }
socket_error(C.setsockopt(s.handle, C.SOL_SOCKET, int(opt), &value, sizeof(bool))) ?
x := int(value)
socket_error(C.setsockopt(s.handle, C.SOL_SOCKET, int(opt), &x, sizeof(int))) ?
return none
}

View File

@ -211,7 +211,8 @@ pub fn (mut s UdpSocket) set_option_bool(opt SocketOption, value bool) ? {
// if opt !in opts_bool {
// return err_option_wrong_type
// }
socket_error(C.setsockopt(s.handle, C.SOL_SOCKET, int(opt), &value, sizeof(bool))) ?
x := int(value)
socket_error(C.setsockopt(s.handle, C.SOL_SOCKET, int(opt), &x, sizeof(int))) ?
return none
}

View File

@ -483,7 +483,7 @@ typedef struct sync__Channel* chan;
#ifndef __cplusplus
#ifndef bool
typedef int bool;
typedef byte bool;
#define true 1
#define false 0
#endif