core: slight changes to allow compilation under c++
This commit is contained in:
@@ -28,7 +28,7 @@ const char *b_class_get_name(const struct _b_class *c)
|
||||
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) {
|
||||
return NULL;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_WCHAR_INVALID ((b_wchar) - 1)
|
||||
|
||||
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(
|
||||
const b_wchar *s, size_t nr_codepoints);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BLUE_CORE_MACROS_H_
|
||||
|
||||
#include <blue/core/class.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/object.h>
|
||||
#include <blue/core/thread.h>
|
||||
#include <blue/core/type.h>
|
||||
@@ -10,6 +11,8 @@
|
||||
#define __B_IFACE_I0(p, x) 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) */
|
||||
|
||||
#define B_TYPE_CLASS_DEFINITION_BEGIN(type_name) \
|
||||
@@ -186,12 +189,4 @@
|
||||
func_name(priv); \
|
||||
} 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
|
||||
|
||||
@@ -8,6 +8,14 @@
|
||||
#define _Nonnull
|
||||
#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_min(type, x, y) (z__b_min_##type(x, y))
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/type.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_OBJECT_MAGIC 0xDECAFC0C0ABEEF13ULL
|
||||
|
||||
#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 bool b_object_is_type(const b_object *p, b_type type);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -48,6 +48,7 @@ B_TYPE_CLASS_DECLARATION_BEGIN(b_stream)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream)
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream_buffer)
|
||||
B_STRUCT_EMPTY;
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream_buffer)
|
||||
|
||||
BLUE_API b_type b_stream_get_type();
|
||||
|
||||
@@ -14,6 +14,7 @@ B_DECLS_BEGIN;
|
||||
B_DECLARE_TYPE(b_stringstream);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stringstream)
|
||||
B_STRUCT_EMPTY;
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stringstream)
|
||||
|
||||
BLUE_API b_type b_stringstream_get_type(void);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_TYPE_MAX_INTERFACES 64
|
||||
|
||||
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_fini_function)(struct _b_object *, void *);
|
||||
|
||||
typedef const union b_type {
|
||||
typedef const union b_type_id {
|
||||
struct {
|
||||
uint64_t p00, p01;
|
||||
} a;
|
||||
@@ -29,11 +31,11 @@ typedef enum b_type_flags {
|
||||
} b_type_flags;
|
||||
|
||||
typedef struct b_type_info {
|
||||
union b_type t_id;
|
||||
union b_type t_parent_id;
|
||||
union b_type_id t_id;
|
||||
union b_type_id t_parent_id;
|
||||
const char *t_name;
|
||||
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_class_size;
|
||||
b_class_init_function t_class_init;
|
||||
@@ -44,9 +46,9 @@ typedef struct b_type_info {
|
||||
} b_type_info;
|
||||
|
||||
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);
|
||||
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.p01 = src->a.p01;
|
||||
@@ -58,9 +60,11 @@ static inline int b_type_id_compare(b_type a, b_type b)
|
||||
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);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
10
core/type.c
10
core/type.c
@@ -12,7 +12,7 @@
|
||||
#include <string.h>
|
||||
|
||||
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 {
|
||||
size_t ctx_class_offset;
|
||||
@@ -39,7 +39,7 @@ B_BTREE_DEFINE_INSERT(
|
||||
put_type_component, component_compare)
|
||||
|
||||
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;
|
||||
while (cur) {
|
||||
@@ -60,7 +60,7 @@ static struct b_type_registration *get_type(
|
||||
}
|
||||
|
||||
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;
|
||||
while (cur) {
|
||||
@@ -96,7 +96,7 @@ static struct b_type_component *create_type_component(
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
b_i32 x_a = b_i32_htob(a);
|
||||
@@ -157,7 +157,7 @@ static b_result locate_interface(
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
b_result result = B_RESULT_SUCCESS;
|
||||
|
||||
@@ -35,6 +35,6 @@ struct b_type_registration {
|
||||
|
||||
extern struct b_type_registration *b_type_get_registration(b_type id);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user