Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_H
|
||||
#define CI2_H
|
||||
|
||||
#include "./platform/ci2_platform.h"
|
||||
|
||||
#include "./platform/error/ci2_exception.h"
|
||||
#include "./platform/mem/ci2_mem.h"
|
||||
#include "./platform/mem/ci2_arena.h"
|
||||
|
||||
#endif // ci2.h
|
||||
@@ -0,0 +1,126 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_ASSERT_H
|
||||
#define CI2_ASSERT_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Force Inline */
|
||||
#if defined(_MSC_VER) || defined(__INTEL__LLVM_COMPILER)
|
||||
#define CI2_INLINE __forceinline
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define CI2_INLINE __attribute__((always_inline)) inline
|
||||
#else
|
||||
#define CI2_INLINE inline
|
||||
#endif
|
||||
|
||||
/* Use __has_builtin if available (Clang and newer GCC). */
|
||||
#if defined(__has_builtin)
|
||||
/* Check builtins in preferred order */
|
||||
#if __has_builtin(__builtin_debugtrap)
|
||||
#define CI2_DEBUG_TRAP() __builtin_debugtrap()
|
||||
#elif __has_builtin(__builtin_trap)
|
||||
#define CI2_DEBUG_TRAP() __builtin_trap()
|
||||
#elif __has_builtin(__builtin_break)
|
||||
#define CI2_DEBUG_TRAP() __builtin_break()
|
||||
#endif
|
||||
#elif defined(_MSC_VER) || defined(__INTEL__LLVM_COMPILER)
|
||||
#define CI2_DEBUG_TRAP() __debugbreak()
|
||||
#else
|
||||
#define CI2_DEBUG_TRAP() (*(volatile int*)0 = 0)
|
||||
#endif
|
||||
|
||||
/* Static Asserts */
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||
/* C11 */
|
||||
#define CI2_STATIC_ASSERT(expr) _Static_assert((expr), #expr)
|
||||
#else
|
||||
/* Abuse a typedef of a negative-size array */
|
||||
#define CI2_STATIC_ASSERT(expr) typedef char _static_assert_[(expr) ? 1 : -1]
|
||||
#endif
|
||||
|
||||
/* Current __func__ */
|
||||
#if defined(__FUNC__)
|
||||
#define CI2_FUNC __FUNCTION__
|
||||
#else
|
||||
#define CI2_FUNC __func__
|
||||
#endif
|
||||
|
||||
/* Assert Fail */
|
||||
static CI2_INLINE void
|
||||
ci2_assert_fail(const char* expr,
|
||||
const char* msg, /* may be NULL */
|
||||
const char* file,
|
||||
int line,
|
||||
const char* func)
|
||||
{
|
||||
if (msg)
|
||||
fprintf(stderr,
|
||||
"\n[ASSERT FAILED]\n"
|
||||
" Expression : %s\n"
|
||||
" Message : %s\n"
|
||||
" Location : %s:%d\n"
|
||||
" Function : %s\n\n",
|
||||
expr,
|
||||
msg,
|
||||
file,
|
||||
line,
|
||||
func);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"\n[ASSERT FAILED]\n"
|
||||
" Expression : %s\n"
|
||||
" Location : %s:%d\n"
|
||||
" Function : %s\n\n",
|
||||
expr,
|
||||
file,
|
||||
line,
|
||||
func);
|
||||
|
||||
/* Flush so the message is visible before we halt */
|
||||
fflush(stderr);
|
||||
|
||||
CI2_DEBUG_TRAP();
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define CI2_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
ci2_assert_fail(#expr, NULL, __FILE__, __LINE__, CI2_FUNC); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CI2_ASSERT_MSG(expr, msg) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
ci2_assert_fail(#expr, (msg), __FILE__, __LINE__, CI2_FUNC); \
|
||||
} \
|
||||
} while (0)
|
||||
#else /* NDEBUG — strip all runtime checks */
|
||||
|
||||
#define ASSERT(expr) ((void)(expr))
|
||||
#define ASSERT_MSG(expr, msg) ((void)(expr))
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#endif // ci2_assert.h
|
||||
@@ -0,0 +1,49 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_BASE_H
|
||||
#define CI2_BASE_H
|
||||
|
||||
#include "ci2_assert.h"
|
||||
#include "ci2_compiler.h"
|
||||
#include "ci2_os.h"
|
||||
#include "ci2_thread.h"
|
||||
#include "ci2_win_env.h"
|
||||
|
||||
#include "ci2_macros.h"
|
||||
#include "ci2_syntax.h"
|
||||
|
||||
/* Here is where we abstract away the differnces between Operating Systems */
|
||||
#if defined CI2_UNIX
|
||||
#define CI2_INVALID_FD -1
|
||||
typedef int ci2_fd;
|
||||
typedef char ci2_sys_char;
|
||||
|
||||
#else // Windows:
|
||||
|
||||
#define CI2_INVALID_FD NULL
|
||||
typedef HANDLE ci2_fd;
|
||||
typedef wchar_t ci2_sys_char;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ci2_base.h
|
||||
@@ -0,0 +1,38 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_COMPILER_H
|
||||
#define CI2_COMPILER_H
|
||||
|
||||
#if defined(__INTEL_LLVM_COMPILER)
|
||||
#define CI2_INTEL_ICX
|
||||
#elif defined(__GNUC__) && !defined(__clang__)
|
||||
#define CI2_GCC
|
||||
#elif defined(__clang__)
|
||||
#define CI2_CLANG
|
||||
#elif define(_MSC_VER) && !defined(__clang__)
|
||||
#define CI2_MSVC
|
||||
#else
|
||||
#error "Compiler is unkown and unsupported."
|
||||
#endif
|
||||
|
||||
#endif // ci2_compiler.h
|
||||
@@ -0,0 +1,101 @@
|
||||
/* - | Copyright |
|
||||
-------------------------------------------------------------- Copyright (c)
|
||||
2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_MACROS_H
|
||||
#define CI2_MACROS_H
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
#define STR2(s) #s
|
||||
#define STR(s) STR2(s)
|
||||
|
||||
#define U8_MIN 0u
|
||||
#define U8_MAX 0xffu
|
||||
#define I8_MIN (-0x7f - 1)
|
||||
#define I8_MAX 0x7f
|
||||
|
||||
#define U16_MIN 0u
|
||||
#define U16_MAX 0xffffu
|
||||
#define I16_MIN (-0x7fff - 1)
|
||||
#define I16_MAX 0x7fff
|
||||
|
||||
#define U32_MIN 0u
|
||||
#define U32_MAX 0xffffffffu
|
||||
#define I32_MIN (-0x7fffffff - 1)
|
||||
#define I32_MAX 0x7fffffff
|
||||
|
||||
#define U64_MIN 0ull
|
||||
#define U64_MAX 0xffffffffffffffffull
|
||||
#define I64_MIN (-0x7fffffffffffffffll - 1)
|
||||
#define I64_MAX 0x7fffffffffffffffll
|
||||
|
||||
#define F32_MIN 1.17549435e-38f
|
||||
#define F32_MAX 3.40282347e+38f
|
||||
|
||||
#define F64_MIN 2.2250738585072014e-308
|
||||
#define F64_MAX 1.7976931348623157e+308
|
||||
|
||||
#define PI 3.14159265
|
||||
#define RAD2DEG(x) ((x) / PI * 180)
|
||||
#define DEG2RAD(x) ((x) * PI / 180)
|
||||
#define ALIGNB(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
||||
#define ALIGN(x, align) ((((x) + ((align) - 1)) / (align)) * (align))
|
||||
#define FLOORB(x, align) ((x) & ~((align) - 1))
|
||||
#define FLOOR(x, align) (((x) / (align)) * (align))
|
||||
#define CEILB(x, align) ALIGNB(x, align)
|
||||
#define CEIL(x, align) ALIGN(x, align)
|
||||
#define CLIP(x, min, max) \
|
||||
(((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))
|
||||
#define UCLIP(x, max) (((x) > (max)) ? (max) : (x))
|
||||
#define LCLIP(x, min) (((x) < (min)) ? (min) : (x))
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#define ABS(x) (((x) < 0) ? -(x) : (x))
|
||||
#define DIFF(a, b) ABS((a) - (b))
|
||||
#define IS_NAN(x) ((x) != (x))
|
||||
#define IMPLIES(x, y) (!(x) || (y))
|
||||
#define COMPARE(x, y) (((x) > (y)) - ((x) < (y)))
|
||||
#define SIGN(x) COMPARE(x, 0)
|
||||
#define IS_ODD(num) ((num) & 1)
|
||||
#define IS_EVEN(num) (!IS_ODD((num)))
|
||||
#define IS_BETWEEN(n, L, H) ((unsigned char)((n) >= (L) && (n) <= (H)))
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define SET(d, n, v) \
|
||||
do { \
|
||||
size_t i_, n_; \
|
||||
for (n_ = (n), i_ = 0; n_ > 0; --n_, ++i_) \
|
||||
(d)[i_] = (v); \
|
||||
} while (0)
|
||||
#define ZERO(d, n) SET(d, n, 0)
|
||||
#define SWAP(a, b) \
|
||||
do { \
|
||||
a ^= b; \
|
||||
b ^= a; \
|
||||
a ^= b; \
|
||||
} while (0)
|
||||
#define SORT(a, b) \
|
||||
do { \
|
||||
if ((a) > (b)) \
|
||||
SWAP((a), (b)); \
|
||||
} while (0)
|
||||
#endif // ci2_macros.h
|
||||
@@ -0,0 +1,81 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_OS_H
|
||||
#define CI2_OS_H
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
/* Entire windows platform */
|
||||
#define CI2_WIN_APIVER 0x0600 // Vista
|
||||
#define NOMINMAX // Don't define min/max macros
|
||||
#define _CRT_SECURE_NO_WARNINGS // No unsafe C warnings
|
||||
#define _CRT_RAND_S // TODO
|
||||
#define OEMRESOURCE // GUI must be before windows.h
|
||||
#include <windows.h> // haha
|
||||
#define CI2_WINDOWS
|
||||
|
||||
#ifdef _WIN64
|
||||
/* Windows (64-bit only) */
|
||||
#define CI2_WINDOWS_64
|
||||
#else
|
||||
/* Windows (32-bit only) */
|
||||
#define CI2_WINDOWS_32
|
||||
#endif
|
||||
|
||||
#elif __APPLE__
|
||||
#define CI2_UNIX
|
||||
#define CI2_APPLE
|
||||
#include <TargetConditionals.h>
|
||||
#if TARGET_IPHONE_SIMULATOR
|
||||
// iOS, tvOS, or watchOS Simulator
|
||||
#define CI2_IOS
|
||||
#elif TARGET_OS_MACCATALYST
|
||||
// Mac's Catalyst (ports iOS API into Mac, like UIKit).
|
||||
#define CI2_IOS
|
||||
#elif TARGET_OS_IPHONE
|
||||
// iOS, tvOS, or watchOS device
|
||||
#define CI2_IOS
|
||||
#elif TARGET_OS_MAC
|
||||
// Other kinds of Apple platforms
|
||||
#define CI2_OSX
|
||||
#else
|
||||
#error "Unknown Apple platform"
|
||||
#endif
|
||||
|
||||
#elif __ANDROID__
|
||||
#define CI2_UNIX
|
||||
#define CI2_ANDROID
|
||||
|
||||
#elif __linux__
|
||||
#define CI2_UNIX
|
||||
|
||||
#elif __unix__ // TODO BSD Variants
|
||||
#define CI2_UNIX
|
||||
|
||||
#elif defined(_POSIX_VERSION)
|
||||
#define CI2_POSIX
|
||||
|
||||
#else
|
||||
#error "Unknown and unsupported operating system."
|
||||
#endif
|
||||
|
||||
#endif // ci2_os.h
|
||||
@@ -0,0 +1,68 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_SYNTAX_H
|
||||
#define CI2_SYNTAX_H
|
||||
|
||||
/* Floating Points */
|
||||
typedef float ci2_f32; // IEEE 754
|
||||
typedef double ci2_f64; // IEE 754
|
||||
|
||||
/* Characters */
|
||||
typedef signed char ci2_char; // [−127, +127]
|
||||
typedef unsigned char ci2_uchar; // [0, 255]
|
||||
typedef unsigned char ci2_byte; // [0, 255]
|
||||
typedef unsigned char* ci2_bytes; // Pointer
|
||||
|
||||
/* Integers */
|
||||
typedef signed short ci2_short; // [−32,767, 32,767]
|
||||
typedef unsigned short ci2_ushort; // [0, 65,535]
|
||||
typedef signed int ci2_int; // [−32,767, 32,767]
|
||||
typedef unsigned int ci2_uint; // [0, 65,535]
|
||||
typedef signed long int ci2_long; // [−2,147,483,647, 2,147,483,647]
|
||||
typedef unsigned long int ci2_ulong; // [0, 4,294,967,295]
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
// −9223372036854775807
|
||||
typedef unsigned long long int ci2_ull; // +9223372036854775807 range.
|
||||
typedef signed long long int ci2_ll; //[0, 18446744073709551615] range.
|
||||
|
||||
typedef int8_t i8;
|
||||
typedef int16_t i16;
|
||||
typedef int32_t i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef uintptr_t uptr;
|
||||
typedef ptrdiff_t size;
|
||||
typedef size_t usize;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ci2_syntax.h
|
||||
@@ -0,0 +1,37 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_THREAD_H
|
||||
#define CI2_THREAD_H
|
||||
|
||||
#if !defined(ci2_thread_local)
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
#define ci2_thread_local __declspec(thread)
|
||||
#elif defined(__GNUC__)
|
||||
#define ci2_thread_local __thread
|
||||
#else
|
||||
#define ci2_thread_local thread_local
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ci2_thread.h
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_WIN_ENV_H
|
||||
#define CI2_WIN_ENV_H
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#if defined __MINGW32__ || defined __MINGW64__
|
||||
#define CI2_WIN_ENV
|
||||
#define CI2_MINGW
|
||||
#elif defined __CYGWIN__
|
||||
#define CI2_WIN_ENV
|
||||
#define CI2_CYGWIN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ci2_win_env.h
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_PLATFORM_H
|
||||
#define CI2_PLATFORM_H
|
||||
|
||||
#include "./base/ci2_base.h"
|
||||
|
||||
/* No name mangling for declarations---------------------------------------- */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* CI2_EXTERN: plain extern with C++ aware linkage token for macros if needed */
|
||||
#if defined(__cplusplus)
|
||||
#define CI2_EXTERN extern "C"
|
||||
#else
|
||||
#define CI2_EXTERN extern
|
||||
#endif
|
||||
|
||||
/* CI2_API: platform/compiler-aware import/export/visibility */
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#if defined(CI2_BUILD_DLL)
|
||||
#define CI2_API CI2_EXTERN __declspec(dllexport)
|
||||
#elif defined(CI2_USE_DLL)
|
||||
#define CI2_API CI2_EXTERN __declspec(dllimport)
|
||||
#else
|
||||
#define CI2_API CI2_EXTERN
|
||||
#endif
|
||||
#else
|
||||
/* Non-Windows: use visibility if supported */
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_LLVM_COMPILER)
|
||||
#if defined(CI2_BUILD_DLL)
|
||||
#define CI2_API CI2_EXTERN __attribute__((visibility("default")))
|
||||
#else
|
||||
#define CI2_API CI2_EXTERN
|
||||
#endif
|
||||
#else
|
||||
#define CI2_API CI2_EXTERN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* CI2_DEF: internal vs external linkage */
|
||||
#ifndef CI2_DEF
|
||||
#ifdef CI2_STATIC
|
||||
#define CI2_DEF static
|
||||
#else
|
||||
#define CI2_DEF CI2_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CI2_SUCCESS 0
|
||||
#define CI2_FAILURE -1
|
||||
|
||||
#define CI2_TRUE 1
|
||||
#define CI2_FALSE 0
|
||||
|
||||
#define CI2_SIZE(x) (ptrdiff_t)sizeof(x)
|
||||
#define CI2_COUNT(a) (sizeof(a) / sizeof(*(a)))
|
||||
#define CI2_LEN(s) (countof(s) - 1)
|
||||
#define CI2_KB(x) ((x) * (size_t)(1024))
|
||||
#define CI2_MB(x) (CI2_KB(x) * (size_t)(1024))
|
||||
#define CI2_GB(x) (CI2_MB(x) * (size_t)(1024))
|
||||
#define CI2_TB(x) (CI2_GB(x) * (size_t)(1024))
|
||||
|
||||
CI2_API ci2_thread_local int ci2_errno;
|
||||
CI2_API int* ci2_errno_location(void);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // c++
|
||||
|
||||
#endif // ci2_platform.h
|
||||
@@ -0,0 +1,188 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_EXCEPTION_H
|
||||
#define CI2_EXCEPTION_H
|
||||
|
||||
#include "../ci2_platform.h"
|
||||
#include <setjmp.h>
|
||||
|
||||
struct Exception
|
||||
{
|
||||
const char* msg;
|
||||
};
|
||||
typedef struct Exception Exception;
|
||||
|
||||
struct Exception_Frame
|
||||
{
|
||||
struct Exception_Frame* prev;
|
||||
jmp_buf env;
|
||||
const char* file;
|
||||
const char* func;
|
||||
int line;
|
||||
const struct Exception* exception;
|
||||
};
|
||||
typedef struct Exception_Frame Exception_Frame;
|
||||
|
||||
enum
|
||||
{
|
||||
EXCEPTION_ENTERED = 0,
|
||||
EXCEPTION_RAISED,
|
||||
EXCEPTION_HANDLED,
|
||||
EXCEPTION_FINALIZED
|
||||
};
|
||||
|
||||
CI2_API const struct Exception assertion_failed;
|
||||
CI2_API void
|
||||
ci2_try_assert(int cond);
|
||||
|
||||
CI2_API void
|
||||
ci2_raise_exception(const struct Exception* e,
|
||||
const char* file,
|
||||
const char* func,
|
||||
int line);
|
||||
|
||||
#if defined(CI2_WINDOWS)
|
||||
CI2_DEF DWORD exception_stack;
|
||||
CI2_DEF void
|
||||
ci2_exception_init(void);
|
||||
CI2_DEF void
|
||||
ci2_exception_push(struct Exception_Frame* fp);
|
||||
CI2_DEF void
|
||||
ci2_exception_pop(void);
|
||||
|
||||
#define CI2_RAISE(e) ci2_raise_exception(&(e), __FILE__, CI2_FUNC, __LINE__)
|
||||
|
||||
#define CI2_RERAISE \
|
||||
ci2_raise_exception(exception_frame.exception, \
|
||||
exception_frame.file, \
|
||||
exception_frame.func, \
|
||||
exception_frame.line)
|
||||
|
||||
#define CI2_RETURN \
|
||||
switch (ci2_exception_pop(), 0) \
|
||||
default: \
|
||||
return
|
||||
|
||||
#define CI2_TRY \
|
||||
do { \
|
||||
volatile int exception_flag; \
|
||||
Exception_Frame exception_frame; \
|
||||
if (exception_stack == TLS_OUT_OF_INDEXES) \
|
||||
ci2_exception_init(); \
|
||||
ci2_exception_push(&exception_frame); \
|
||||
exception_flag = setjmp(exception_frame.env); \
|
||||
if (exception_flag == EXCEPTION_ENTERED) {
|
||||
|
||||
#define CI2_EXCEPT(e) \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
ci2_exception_pop(); \
|
||||
} \
|
||||
else if (exception_frame.exception == &(e)) \
|
||||
{ \
|
||||
exception_flag = EXCEPTION_HANDLED;
|
||||
|
||||
#define CI2_ELSE \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
ci2_exception_pop(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
exception_flag = EXCEPTION_HANDLED;
|
||||
|
||||
#define CI2_FINALLY \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
ci2_exception_pop(); \
|
||||
} \
|
||||
{ \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_flag = EXCEPTION_FINALIZED;
|
||||
|
||||
#define CI2_END_TRY \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
ci2_exception_pop(); \
|
||||
} \
|
||||
if (exception_flag == EXCEPTION_RAISED) \
|
||||
CI2_RERAISE; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#else // UNIX
|
||||
CI2_DEF struct Exception_Frame* exception_stack;
|
||||
|
||||
#define CI2_RAISE(e) ci2_raise_exception(&(e), __FILE__, CI2_FUNC, __LINE__)
|
||||
|
||||
#define CI2_RERAISE \
|
||||
ci2_raise_exception(exception_frame.exception, \
|
||||
exception_frame.file, \
|
||||
exception_frame.func, \
|
||||
exception_frame.line)
|
||||
|
||||
#define CI2_RETURN \
|
||||
switch (exception_stack = exception_stack->prev, 0) \
|
||||
default: \
|
||||
return
|
||||
|
||||
#define CI2_TRY \
|
||||
do { \
|
||||
volatile int exception_flag; \
|
||||
Exception_Frame exception_frame; \
|
||||
exception_frame.prev = exception_stack; \
|
||||
exception_stack = &exception_frame; \
|
||||
exception_flag = setjmp(exception_frame.env); \
|
||||
if (exception_flag == EXCEPTION_ENTERED) {
|
||||
|
||||
#define CI2_EXCEPT(e) \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_stack = exception_stack->prev; \
|
||||
} \
|
||||
else if (exception_frame.exception == &(e)) \
|
||||
{ \
|
||||
exception_flag = EXCEPTION_HANDLED;
|
||||
|
||||
#define CI2_ELSE \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_stack = exception_stack->prev; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
exception_flag = EXCEPTION_HANDLED;
|
||||
|
||||
#define CI2_FINALLY \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_stack = exception_stack->prev; \
|
||||
} \
|
||||
{ \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_flag = EXCEPTION_FINALIZED;
|
||||
|
||||
#define CI2_END_TRY \
|
||||
if (exception_flag == EXCEPTION_ENTERED) \
|
||||
exception_stack = exception_stack->prev; \
|
||||
} \
|
||||
if (exception_flag == EXCEPTION_RAISED) \
|
||||
CI2_RERAISE; \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#endif // ci2_exception.h
|
||||
@@ -0,0 +1,67 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_ARENA_H
|
||||
#define CI2_ARENA_H
|
||||
|
||||
#include "../ci2_platform.h"
|
||||
#include "../error/ci2_exception.h"
|
||||
|
||||
enum
|
||||
{
|
||||
DEFAULT = 0, /* default: fail-handler (throws) + zero */
|
||||
SOFT_FAIL = 1u << 0, /* on failure return NULL */
|
||||
HARD_FAIL = 1u << 1, /* on failure call abort() */
|
||||
NO_ZERO = 1u << 2, /* do not zero memory on success */
|
||||
};
|
||||
|
||||
struct Arena
|
||||
{
|
||||
char* beg;
|
||||
char* end;
|
||||
};
|
||||
typedef struct Arena Arena;
|
||||
|
||||
/* Forward definition of an exception */
|
||||
CI2_API struct Exception arena_oom;
|
||||
|
||||
/* Initialize an Arena from a buffer. */
|
||||
CI2_API void
|
||||
arena_init(struct Arena* a, void* buf, ptrdiff_t len);
|
||||
|
||||
/* Dynamically allocate an Arena */
|
||||
CI2_API struct Arena
|
||||
arena_new(ptrdiff_t cap);
|
||||
|
||||
/* Get the remaining capicity of an arena. */
|
||||
CI2_API ptrdiff_t
|
||||
arena_size(struct Arena a);
|
||||
|
||||
/* Make an allocation from an Arena. */
|
||||
CI2_API void*
|
||||
arena_alloc(struct Arena* a,
|
||||
int flags,
|
||||
ptrdiff_t size,
|
||||
ptrdiff_t align,
|
||||
ptrdiff_t count);
|
||||
|
||||
#endif // ci2_arena.h
|
||||
@@ -0,0 +1,69 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_MEM_H
|
||||
#define CI2_MEM_H
|
||||
|
||||
#include "../error/ci2_exception.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/* Out of memory exception forward declaration. */
|
||||
CI2_API const struct Exception oom;
|
||||
|
||||
/* Allocate an object and do not zero. May throw exception. */
|
||||
CI2_API void*
|
||||
ci2_malloc(size_t nbytes, const char* file, const char* func, int line);
|
||||
|
||||
/* Allocate an object and zero ci2ory. May throw exception. */
|
||||
CI2_API void*
|
||||
ci2_calloc(size_t count,
|
||||
size_t nbytes,
|
||||
const char* file,
|
||||
const char* func,
|
||||
int line);
|
||||
|
||||
/* Free and null a pointer */
|
||||
CI2_API void
|
||||
ci2_free(void** ptr, const char* file, const char* func, int line);
|
||||
|
||||
/* Resize a non-null pointer */
|
||||
CI2_API void*
|
||||
ci2_resize(void* ptr,
|
||||
size_t nbytes,
|
||||
const char* file,
|
||||
const char* func,
|
||||
int line);
|
||||
|
||||
#define CI2_MALLOC(nbytes) ci2_malloc((nbytes), __FILE__, CI2_FUNC, __LINE__)
|
||||
#define CI2_CALLOC(count, nbytes) \
|
||||
ci2_calloc((count), (nbytes), __FILE__, CI2_FUNC, __LINE__)
|
||||
|
||||
#define CI2_NEW(p) ((p) = CI2_MALLOC((size_t)sizeof *(p)))
|
||||
#define CI2_NEW0(p) ((p) = CI2_CALLOC(1, (size_t)sizeof *(p)))
|
||||
|
||||
#define CI2_FREE(ptr) \
|
||||
((void)(ci2_free((ptr), __FILE__, CI2_FUNC, __LINE__), (ptr) = 0))
|
||||
|
||||
#define CI2_RESIZE(ptr, nbytes) \
|
||||
((ptr) = ci2_resize((ptr), (nbytes), __FILE__, CI2_FUNC, __LINE__))
|
||||
|
||||
#endif // ci2_mem.h
|
||||
Reference in New Issue
Block a user