diff --git a/README.md b/README.md index d483940f..c07a8784 100644 --- a/README.md +++ b/README.md @@ -4456,6 +4456,12 @@ The object oplist is expected to have at least the following operators (`CLEAR` There are designed to work with buffers with policy `BUFFER_PUSH_INIT_POP_MOVE` to send a shared pointer across multiple threads. +If the type is an incomplete type, you need to disable the `INIT` operator and not defined the `EMPLACE_TYPE` operator in the given oplist like this: + +```C + (INIT(0), CLEAR(API_2(incomplete_clear))) ) +``` + `SHARED_PTR_DEF_AS` is the same as `SHARED_PTR_DEF` except the name of the type `name_t` is provided. diff --git a/m-shared.h b/m-shared.h index f64bcf8a..4ec8e25a 100644 --- a/m-shared.h +++ b/m-shared.h @@ -183,10 +183,12 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; } typedef shared_t M_F(name, _ct); \ typedef type M_F(name, _subtype_ct); \ \ - typedef struct M_F(name, _combine_s) { \ - struct M_F(name, _s) ptr; \ - type data; \ - } M_F(name, combine_ct)[1]; \ + M_IF(M_OR(M_TEST_METHOD_P(INIT, oplist), M_TEST_METHOD_ALTER_P(EMPLACE_TYPE, oplist)))( \ + typedef struct M_F(name, _combine_s) { \ + struct M_F(name, _s) ptr; \ + type data; \ + } M_F(name, combine_ct)[1]; \ + , /* nothing to do */ ) /* Define the core functions */ #define M_SHAR3D_PTR_DEF_CORE(name, type, oplist, cpt_oplist, shared_t) \ diff --git a/tests/test-mshared.c b/tests/test-mshared.c index 50891e96..67d3f34b 100644 --- a/tests/test-mshared.c +++ b/tests/test-mshared.c @@ -38,6 +38,11 @@ SHARED_PTR_DEF_AS(SharedDouble, SharedDouble, double) SHARED_PTR_RELAXED_DEF_AS(SharedDouble2, SharedDouble2, double, M_BASIC_OPLIST) SHARED_RESOURCE_DEF_AS(SharedRessource, SharedRessource, SharedRessourceIt, double) +// Test with incomplete structure +struct incomplete_s; +extern void incomplete_clear(struct incomplete_s *ptr); +SHARED_PTR_DEF( shared_incomplete, struct incomplete_s, (INIT(0), CLEAR(API_2(incomplete_clear))) ) + static int f(const shared_int_t p) { return *shared_int_cref(p);