core: slight changes to allow compilation under c++

This commit is contained in:
2026-02-03 17:40:45 +00:00
parent 84df46489a
commit e0aea0be19
10 changed files with 39 additions and 22 deletions

View File

@@ -28,7 +28,7 @@ const char *b_class_get_name(const struct _b_class *c)
return c->c_type->r_info->t_name; return c->c_type->r_info->t_name;
} }
void *b_class_get_interface(const struct _b_class *c, const union b_type *id) void *b_class_get_interface(const struct _b_class *c, const union b_type_id *id)
{ {
if (!c) { if (!c) {
return NULL; return NULL;

View File

@@ -5,6 +5,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
B_DECLS_BEGIN;
#define B_WCHAR_INVALID ((b_wchar) - 1) #define B_WCHAR_INVALID ((b_wchar) - 1)
typedef int32_t b_wchar; typedef int32_t b_wchar;
@@ -38,4 +40,6 @@ BLUE_API size_t b_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes);
BLUE_API size_t b_wchar_utf8_string_encoded_size( BLUE_API size_t b_wchar_utf8_string_encoded_size(
const b_wchar *s, size_t nr_codepoints); const b_wchar *s, size_t nr_codepoints);
B_DECLS_END;
#endif #endif

View File

@@ -2,6 +2,7 @@
#define BLUE_CORE_MACROS_H_ #define BLUE_CORE_MACROS_H_
#include <blue/core/class.h> #include <blue/core/class.h>
#include <blue/core/misc.h>
#include <blue/core/object.h> #include <blue/core/object.h>
#include <blue/core/thread.h> #include <blue/core/thread.h>
#include <blue/core/type.h> #include <blue/core/type.h>
@@ -10,6 +11,8 @@
#define __B_IFACE_I0(p, x) p##x #define __B_IFACE_I0(p, x) p##x
#define __B_IFACE_I1(p, x) __B_IFACE_I0(p, x) #define __B_IFACE_I1(p, x) __B_IFACE_I0(p, x)
#define B_STRUCT_EMPTY char _x
/* Type definitions macros (for use in .c source file) */ /* Type definitions macros (for use in .c source file) */
#define B_TYPE_CLASS_DEFINITION_BEGIN(type_name) \ #define B_TYPE_CLASS_DEFINITION_BEGIN(type_name) \
@@ -186,12 +189,4 @@
func_name(priv); \ func_name(priv); \
} while (0) } while (0)
#ifdef __cplusplus
#define B_DECLS_BEGIN extern "C" {
#define B_DECLS_END }
#else
#define B_DECLS_BEGIN
#define B_DECLS_END
#endif
#endif #endif

View File

@@ -8,6 +8,14 @@
#define _Nonnull #define _Nonnull
#endif #endif
#ifdef __cplusplus
#define B_DECLS_BEGIN extern "C" {
#define B_DECLS_END }
#else
#define B_DECLS_BEGIN
#define B_DECLS_END
#endif
#define B_NPOS ((size_t)-1) #define B_NPOS ((size_t)-1)
#define b_min(type, x, y) (z__b_min_##type(x, y)) #define b_min(type, x, y) (z__b_min_##type(x, y))

View File

@@ -4,6 +4,8 @@
#include <blue/core/misc.h> #include <blue/core/misc.h>
#include <blue/core/type.h> #include <blue/core/type.h>
B_DECLS_BEGIN;
#define B_OBJECT_MAGIC 0xDECAFC0C0ABEEF13ULL #define B_OBJECT_MAGIC 0xDECAFC0C0ABEEF13ULL
#define B_OBJECT(p) ((b_object *)(p)) #define B_OBJECT(p) ((b_object *)(p))
@@ -36,4 +38,6 @@ BLUE_API b_object *b_object_create(b_type type);
BLUE_API void b_object_to_string(const b_object *p, B_TYPE_FWDREF(b_stream) * out); BLUE_API void b_object_to_string(const b_object *p, B_TYPE_FWDREF(b_stream) * out);
BLUE_API bool b_object_is_type(const b_object *p, b_type type); BLUE_API bool b_object_is_type(const b_object *p, b_type type);
B_DECLS_END;
#endif #endif

View File

@@ -48,6 +48,7 @@ B_TYPE_CLASS_DECLARATION_BEGIN(b_stream)
B_TYPE_CLASS_DECLARATION_END(b_stream) B_TYPE_CLASS_DECLARATION_END(b_stream)
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream_buffer) B_TYPE_CLASS_DECLARATION_BEGIN(b_stream_buffer)
B_STRUCT_EMPTY;
B_TYPE_CLASS_DECLARATION_END(b_stream_buffer) B_TYPE_CLASS_DECLARATION_END(b_stream_buffer)
BLUE_API b_type b_stream_get_type(); BLUE_API b_type b_stream_get_type();

View File

@@ -14,6 +14,7 @@ B_DECLS_BEGIN;
B_DECLARE_TYPE(b_stringstream); B_DECLARE_TYPE(b_stringstream);
B_TYPE_CLASS_DECLARATION_BEGIN(b_stringstream) B_TYPE_CLASS_DECLARATION_BEGIN(b_stringstream)
B_STRUCT_EMPTY;
B_TYPE_CLASS_DECLARATION_END(b_stringstream) B_TYPE_CLASS_DECLARATION_END(b_stringstream)
BLUE_API b_type b_stringstream_get_type(void); BLUE_API b_type b_stringstream_get_type(void);

