maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #10946
Code syntax: questions on pointers, etc.
Recent refactorings of replacing C strings with LEX_CSTRING which is
no doubt a good thing raise some questions:
1. Is it still guaranteed that Field::field_name.str is NULL-terminated?
2. It is still passed as a pointer to functions. Why is that?
The main feature of C++ references is that it cannot be NULL, so we
get segfault on top of the stack (closer to a cause), not the bottom
of it. I see that pointers are now widely used and mainly assumed to
be always non-NULL (i.e. dereferenced without assertion). But placing
such implicit contract on data is not evident and bug-prone. IMHO it's
much better to use references whenever it is possible (and when there
is no need in cosy NULL semantic). What do you think?
But for such lightweight structs like LEX_CSTRING it is even better to
pass by value, so we could have the conventience of type cast.
3. LEX_CSTRING and LEX_STRING are now non-convertible. Why not to make:
template <typename char_t>
struct st_mysql_lex_string
{
char_t *str;
size_t length;
};
typedef st_mysql_lex_string<char *> LEX_STRING;
typedef st_mysql_lex_string<const char *> LEX_CSTRING;
typedef st_mysql_lex_string<const unsigned char *> LEX_CUSTRING;
?
4. There are some duplicate types: MYSQL_LEX_STRING,
MYSQL_CONST_LEX_STRING. Why?
--
All the best,
Aleksey Midenkov
@midenok
Follow ups