mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: make bool
s take up a single byte, not 4 (#9352)
This commit is contained in:
parent
4ae2c22c18
commit
624c1f3bcf
@ -260,19 +260,19 @@ fn map_eq_string(a voidptr, b voidptr) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn map_eq_int_1(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 {
|
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 {
|
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 {
|
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) {
|
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) {
|
fn map_clone_int_1(dest voidptr, pkey voidptr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*&byte(dest) = *&byte(pkey)
|
C.memcpy(dest, pkey, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_clone_int_2(dest voidptr, pkey voidptr) {
|
fn map_clone_int_2(dest voidptr, pkey voidptr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*&u16(dest) = *&u16(pkey)
|
C.memcpy(dest, pkey, 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_clone_int_4(dest voidptr, pkey voidptr) {
|
fn map_clone_int_4(dest voidptr, pkey voidptr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*&u32(dest) = *&u32(pkey)
|
C.memcpy(dest, pkey, 4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_clone_int_8(dest voidptr, pkey voidptr) {
|
fn map_clone_int_8(dest voidptr, pkey voidptr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*&u64(dest) = *&u64(pkey)
|
C.memcpy(dest, pkey, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,8 @@ pub fn (mut s TcpSocket) set_option_bool(opt SocketOption, value bool) ? {
|
|||||||
// if opt !in opts_bool {
|
// if opt !in opts_bool {
|
||||||
// return err_option_wrong_type
|
// 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
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,8 @@ pub fn (mut s UdpSocket) set_option_bool(opt SocketOption, value bool) ? {
|
|||||||
// if opt !in opts_bool {
|
// if opt !in opts_bool {
|
||||||
// return err_option_wrong_type
|
// 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
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ typedef struct sync__Channel* chan;
|
|||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#ifndef bool
|
#ifndef bool
|
||||||
typedef int bool;
|
typedef byte bool;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user