Skip to content

Commit

Permalink
Fix parse_int on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Sep 18, 2024
1 parent 74648bb commit 25c0ca7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions sources/iron.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,13 @@ f32 math_acos(f32 x) { return acosf(x); }
f32 math_exp(f32 x) { return expf(x); }
f32 math_fmod(f32 x, f32 y) { return fmod(x, y); }

#ifdef _WIN32
i32 parse_int(const char *s) { return _strtoi64(s, NULL, 10); }
i32 parse_int_hex(const char *s) { return _strtoi64(s, NULL, 16); }
#else
i32 parse_int(const char *s) { return strtol(s, NULL, 10); }
i32 parse_int_hex(const char *s) { return strtol(s, NULL, 16); }
#endif
f32 parse_float(const char *s) { return strtof(s, NULL); }

i32 color_from_floats(f32 r, f32 g, f32 b, f32 a) {
Expand Down
7 changes: 7 additions & 0 deletions sources/iron_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ static void store_u8(uint8_t u8) {
}

static void store_i32(int32_t i32) {
// TODO: signed overflow is UB
// if (i32 > INT32_MAX)
// i32 = (int32_t)(i32 - INT32_MAX - 1) - INT32_MAX - 1;
wi += pad(wi, 4);
*(int32_t *)(decoded + wi) = i32;
wi += 4;
Expand Down Expand Up @@ -149,7 +152,11 @@ static void token_write() {
else {
has_dot(source + t.start, t.end - t.start) ?
store_f32(strtof(source + t.start, NULL)) :
#ifdef _WIN32
store_i32(_strtoi64(source + t.start, NULL, 10));
#else
store_i32(strtol(source + t.start, NULL, 10));
#endif
}
}
else if (t.type == JSMN_ARRAY) {
Expand Down
4 changes: 4 additions & 0 deletions sources/iron_ui_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ int ui_color_wheel(ui_handle_t *handle, bool alpha, float w, float h, bool color
hex_code[0] = 'f';
hex_code[1] = 'f';
}
#ifdef _WIN32
handle->color = _strtoi64(hex_code, NULL, 16);
#else
handle->color = strtol(hex_code, NULL, 16);
#endif
}
if (h0->changed || h1->changed || h2->changed) {
handle->changed = current->changed = true;
Expand Down
8 changes: 4 additions & 4 deletions sources/ts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ declare type ui_options_t = {
};

declare type ui_coloring_t = {
color?: i32;
color?: u32;
start?: string[];
end?: string;
separated?: bool;
};

declare type ui_text_coloring_t = {
colorings?: ui_coloring_t[];
default_color?: i32;
default_color?: u32;
};

declare type ui_canvas_control_t = {
Expand All @@ -384,7 +384,7 @@ declare type ui_node_t = {
type?: string;
x?: f32;
y?: f32;
color?: i32;
color?: u32;
inputs?: ui_node_socket_t[];
outputs?: ui_node_socket_t[];
buttons?: ui_node_button_t[];
Expand All @@ -396,7 +396,7 @@ declare type ui_node_socket_t = {
node_id?: i32;
name?: string;
type?: string;
color?: i32;
color?: u32;
default_value?: f32_array_t;
min?: f32;
max?: f32;
Expand Down
5 changes: 5 additions & 0 deletions tools/amake/iron.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ f32 math_acos(f32 x) { return acosf(x); }
f32 math_exp(f32 x) { return expf(x); }
f32 math_fmod(f32 x, f32 y) { return fmod(x, y); }

#ifdef _WIN32
i32 parse_int(const char *s) { return _strtoi64(s, NULL, 10); }
i32 parse_int_hex(const char *s) { return _strtoi64(s, NULL, 16); }
#else
i32 parse_int(const char *s) { return strtol(s, NULL, 10); }
i32 parse_int_hex(const char *s) { return strtol(s, NULL, 16); }
#endif
f32 parse_float(const char *s) { return strtof(s, NULL); }

0 comments on commit 25c0ca7

Please sign in to comment.