Add support for out_str for the default C types if C11 is enabled.
This commit is contained in:
1 parent
017f25d9d5
commit
166d408f5e
2 files changed
+40
-1
No files matched your search
@@ -1764,12 +1764,22 @@ m_core_hash (const void *str, size_t length)
|
||||
CLEAR(M_NOTHING_DEFAULT), EQUAL(M_MEMCMP1_A1_DEFAULT), CMP(M_MEMCMP2_A1_DEFAULT), \
|
||||
HASH(M_HASH_A1_DEFAULT))
|
||||
|
||||
/* Default oplist for C standard types (int & float) */
|
||||
/* Default oplist for C standard types (int & float).
|
||||
Implement a generic out_str function if using C11.
|
||||
*/
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
#define M_DEFAULT_OPLIST \
|
||||
(INIT(M_INIT_DEFAULT), INIT_SET(M_SET_DEFAULT), SET(M_SET_DEFAULT), \
|
||||
CLEAR(M_NOTHING_DEFAULT), EQUAL(M_EQUAL_DEFAULT), CMP(M_CMP_DEFAULT), \
|
||||
INIT_MOVE(M_MOVE_DEFAULT), MOVE(M_MOVE_DEFAULT) , \
|
||||
HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) , OUT_STR(M_FPRINT_ARG) )
|
||||
#else
|
||||
#define M_DEFAULT_OPLIST \
|
||||
(INIT(M_INIT_DEFAULT), INIT_SET(M_SET_DEFAULT), SET(M_SET_DEFAULT), \
|
||||
CLEAR(M_NOTHING_DEFAULT), EQUAL(M_EQUAL_DEFAULT), CMP(M_CMP_DEFAULT), \
|
||||
INIT_MOVE(M_MOVE_DEFAULT), MOVE(M_MOVE_DEFAULT) , \
|
||||
HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) )
|
||||
#endif
|
||||
|
||||
#define M_CLASSIC_OPLIST(name) ( \
|
||||
INIT(M_C(name, _init)), \
|
||||
|
||||
@@ -589,12 +589,41 @@ static void test_dual_it1(void)
|
||||
list2_double_clear(list);
|
||||
}
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
|
||||
LIST_DEF(list_int, int)
|
||||
#define M_OPL_list_int_t() LIST_OPLIST(list_int)
|
||||
|
||||
static void test_out_default_oplist(void)
|
||||
{
|
||||
M_LET(list, list_int_t) {
|
||||
FILE *f = fopen ("a-mlist.dat", "wt");
|
||||
if (!f) abort();
|
||||
list_int_push_back(list, 2);
|
||||
list_int_push_back(list, 3);
|
||||
list_int_out_str(f, list);
|
||||
fclose(f);
|
||||
f = fopen("a-mlist.dat", "rt");
|
||||
if (!f) abort();
|
||||
char buffer[1024];
|
||||
assert (fgets(buffer, 1024, f) == buffer);
|
||||
assert (strcmp(buffer, "[3,2]") == 0);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void test_out_default_oplist(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_uint();
|
||||
test_mpz();
|
||||
test_dual_push1();
|
||||
test_dual_it1();
|
||||
test_out_default_oplist();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user