Comments (8)
I can reproduce the issue.
I have a precise idea why it fails and it is a nasty bug (recursive call of M_REDUCE2 that fails to expand properly on its second invocation). I'll think about which is the best solution to fix this properly.
Thanks for the report!
from mlib.
The issue should be solved in master.
If it works fine, I'll back-port the fix to the variant.
from mlib.
Ok, I can confirm that it fixes the toy example and my bigger code.
A question: if I understood I can omit the oplist specifications also in macros like TUPLE_OPLIST (like in the toy example above). Right?
If this is true I think that another bug is raising: it looks related to the automatic definition of the out_str method (with container elements supporting it). I'll try to create another related toy example.
from mlib.
Here the example for the second bug:
TUPLE_DEF2(my_tuple, (name, string_t), (value, int))
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple)
ARRAY_DEF(my_list_of_tuple, my_tuple_t)
#define M_OPL_my_list_of_tuple_t() ARRAY_OPLIST(my_list_of_tuple)
TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)
int main() {
M_LET(t, my_tuple_t)
M_LET(lt, my_list_of_tuple_t)
M_LET(tt, my_tuple_of_tuple_t) {
my_tuple_out_str(stdout, t);
my_list_of_tuple_out_str(stdout, lt);
my_tuple_of_tuple_out_str(stdout, tt);
}
}
Here the methods my_list_of_tuple_out_str
/my_tuple_of_tuple_out_str
are not defined. If I use the specific OPLISTs for the former tuple (#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple, STRING_OPLIST, M_DEFAULT_OPLIST)
then the methods are defined.
from mlib.
You cannot omit the oplist specifications in macros like TUPLE_OPLIST. Otherwise this macro will be conservative and will only provide the interfaces that are always defined by the tuples. This is true for all _OPLIST macro. Unfortunately, I don't know any way to avoid this constraint.
I plan to add support for types in _OPLIST alongside oplist (so that it will try to get a global defined one), but it is not supported yet.
from mlib.
Ok, but I don't understand why the following example looks to work even if the last two OPLISTs are defined without further specifications:
TUPLE_DEF2(my_tuple, (name, string_t), (value, int))
#define M_OPL_my_tuple_t() TUPLE_OPLIST(my_tuple, STRING_OPLIST, M_DEFAULT_OPLIST
ARRAY_DEF(my_list_of_tuple, my_tuple_t)
#define M_OPL_my_list_of_tuple_t() ARRAY_OPLIST(my_list_of_tuple)
TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)
int main() {
M_LET(t, my_tuple_t)
M_LET(lt, my_list_of_tuple_t)
M_LET(tt, my_tuple_of_tuple_t) {
my_tuple_out_str(stdout, t);
my_list_of_tuple_out_str(stdout, lt);
my_tuple_of_tuple_out_str(stdout, tt);
}
}
In this case the _out_str methods looks defined...
from mlib.
The only interface that will read the oplists defined by M_OPL_my_list_of_tuple_t() and M_OPL_my_tuple_of_tuple_t() is the macro M_LET. M_LET only needs an interface that provides the INIT & CLEAR & TYPE operators. And all oplist provide the methods of theses operators. Therefore, you can omit it in this case and it will still work.
An OPLIST only provides to other the interface of the defined type itself. The type and its functions are defined by the macro _DEF, and this macro only needs the oplists of its sub types to decide which function to define, and doesn't need at all the upper OPLIST.
In summary:
/* This will define my_tuple_of_tuple_out_str as string_t exports an OUT_STR method and my_tuple_t exports one too */
TUPLE_DEF2(my_tuple_of_tuple, (name, string_t), (inner_tuple, my_tuple_t))
/* This will not export the defined OUT_STR method to other interfaces */
#define M_OPL_my_tuple_of_tuple_t() TUPLE_OPLIST(my_tuple_of_tuple)
However, I think it is safer to always define the OPLIST with the proper sub-oplists.
from mlib.
Ok, thanks for the details. Closing this.
from mlib.
Related Issues (20)
- Compiler errors HOT 3
- README example not work HOT 3
- Add EMPLACE_TYPE support for B+TREE, DICT, RB-TREE, BUFFER, CONCURRENT HOT 3
- bitset: function for getting minimum index with bit set HOT 3
- Memory leak HOT 5
- How to define REALLOC in OPLIST? HOT 1
- Bug in list? HOT 1
- Allocator customization HOT 2
- How to define a set of pointer? HOT 1
- Possible issue in m-core.h HOT 2
- Possible assertion error HOT 6
- Wrong implementation for set_cstr for bounded strings HOT 16
- M_EMPTY_P(max) doesn't work HOT 4
- BPTREEI_OPLIST2_P4 missing push definition?
- Is it actually possible to create a fixed-size looping buffer? HOT 10
- BUFFER_DEF / BUFFER_THREAD_UNSAFE: performance issue HOT 1
- RB-tree _it_from on root node HOT 1
- Memory issue with _pop_at function while using 2d arrays HOT 1
- string_t: extremely confusing methods names: string_clean and string_clear HOT 5
- Change _str suffix HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlib.