Rename some stuff.
This commit is contained in:
parent
db6b9fcdc1
commit
6695101c48
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
project(rtcore C)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
|
||||||
|
function(compile_opts target)
|
||||||
|
target_compile_options(${target} PRIVATE
|
||||||
|
$<IF:$<C_COMPILER_ID:GNU>,
|
||||||
|
-Wall -Wextra -Wpedantic, # -Wno-unused-parameter,
|
||||||
|
>
|
||||||
|
$<IF:$<C_COMPILER_ID:MSVC>,
|
||||||
|
/W4,
|
||||||
|
>)
|
||||||
|
set_target_properties(${target} PROPERTIES COMPILE_WARNING_AS_ERROR ON)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
add_executable(rtcore_test rtcore_test.c rtcore.h)
|
||||||
|
compile_opts(rtcore_test)
|
||||||
@ -1,2 +1,4 @@
|
|||||||
-DRT_JSON_IMPLEMENTATION
|
-DRT_JSON_IMPLEMENTATION
|
||||||
-DRT_CORE_IMPLEMENTATION
|
-DRT_CORE_IMPLEMENTATION
|
||||||
|
-DRT_MPMC_IMPLEMENTATION
|
||||||
|
-std=c99
|
||||||
63
rtcore.h
63
rtcore.h
@ -88,14 +88,14 @@ typedef int32_t b32;
|
|||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#ifdef __has_builtin
|
#ifdef __has_builtin
|
||||||
#if __has_builtin(__builtin_expect)
|
#if __has_builtin(__builtin_expect)
|
||||||
#define likely(x) __builtin_expect(!!(x), 1)
|
#define Likely(x) __builtin_expect(!!(x), 1)
|
||||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
#define Unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef likely
|
#ifndef Likely
|
||||||
#define likely(x) (x)
|
#define Likely(x) (x)
|
||||||
#define unlikely(x) (x)
|
#define Unlikely(x) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define internal static
|
#define internal static
|
||||||
@ -107,20 +107,20 @@ typedef int32_t b32;
|
|||||||
#define exported __dllexport
|
#define exported __dllexport
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
#define Min(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define Max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
#define kilobytes(n) ((n) * 1024)
|
#define Kilobytes(n) ((n) * 1024)
|
||||||
#define megabytes(n) ((n) * 1024 * 1024)
|
#define Megabytes(n) ((n) * 1024 * 1024)
|
||||||
#define gigabytes(n) ((n) * 1024 * 1024 * 1024)
|
#define Gigabytes(n) ((n) * 1024 * 1024 * 1024)
|
||||||
|
|
||||||
#define isizeof(x) (isize)sizeof(x)
|
#define ISizeof(x) (isize)sizeof(x)
|
||||||
/* number of elements in array a */
|
/* number of elements in array a */
|
||||||
#define countof(a) (isize)(sizeof(a) / sizeof(*(a)))
|
#define CountOf(a) (isize)(sizeof(a) / sizeof(*(a)))
|
||||||
/* number of characters in string constant s (exluding the terminating 0) */
|
/* number of characters in string constant s (exluding the terminating 0) */
|
||||||
#define lengthof(s) (countof(s) - 1)
|
#define LengthOf(s) (CountOf(s) - 1)
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define assert(x) \
|
#define Assert(x) \
|
||||||
while (!(x)) \
|
while (!(x)) \
|
||||||
{ \
|
{ \
|
||||||
__builtin_trap(); \
|
__builtin_trap(); \
|
||||||
@ -129,7 +129,7 @@ typedef int32_t b32;
|
|||||||
|
|
||||||
#define force_inline inline __attribute__((always_inline))
|
#define force_inline inline __attribute__((always_inline))
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define assert(x) \
|
#define Assert(x) \
|
||||||
if (!(x)) \
|
if (!(x)) \
|
||||||
{ \
|
{ \
|
||||||
__debugbreak(); \
|
__debugbreak(); \
|
||||||
@ -137,20 +137,20 @@ typedef int32_t b32;
|
|||||||
|
|
||||||
#define force_inline __forceinline
|
#define force_inline __forceinline
|
||||||
#else
|
#else
|
||||||
#define assert(x)
|
#define Assert(x)
|
||||||
#define force_inline inline
|
#define force_inline inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __STDC_VERSION__ >= 201112L
|
#if __STDC_VERSION__ >= 201112L
|
||||||
/* C11 introduces _Alignof */
|
/* C11 introduces _Alignof */
|
||||||
#define ALIGNOF(T) _Alignof(T)
|
#define AlignOf(T) _Alignof(T)
|
||||||
#else
|
#else
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
/* Use the compiler-specific keyword/operator */
|
/* Use the compiler-specific keyword/operator */
|
||||||
#define ALIGNOF(T) __alignof__(T)
|
#define AlignOf(T) __alignof__(T)
|
||||||
#else
|
#else
|
||||||
/* Fallback to the portable C89/C99 trick */
|
/* Fallback to the portable C89/C99 trick */
|
||||||
#define ALIGNOF(T) offsetof(struct { char c; T member; }, member)
|
#define AlignOf(T) offsetof(struct { char c; T member; }, member)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -200,17 +200,10 @@ enum
|
|||||||
ALLOC_SOFTFAIL = 0x2,
|
ALLOC_SOFTFAIL = 0x2,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* allocate objects from an arena.
|
#define Alloc(_arena, _t) (_t *)ArenaAlloc(_arena, ISizeof(_t), AlignOf(_t), 1, 0)
|
||||||
* usage is one of:
|
#define AllocFlags(_arena, _t, _flags) (_t *)ArenaAlloc(_arena, ISizeof(_t), AlignOf(_t), 1, (_flags))
|
||||||
* - a(a, t) - allocate one object of type t from arena a
|
#define AllocArray(_arena, _t, _n) (_t *)ArenaAlloc(_arena, ISizeof(_t), AlignOf(_t), (_n), 0)
|
||||||
* - alloc(a, t, n) - allocate n objects of type t from arena a
|
#define AllocArrayFlags(_arena, _t, _n, _flags) (_t *)ArenaAlloc(_arena, ISizeof(_t), AlignOf(_t), (_n), (_flags))
|
||||||
* - (a, t, n, f) - allocate n objects of type t from arena a using flags f
|
|
||||||
*/
|
|
||||||
#define alloc(...) allocx(__VA_ARGS__, alloc4, alloc3, alloc2)(__VA_ARGS__)
|
|
||||||
#define allocx(a, b, c, d, e, ...) e
|
|
||||||
#define alloc2(a, t) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), 1, 0)
|
|
||||||
#define alloc3(a, t, n) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), n, 0)
|
|
||||||
#define alloc4(a, t, n, f) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), n, f)
|
|
||||||
|
|
||||||
RTC_API void *ArenaAlloc(arena *a, isize size, isize align, isize n, int flags);
|
RTC_API void *ArenaAlloc(arena *a, isize size, isize align, isize n, int flags);
|
||||||
|
|
||||||
@ -224,7 +217,7 @@ typedef struct s8
|
|||||||
isize length;
|
isize length;
|
||||||
} s8;
|
} s8;
|
||||||
#define S8(_s) \
|
#define S8(_s) \
|
||||||
(s8) { .data = (u8 *)_s, .length = lengthof(_s), }
|
(s8) { .data = (u8 *)_s, .length = LengthOf(_s), }
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -515,7 +508,7 @@ S8Equals(s8 a, s8 b)
|
|||||||
RTC_API isize
|
RTC_API isize
|
||||||
S8Compare(s8 a, s8 b)
|
S8Compare(s8 a, s8 b)
|
||||||
{
|
{
|
||||||
isize n = min(a.length, b.length);
|
isize n = Min(a.length, b.length);
|
||||||
for (isize i = 0; i < n; ++i)
|
for (isize i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
if (a.data[i] != b.data[i])
|
if (a.data[i] != b.data[i])
|
||||||
@ -603,7 +596,7 @@ RTC_API s8
|
|||||||
S8Clone(s8 s, arena *a)
|
S8Clone(s8 s, arena *a)
|
||||||
{
|
{
|
||||||
s8 c = {0};
|
s8 c = {0};
|
||||||
c.data = alloc(a, u8, s.length);
|
c.data = AllocArray(a, u8, s.length);
|
||||||
c.length = s.length;
|
c.length = s.length;
|
||||||
memcpy(c.data, s.data, s.length);
|
memcpy(c.data, s.data, s.length);
|
||||||
return s;
|
return s;
|
||||||
@ -708,7 +701,7 @@ RTC_API file_buffer
|
|||||||
ReadEntireFile(s8 path, arena *a)
|
ReadEntireFile(s8 path, arena *a)
|
||||||
{
|
{
|
||||||
char _p[260];
|
char _p[260];
|
||||||
if (path.length >= countof(_p))
|
if (path.length >= CountOf(_p))
|
||||||
return (file_buffer){0};
|
return (file_buffer){0};
|
||||||
memcpy(_p, path.data, path.length);
|
memcpy(_p, path.data, path.length);
|
||||||
_p[path.length] = '\0';
|
_p[path.length] = '\0';
|
||||||
@ -743,7 +736,7 @@ RTC_API b32
|
|||||||
WriteEntireFile(s8 path, byte *data, isize length)
|
WriteEntireFile(s8 path, byte *data, isize length)
|
||||||
{
|
{
|
||||||
char _p[260];
|
char _p[260];
|
||||||
if (path.length >= countof(_p))
|
if (path.length >= CountOf(_p))
|
||||||
return 0;
|
return 0;
|
||||||
memcpy(_p, path.data, path.length);
|
memcpy(_p, path.data, path.length);
|
||||||
_p[path.length] = '\0';
|
_p[path.length] = '\0';
|
||||||
|
|||||||
@ -20,13 +20,13 @@ internal int
|
|||||||
AllocTest(void)
|
AllocTest(void)
|
||||||
{
|
{
|
||||||
char space[260];
|
char space[260];
|
||||||
arena a = {.begin = space, .end = space + countof(space) };
|
arena a = {.begin = space, .end = space + CountOf(space) };
|
||||||
|
|
||||||
int *t = alloc(&a, int);
|
int *t = Alloc(&a, int);
|
||||||
if (!t)
|
if (!t)
|
||||||
return 0;
|
return 0;
|
||||||
*t = 42;
|
*t = 42;
|
||||||
int *t2 = alloc(&a, int);
|
int *t2 = Alloc(&a, int);
|
||||||
if (t == t2)
|
if (t == t2)
|
||||||
return 0;
|
return 0;
|
||||||
*t2 = *t;
|
*t2 = *t;
|
||||||
@ -38,7 +38,7 @@ internal int
|
|||||||
ReadFileTest(void)
|
ReadFileTest(void)
|
||||||
{
|
{
|
||||||
char space[260];
|
char space[260];
|
||||||
arena a = {.begin = space, .end = space + countof(space) };
|
arena a = {.begin = space, .end = space + CountOf(space) };
|
||||||
s8 data = ReadEntireFileS8(S8("somedata.txt"), &a);
|
s8 data = ReadEntireFileS8(S8("somedata.txt"), &a);
|
||||||
return S8Equals(data, S8("1234567890\n"));
|
return S8Equals(data, S8("1234567890\n"));
|
||||||
}
|
}
|
||||||
10
rtjson.h
10
rtjson.h
@ -190,7 +190,7 @@ ParseString(s8 text, isize *_at, isize *current_line, s8 file, arena *a)
|
|||||||
printf("%zu: unexpected end of file\n", *current_line);
|
printf("%zu: unexpected end of file\n", *current_line);
|
||||||
return (s8){0};
|
return (s8){0};
|
||||||
}
|
}
|
||||||
u8 *mem = alloc(a, u8, total_length);
|
u8 *mem = AllocArray(a, u8, total_length);
|
||||||
if (at > first_char)
|
if (at > first_char)
|
||||||
memcpy(mem, str.data, at - first_char);
|
memcpy(mem, str.data, at - first_char);
|
||||||
str.data = mem;
|
str.data = mem;
|
||||||
@ -339,7 +339,7 @@ ParseValue(s8 text, isize *_at, isize *current_line, s8 file, arena *a)
|
|||||||
}
|
}
|
||||||
else if (text.data[at] == '\"')
|
else if (text.data[at] == '\"')
|
||||||
{
|
{
|
||||||
child = alloc(a, json);
|
child = Alloc(a, json);
|
||||||
child->value.s = ParseString(text, &at, current_line, file, a);
|
child->value.s = ParseString(text, &at, current_line, file, a);
|
||||||
if (!child->value.s.data)
|
if (!child->value.s.data)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -353,7 +353,7 @@ ParseValue(s8 text, isize *_at, isize *current_line, s8 file, arena *a)
|
|||||||
parse_number_result res = ParseNumber(text, &at, current_line, file, &i, &f);
|
parse_number_result res = ParseNumber(text, &at, current_line, file, &i, &f);
|
||||||
if (res == NOT_A_NUMBER)
|
if (res == NOT_A_NUMBER)
|
||||||
return NULL;
|
return NULL;
|
||||||
child = alloc(a, json);
|
child = Alloc(a, json);
|
||||||
if (res == INT)
|
if (res == INT)
|
||||||
{
|
{
|
||||||
child->value.i = i;
|
child->value.i = i;
|
||||||
@ -379,7 +379,7 @@ ParseValue(s8 text, isize *_at, isize *current_line, s8 file, arena *a)
|
|||||||
++at;
|
++at;
|
||||||
++value_str.length;
|
++value_str.length;
|
||||||
}
|
}
|
||||||
child = alloc(a, json);
|
child = Alloc(a, json);
|
||||||
if (S8Equals(value_str, true_str))
|
if (S8Equals(value_str, true_str))
|
||||||
{
|
{
|
||||||
child->value.b = 1;
|
child->value.b = 1;
|
||||||
@ -412,7 +412,7 @@ ParseJSONImpl(s8 text, isize *_at, isize *current_line, s8 file, arena *a)
|
|||||||
{
|
{
|
||||||
isize at = *_at;
|
isize at = *_at;
|
||||||
|
|
||||||
json *j = alloc(a, json);
|
json *j = Alloc(a, json);
|
||||||
|
|
||||||
if (text.data[at] == '{')
|
if (text.data[at] == '{')
|
||||||
{
|
{
|
||||||
|
|||||||
2
rtmpmc.h
2
rtmpmc.h
@ -89,7 +89,7 @@ NewMPMCQueue(u32 capacity, arena *a)
|
|||||||
mpmc_queue q = {0};
|
mpmc_queue q = {0};
|
||||||
q.capacity = capacity;
|
q.capacity = capacity;
|
||||||
q.mod = capacity - 1;
|
q.mod = capacity - 1;
|
||||||
q.slots = alloc(a, mpmc_slot, capacity + 1);
|
q.slots = AllocArray(a, mpmc_slot, capacity + 1);
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user