Skip to content

Commit dbe43ec

Browse files
Zuhaitz-devgithub-actions[bot]
authored andcommitted
Auto-update: Bump z-core [skip ci]
1 parent e4e9fb6 commit dbe43ec

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

zstr.h

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* used across all ZDK libraries.
2525
*
2626
* License: MIT
27+
* Author: Zuhaitz
28+
* Repository: https://github.com/z-libs/z-core
29+
* Version: 1.0.0
2730
*/
2831

2932
#ifndef ZCOMMON_H
@@ -36,25 +39,15 @@
3639
#include <string.h>
3740

3841
// Return codes and error handling.
39-
40-
// Success.
4142
#define Z_OK 0
4243
#define Z_FOUND 1 // Element found (positive).
43-
44-
// Generic errors.
4544
#define Z_ERR -1 // Generic error.
46-
47-
// Resource errors.
4845
#define Z_ENOMEM -2 // Out of memory (malloc/realloc failed).
49-
50-
// Access errors.
5146
#define Z_EOOB -3 // Out of bounds / range error.
5247
#define Z_EEMPTY -4 // Container is empty.
5348
#define Z_ENOTFOUND -5 // Element not found.
54-
55-
// Logic errors.
5649
#define Z_EINVAL -6 // Invalid argument / parameter.
57-
#define Z_EEXIST -7 // Element already exists (for example, unique keys).
50+
#define Z_EEXIST -7 // Element already exists.
5851

5952
// Memory management.
6053

@@ -72,26 +65,39 @@
7265

7366
// Compiler extensions and optimization.
7467

75-
/* * We check for GCC/Clang features to enable RAII-style cleanup and optimization hints.
76-
* Define Z_NO_EXTENSIONS to disable this manually.
77-
*/
78-
#if !defined(Z_NO_EXTENSIONS) && (defined(__GNUC__) || defined(__clang__))
68+
// Type inference (typeof)
69+
#ifdef __cplusplus
70+
# include <type_traits>
71+
# define Z_TYPEOF(x) typename std::remove_reference<decltype(x)>::type
72+
# define Z_HAS_TYPEOF 1
73+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
74+
# define Z_TYPEOF(x) typeof(x)
75+
# define Z_HAS_TYPEOF 1
76+
#elif defined(__GNUC__) || defined(__clang__) || defined(__TINYC__)
77+
# define Z_TYPEOF(x) __typeof__(x)
78+
# define Z_HAS_TYPEOF 1
79+
#else
80+
# define Z_HAS_TYPEOF 0
81+
#endif
82+
83+
// Extensions (cleanup, attributes, branch prediction)
84+
#if !defined(Z_NO_EXTENSIONS) && (defined(__GNUC__) || defined(__clang__) || defined(__TINYC__))
7985

8086
# define Z_HAS_CLEANUP 1
81-
82-
// RAII cleanup (destructors).
83-
// Usage: zvec_autofree(Int) v = zvec_init(Int);
8487
# define Z_CLEANUP(func) __attribute__((cleanup(func)))
85-
86-
// Warn if the return value (e.g., an Error Result) is ignored.
8788
# define Z_NODISCARD __attribute__((warn_unused_result))
8889

89-
// Branch prediction hints for the compiler.
90-
# define Z_LIKELY(x) __builtin_expect(!!(x), 1)
91-
# define Z_UNLIKELY(x) __builtin_expect(!!(x), 0)
90+
// TCC supports attributes but NOT __builtin_expect
91+
# if defined(__TINYC__)
92+
# define Z_LIKELY(x) (x)
93+
# define Z_UNLIKELY(x) (x)
94+
# else
95+
# define Z_LIKELY(x) __builtin_expect(!!(x), 1)
96+
# define Z_UNLIKELY(x) __builtin_expect(!!(x), 0)
97+
# endif
9298

9399
#else
94-
100+
// Fallback for MSVC or strict standard C.
95101
# define Z_HAS_CLEANUP 0
96102
# define Z_CLEANUP(func)
97103
# define Z_NODISCARD
@@ -110,6 +116,7 @@
110116
#define DEFINE_LIST_TYPE(T, Name)
111117
#define DEFINE_MAP_TYPE(Key, Val, Name)
112118
#define DEFINE_STABLE_MAP_TYPE(Key, Val, Name)
119+
#define DEFINE_TREE_TYPE(Key, Val, Name)
113120

114121
// Token concatenation macros (useful for unique variable names in macros).
115122
#define Z_CONCAT_(a, b) a ## b

0 commit comments

Comments
 (0)