fix read-only macro in debug mode

This commit is contained in:
jacob 2024-04-12 16:10:25 -05:00
parent f399c093ca
commit 77fd98baaa
6 changed files with 36 additions and 27 deletions

View File

@ -162,9 +162,14 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define INTERNAL static #define INTERNAL static
#define GLOBAL static #define GLOBAL static
/* Storage specifiers */ /* Read-only */
#pragma section(".roglob", read) #if OS_WINDOWS
#define READONLY __declspec(allocate(".roglob")) # define READONLY __declspec(allocate(".rdata"))
#elif OS_MAC
#define READONLY __attribute((section("__TEXT,__const")))
#else
#define READONLY __attribute((section(".rodata")))
#endif
/* Markup */ /* Markup */
#define UNUSED void #define UNUSED void

View File

@ -1,6 +1,7 @@
#include "entity.h" #include "entity.h"
#include "math.h" #include "math.h"
/* Accessed via entity_nil() */
READONLY struct entity _g_entity_nil = { READONLY struct entity _g_entity_nil = {
.rel_xform = XFORM_IDENT, .rel_xform = XFORM_IDENT,
.world_xform = XFORM_IDENT, .world_xform = XFORM_IDENT,

View File

@ -116,8 +116,11 @@ struct entity_prop_array {
* Nil * Nil
* ========================== */ * ========================== */
extern READONLY struct entity _g_entity_nil; INLINE struct entity *entity_nil(void)
INLINE READONLY struct entity *entity_nil(void) { return &_g_entity_nil; } {
extern READONLY struct entity _g_entity_nil;
return &_g_entity_nil;
}
/* ========================== * /* ========================== *
* Property helpers * Property helpers

View File

@ -22,7 +22,7 @@ GLOBAL struct {
b32 file_valid; b32 file_valid;
} G = { 0 }, DEBUG_ALIAS(G, G_log); } G = { 0 }, DEBUG_ALIAS(G, G_log);
GLOBAL READONLY const struct log_level_settings g_log_level_settings[LOG_LEVEL_COUNT] = { GLOBAL READONLY struct log_level_settings g_log_level_settings[LOG_LEVEL_COUNT] = {
[LOG_LEVEL_CRITICAL] = { [LOG_LEVEL_CRITICAL] = {
STR_NOCAST("CRITICAL"), STR_NOCAST("CRITICAL"),
0xFFFF00FF 0xFFFF00FF

View File

@ -133,8 +133,8 @@ INLINE u64 math_pow_u64(u64 base, u8 exp) {
* https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/e_logf.c */ * https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/e_logf.c */
INLINE f32 math_ln(f32 x) INLINE f32 math_ln(f32 x)
{ {
static const f32 ln2_hi = 6.9313812256e-01; LOCAL_PERSIST const f32 ln2_hi = 6.9313812256e-01;
static const f32 ln2_lo = 9.0580006145e-06; LOCAL_PERSIST const f32 ln2_lo = 9.0580006145e-06;
i32 x_int = *(u32 *)&x; i32 x_int = *(u32 *)&x;
@ -202,14 +202,14 @@ INLINE f32 math_ln(f32 x)
* https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/e_expf.c */ * https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/e_expf.c */
INLINE f32 math_exp(f32 x) INLINE f32 math_exp(f32 x)
{ {
static const f32 half[2] = { 0.5, -0.5 }; LOCAL_PERSIST const f32 half[2] = { 0.5, -0.5 };
static const f32 o_threshold = 8.8721679688e+01; LOCAL_PERSIST const f32 o_threshold = 8.8721679688e+01;
static const f32 u_threshold = -1.0397208405e+02; LOCAL_PERSIST const f32 u_threshold = -1.0397208405e+02;
static const f32 ln2_hi[2] = { 6.9314575195e-01, -6.9314575195e-01 }; LOCAL_PERSIST const f32 ln2_hi[2] = { 6.9314575195e-01, -6.9314575195e-01 };
static const f32 ln2_lo[2] = { 1.4286067653e-06, -1.4286067653e-06 }; LOCAL_PERSIST const f32 ln2_lo[2] = { 1.4286067653e-06, -1.4286067653e-06 };
static const f32 inv_ln2 = 1.4426950216e+00; LOCAL_PERSIST const f32 inv_ln2 = 1.4426950216e+00;
static const f32 huge = 1.0e+30; LOCAL_PERSIST const f32 huge = 1.0e+30;
static const f32 two_m100 = 7.8886090522e-31; LOCAL_PERSIST const f32 two_m100 = 7.8886090522e-31;
u32 x_uint = *(u32 *)&x; u32 x_uint = *(u32 *)&x;
i32 x_sign_bit = (x_uint >> 31) & 1; i32 x_sign_bit = (x_uint >> 31) & 1;

View File

@ -4,17 +4,17 @@
* utf8 * utf8
* ========================== */ * ========================== */
GLOBAL READONLY u8 g_utf8_lens[32] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5
};
struct uni_decode_utf8_result uni_decode_utf8(struct string str) struct uni_decode_utf8_result uni_decode_utf8(struct string str)
{ {
LOCAL_PERSIST const u8 lengths[32] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5
};
u32 codepoint = U32_MAX; u32 codepoint = U32_MAX;
u32 advance = 0; u32 advance = 0;
if (str.len > 0) { if (str.len > 0) {
u8 c0 = str.text[0]; u8 c0 = str.text[0];
u8 utf8_len = g_utf8_lens[c0 >> 3]; u8 utf8_len = lengths[c0 >> 3];
advance = 1; advance = 1;
switch (utf8_len) { switch (utf8_len) {
@ -25,7 +25,7 @@ struct uni_decode_utf8_result uni_decode_utf8(struct string str)
case 2: { case 2: {
if (str.len >= 2) { if (str.len >= 2) {
u8 c1 = str.text[1]; u8 c1 = str.text[1];
if (g_utf8_lens[c1 >> 3] == 0) { if (lengths[c1 >> 3] == 0) {
codepoint = (c1 & 0x3F) << 0; codepoint = (c1 & 0x3F) << 0;
codepoint |= (c0 & 0x1F) << 6; codepoint |= (c0 & 0x1F) << 6;
advance = 2; advance = 2;
@ -37,8 +37,8 @@ struct uni_decode_utf8_result uni_decode_utf8(struct string str)
if (str.len >= 3) { if (str.len >= 3) {
u8 c1 = str.text[1]; u8 c1 = str.text[1];
u8 c2 = str.text[2]; u8 c2 = str.text[2];
if (g_utf8_lens[c1 >> 3] == 0 && if (lengths[c1 >> 3] == 0 &&
g_utf8_lens[c2 >> 3] == 0) { lengths[c2 >> 3] == 0) {
codepoint = (c2 & 0x3F) << 0; codepoint = (c2 & 0x3F) << 0;
codepoint |= (c1 & 0x3F) << 6; codepoint |= (c1 & 0x3F) << 6;
codepoint |= (c0 & 0x0F) << 12; codepoint |= (c0 & 0x0F) << 12;
@ -52,9 +52,9 @@ struct uni_decode_utf8_result uni_decode_utf8(struct string str)
u8 c1 = str.text[1]; u8 c1 = str.text[1];
u8 c2 = str.text[2]; u8 c2 = str.text[2];
u8 c3 = str.text[3]; u8 c3 = str.text[3];
if (g_utf8_lens[c1 >> 3] == 0 && if (lengths[c1 >> 3] == 0 &&
g_utf8_lens[c2 >> 3] == 0 && lengths[c2 >> 3] == 0 &&
g_utf8_lens[c3 >> 3] == 0) { lengths[c3 >> 3] == 0) {
codepoint = (c3 & 0x3F) << 0; codepoint = (c3 & 0x3F) << 0;
codepoint |= (c2 & 0x3F) << 6; codepoint |= (c2 & 0x3F) << 6;
codepoint |= (c1 & 0x3F) << 12; codepoint |= (c1 & 0x3F) << 12;