Comments (8)
On first glance I would say that the second option would be acceptable and less intrusive but I see the same problem with variants: there the return value type is not constant and you can't exploit such coincidence.
Looking at the GMP naming you should even use get_str/set_str but this would be a further complication...
from mlib.
True...
I propose then to have for both tuple & variant:
- T * _get_at_##field
- T const * _cget_at_##field
It may be good to have also:
- T * _get(tuple, enum field)
- T const * _cget(tuple, enum field)
with the enum field defining which version of the field we want.
(this will give a good symmetry with an array / dict _get & _cget).
from mlib.
This proposal looks reasonable with a safer naming.
I'm still looking at the strange naming of the _set_str/_parse_str methods. I understand that the _parse_str is one of the methods of an OPLIST and that it gets a third parameter to make possible the step-by-step parsing. On the other side I look at the string_set_str specific method and to the mpz_set_str one of GMP. I'm wondering if would be more congruent to keep the _parse_str methods with three params but to make standard a _set_str method for all the containers that get only two params and, maybe using _parse_str, parse the full string in order to reconstruct the container content. Does it make sense?
from mlib.
Thanks.
The parse_str interface is based on the strtol interface, whereas set_str is based on atol. In fact, I think a method like parse_str is missing in GMP (MPFR has added mpfr_strtofr). The method _set_str is too limited for its designed usage. Moreover, there is the strict equivalence:
_set\_str(Object, str) == _parse_str(Object, str, NULL)
(_parse_str accepts NULL as final argument).
This different interface is why I chose a different naming for this function. Moreover, it reflects more what it does since for non-trivial types, it performs a parsing of the string. _set_str is suitable only for simple and controlled cases.
Note that string_set_str != string_parse_str: string_set_str sets the string to the exact array of char string_parse_str parses the string that shall be in the form "THIS \"IS\" A STRING" into THIS "IS" A STRING (this is needed for proper serialization of objects within other objects).
Therefore, I don't see the needs for adding _set_str.
from mlib.
Ok, I can see the difference. Now it is more clear.
I've just tried the latest version in master and maybe something went wrong. Now my main code raises a warning like:
warning: passing 'const symbol_list_t' (aka 'struct symbol_list_s const[1]') to parameter of type 'struct symbol_list_s *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
TUPLE_DEF2(record, (name, string_t), (key, symbol_t),
on a tuple of mine:
TUPLE_DEF2(record, (name, string_t), (key, symbol_t), (fields, symbol_list_t))
If you tests say that all is ok, I can try to isolate the exact case.
from mlib.
I cannot reproduce the issue. Could you open a bug report (with the function that raises the warning)?
from mlib.
Methods have been renamed into _get_at and new methods _cget_at have been added.
from mlib.
I don't see any way to implement the T * _get(tuple, enum field) method, as this method should be able to return different type depending on the fields.
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
- Github actions failure HOT 1
- 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.