View File

@@ -7,6 +7,8 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
B_DECLS_BEGIN;
#define B_TYPE_MAX_INTERFACES 64 #define B_TYPE_MAX_INTERFACES 64
struct _b_class; struct _b_class;
@@ -16,7 +18,7 @@ typedef void (*b_class_init_function)(struct _b_class *, void *);
typedef void (*b_instance_init_function)(struct _b_object *, void *); typedef void (*b_instance_init_function)(struct _b_object *, void *);
typedef void (*b_instance_fini_function)(struct _b_object *, void *); typedef void (*b_instance_fini_function)(struct _b_object *, void *);
typedef const union b_type { typedef const union b_type_id {
struct { struct {
uint64_t p00, p01; uint64_t p00, p01;
} a; } a;
@@ -29,11 +31,11 @@ typedef enum b_type_flags {
} b_type_flags; } b_type_flags;
typedef struct b_type_info { typedef struct b_type_info {
union b_type t_id; union b_type_id t_id;
union b_type t_parent_id; union b_type_id t_parent_id;
const char *t_name; const char *t_name;
b_type_flags t_flags; b_type_flags t_flags;
union b_type t_interfaces[B_TYPE_MAX_INTERFACES]; union b_type_id t_interfaces[B_TYPE_MAX_INTERFACES];
size_t t_nr_interfaces; size_t t_nr_interfaces;
size_t t_class_size; size_t t_class_size;
b_class_init_function t_class_init; b_class_init_function t_class_init;
@@ -44,9 +46,9 @@ typedef struct b_type_info {
} b_type_info; } b_type_info;
BLUE_API void b_type_id_init( BLUE_API void b_type_id_init(
union b_type *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d, union b_type_id *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d,
uint64_t e); uint64_t e);
static inline void b_type_id_copy(b_type src, union b_type *dest) static inline void b_type_id_copy(b_type src, union b_type_id *dest)
{ {
dest->a.p00 = src->a.p00; dest->a.p00 = src->a.p00;
dest->a.p01 = src->a.p01; dest->a.p01 = src->a.p01;
@@ -58,9 +60,11 @@ static inline int b_type_id_compare(b_type a, b_type b)
return 0; return 0;
} }
return memcmp(a, b, sizeof(union b_type)); return memcmp(a, b, sizeof(union b_type_id));
} }
BLUE_API b_result b_type_register(b_type_info *info); BLUE_API b_result b_type_register(b_type_info *info);
B_DECLS_END;
#endif #endif

View File

@@ -12,7 +12,7 @@
#include <string.h> #include <string.h>
static struct b_btree type_list = B_BTREE_INIT; static struct b_btree type_list = B_BTREE_INIT;
static union b_type zero_id = {0}; static union b_type_id zero_id = {0};
struct type_init_ctx { struct type_init_ctx {
size_t ctx_class_offset; size_t ctx_class_offset;
@@ -39,7 +39,7 @@ B_BTREE_DEFINE_INSERT(
put_type_component, component_compare) put_type_component, component_compare)
static struct b_type_registration *get_type( static struct b_type_registration *get_type(
const b_btree *tree, const union b_type *key) const b_btree *tree, const union b_type_id *key)
{ {
b_btree_node *cur = tree->b_root; b_btree_node *cur = tree->b_root;
while (cur) { while (cur) {
@@ -60,7 +60,7 @@ static struct b_type_registration *get_type(
} }
struct b_type_component *b_type_get_component( struct b_type_component *b_type_get_component(
const b_btree *tree, const union b_type *key) const b_btree *tree, const union b_type_id *key)
{ {
b_btree_node *cur = tree->b_root; b_btree_node *cur = tree->b_root;
while (cur) { while (cur) {
@@ -96,7 +96,7 @@ static struct b_type_component *create_type_component(
} }
void b_type_id_init( void b_type_id_init(
union b_type *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d, union b_type_id *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d,
uint64_t e) uint64_t e)
{ {
b_i32 x_a = b_i32_htob(a); b_i32 x_a = b_i32_htob(a);
@@ -157,7 +157,7 @@ static b_result locate_interface(
} }
static b_result locate_interfaces( static b_result locate_interfaces(
const union b_type *interfaces, size_t nr_interfaces, const union b_type_id *interfaces, size_t nr_interfaces,
struct b_type_registration *dest, struct type_init_ctx *init_ctx) struct b_type_registration *dest, struct type_init_ctx *init_ctx)
{ {
b_result result = B_RESULT_SUCCESS; b_result result = B_RESULT_SUCCESS;

View File

@@ -35,6 +35,6 @@ struct b_type_registration {
extern struct b_type_registration *b_type_get_registration(b_type id); extern struct b_type_registration *b_type_get_registration(b_type id);
extern struct b_type_component *b_type_get_component( extern struct b_type_component *b_type_get_component(
const b_btree *tree, const union b_type *key); const b_btree *tree, const union b_type_id *key);
#endif #endif