Skip to content

Commit

Permalink
Use stdbool rather than custom booleans
Browse files Browse the repository at this point in the history
Fixes: #817
  • Loading branch information
saghul committed Jan 15, 2025
1 parent 8bcc070 commit a7914d1
Show file tree
Hide file tree
Showing 20 changed files with 1,470 additions and 1,482 deletions.
6 changes: 3 additions & 3 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int dbuf_realloc(DynBuf *s, size_t new_size)
new_size = size;
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
if (!new_buf) {
s->error = TRUE;
s->error = true;
return -1;
}
s->buf = new_buf;
Expand Down Expand Up @@ -1209,12 +1209,12 @@ typedef struct {
js__once_cb callback;
} js__once_data_t;

static BOOL WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
static int WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
js__once_data_t *data = param;

data->callback();

return TRUE;
return 1;
}

void js_once(js_once_t *guard, js__once_cb callback) {
Expand Down
22 changes: 7 additions & 15 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef CUTILS_H
#define CUTILS_H

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
Expand Down Expand Up @@ -112,15 +113,6 @@ extern "C" {
#define minimum_length(n) static n
#endif

typedef int BOOL;

#ifndef FALSE
enum {
FALSE = 0,
TRUE = 1,
};
#endif

void js__pstrcpy(char *buf, int buf_size, const char *str);
char *js__pstrcat(char *buf, int buf_size, const char *s);
int js__strstart(const char *str, const char *val, const char **ptr);
Expand Down Expand Up @@ -428,7 +420,7 @@ typedef struct DynBuf {
uint8_t *buf;
size_t size;
size_t allocated_size;
BOOL error; /* true if a memory allocation error occurred */
bool error; /* true if a memory allocation error occurred */
DynBufReallocFunc *realloc_func;
void *opaque; /* for realloc_func */
} DynBuf;
Expand Down Expand Up @@ -456,12 +448,12 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
FORMAT_STRING(const char *fmt), ...);
void dbuf_free(DynBuf *s);
static inline BOOL dbuf_error(DynBuf *s) {
static inline bool dbuf_error(DynBuf *s) {
return s->error;
}
static inline void dbuf_set_error(DynBuf *s)
{
s->error = TRUE;
s->error = true;
}

/*---- UTF-8 and UTF-16 handling ----*/
Expand All @@ -485,17 +477,17 @@ size_t utf8_decode_buf16(uint16_t *dest, size_t dest_len, const char *src, size_
size_t utf8_encode_buf8(char *dest, size_t dest_len, const uint8_t *src, size_t src_len);
size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_t src_len);

static inline BOOL is_surrogate(uint32_t c)
static inline bool is_surrogate(uint32_t c)
{
return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
}

static inline BOOL is_hi_surrogate(uint32_t c)
static inline bool is_hi_surrogate(uint32_t c)
{
return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
}

static inline BOOL is_lo_surrogate(uint32_t c)
static inline bool is_lo_surrogate(uint32_t c)
{
return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
}
Expand Down
4 changes: 2 additions & 2 deletions dirent_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ dirent_next(
} else if (dirp->handle != INVALID_HANDLE_VALUE) {

/* Get the next directory entry from stream */
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
if (FindNextFileW (dirp->handle, &dirp->data) != 0) {
/* Got a file */
p = &dirp->data;
} else {
Expand Down Expand Up @@ -1163,4 +1163,4 @@ dirent_set_errno(
#ifdef __cplusplus
}
#endif
#endif /*DIRENT_H*/
#endif /*DIRENT_H*/
4 changes: 2 additions & 2 deletions gen/function_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const uint8_t qjsc_function_source[320] = {
0x6e, 0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20,
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34,
0x32, 0x20, 0x7d, 0x0d, 0xc0, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x20, 0xfa, 0x01, 0xa2,
0x00, 0x00, 0x00, 0x0c, 0x20, 0x0a, 0x01, 0xa2,
0x01, 0x00, 0x05, 0x00, 0x03, 0x02, 0x01, 0x74,
0x05, 0xc2, 0x03, 0x02, 0x00, 0x30, 0xc4, 0x03,
0x04, 0x00, 0x70, 0xc2, 0x03, 0x04, 0x02, 0x70,
0x10, 0x00, 0x01, 0x00, 0xe4, 0x01, 0x00, 0x01,
0x00, 0xc6, 0x03, 0x00, 0x0d, 0xc4, 0x03, 0x01,
0x01, 0x0c, 0x43, 0xfa, 0x01, 0xc4, 0x03, 0x00,
0x01, 0x0c, 0x43, 0x0a, 0x01, 0xc4, 0x03, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbd,
0x2a, 0x28, 0xc0, 0x03, 0x03, 0x01, 0x00, 0x1a,
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
Expand Down
2 changes: 1 addition & 1 deletion gen/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const uint8_t qjsc_hello[103] = {
0x6c, 0x6f, 0x67, 0x01, 0x16, 0x48, 0x65, 0x6c,
0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64,
0x0d, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x20, 0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00,
0x0c, 0x20, 0x0a, 0x01, 0xa2, 0x01, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x19, 0x00, 0x08, 0xeb,
0x02, 0x29, 0x39, 0xe1, 0x00, 0x00, 0x00, 0x43,
0xe2, 0x00, 0x00, 0x00, 0x04, 0xe3, 0x00, 0x00,
Expand Down
6 changes: 3 additions & 3 deletions gen/hello_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const uint8_t qjsc_fib_module[290] = {
0x6a, 0x73, 0x01, 0x06, 0x66, 0x69, 0x62, 0x01,
0x02, 0x6e, 0x0d, 0xc0, 0x03, 0x00, 0x01, 0x00,
0x00, 0xc2, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x20,
0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x01,
0x0a, 0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x09, 0x00, 0xc2, 0x03, 0x00, 0x01,
0x0c, 0x43, 0xfa, 0x01, 0xc2, 0x03, 0x01, 0x00,
0x0c, 0x43, 0x0a, 0x01, 0xc2, 0x03, 0x01, 0x00,
0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xc4, 0x03,
0x00, 0x01, 0x00, 0xc2, 0x03, 0x00, 0x00, 0xd2,
0xb5, 0xa8, 0xeb, 0x03, 0xb5, 0x28, 0xd2, 0xb6,
Expand Down Expand Up @@ -59,7 +59,7 @@ const uint8_t qjsc_hello_module[187] = {
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x01, 0x10, 0x66,
0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d, 0x0d,
0xc0, 0x03, 0x01, 0xc2, 0x03, 0x00, 0x00, 0x01,
0x00, 0xc4, 0x03, 0x00, 0x00, 0x0c, 0x20, 0xfa,
0x00, 0xc4, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x0a,
0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
0x00, 0x32, 0x00, 0xc4, 0x03, 0x00, 0x0c, 0x08,
0xeb, 0x02, 0x29, 0x39, 0xe3, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion gen/test_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const uint8_t qjsc_test_fib[294] = {
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x01, 0x10, 0x66,
0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d, 0x0d,
0xc0, 0x03, 0x01, 0xc2, 0x03, 0x00, 0x00, 0x01,
0x00, 0xfc, 0x01, 0x00, 0x01, 0x0c, 0x20, 0xfa,
0x00, 0xfc, 0x01, 0x00, 0x01, 0x0c, 0x20, 0x0a,
0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x05, 0x03,
0x00, 0x73, 0x00, 0xc4, 0x03, 0x00, 0x0d, 0xc6,
0x03, 0x00, 0x0d, 0xc8, 0x03, 0x01, 0x0d, 0x08,
Expand Down
Loading

0 comments on commit a7914d1

Please sign in to comment.