Changeset: 21dcd139fcfe for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=21dcd139fcfe Modified Files: gdk/gdk.h gdk/gdk_atoms.c sql/backends/monet5/sql_cast.c sql/backends/monet5/sql_cast_impl_down_from_flt.h sql/backends/monet5/sql_round_impl.h Branch: default Log Message:
Use anonymous enums for TYPE_* values, use designators for initializing BATatoms. Using the enums has the advantage that we can just let the compiler do the counting instead of needing to choose between multiple defines with ifdefs. Using the designators for initialization has the advantage that we don't have to keep the order the same as the the order of the TYPE_* values. diffs (truncated from 563 to 300 lines): diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -464,24 +464,24 @@ #define BATTINY_BITS 8 #define BATTINY ((BUN)1<<BATTINY_BITS) /* minimum allocation buncnt for a BAT */ -#define TYPE_void 0 -#define TYPE_bit 1 -#define TYPE_bte 2 -#define TYPE_sht 3 -#define TYPE_bat 4 /* BAT id: index in BBPcache */ -#define TYPE_int 5 -#define TYPE_oid 6 -#define TYPE_ptr 7 /* C pointer! */ -#define TYPE_flt 8 -#define TYPE_dbl 9 -#define TYPE_lng 10 +enum { + TYPE_void = 0, + TYPE_bit, + TYPE_bte, + TYPE_sht, + TYPE_bat, + TYPE_int, + TYPE_oid, + TYPE_ptr, + TYPE_flt, + TYPE_dbl, + TYPE_lng, #ifdef HAVE_HGE -#define TYPE_hge 11 -#define TYPE_str 12 -#else -#define TYPE_str 11 + TYPE_hge, #endif -#define TYPE_any 255 /* limit types to <255! */ + TYPE_str, + TYPE_any = 255, /* limit types to <255! */ +}; typedef int8_t bit; typedef int8_t bte; diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -1858,270 +1858,209 @@ OIDtoStr(char **dst, size_t *len, const } atomDesc BATatoms[MAXATOMS] = { - {"void", /* name */ - TYPE_void, /* storage */ - true, /* linear */ - 0, /* size */ + [TYPE_void] = { + .name = "void", + .storage = TYPE_void, + .linear = true, #if SIZEOF_OID == SIZEOF_INT - (ptr) &int_nil, /* atomNull */ + .atomNull = (ptr) &int_nil, #else - (ptr) &lng_nil, /* atomNull */ -#endif - (ssize_t (*)(const char *, size_t *, ptr *)) OIDfromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) OIDtoStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) voidRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) voidWrite, /* atomWrite */ -#if SIZEOF_OID == SIZEOF_INT - (int (*)(const void *, const void *)) intCmp, /* atomCmp */ - (BUN (*)(const void *)) intHash, /* atomHash */ -#else - (int (*)(const void *, const void *)) lngCmp, /* atomCmp */ - (BUN (*)(const void *)) lngHash, /* atomHash */ + .atomNull = (ptr) &lng_nil, #endif - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) OIDfromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) OIDtoStr, + .atomRead = (void *(*)(void *, stream *, size_t)) voidRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) voidWrite, +#if SIZEOF_OID == SIZEOF_INT + .atomCmp = (int (*)(const void *, const void *)) intCmp, + .atomHash = (BUN (*)(const void *)) intHash, +#else + .atomCmp = (int (*)(const void *, const void *)) lngCmp, + .atomHash = (BUN (*)(const void *)) lngHash, +#endif }, - {"bit", /* name */ - TYPE_bte, /* storage */ - true, /* linear */ - sizeof(bit), /* size */ - (ptr) &bte_nil, /* atomNull */ - (ssize_t (*)(const char *, size_t *, ptr *)) bitFromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) bitToStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) bitRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) bitWrite, /* atomWrite */ - (int (*)(const void *, const void *)) bteCmp, /* atomCmp */ - (BUN (*)(const void *)) bteHash, /* atomHash */ - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + [TYPE_bit] = { + .name = "bit", + .storage = TYPE_bte, + .linear = true, + .size = sizeof(bit), + .atomNull = (ptr) &bte_nil, + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) bitFromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) bitToStr, + .atomRead = (void *(*)(void *, stream *, size_t)) bitRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) bitWrite, + .atomCmp = (int (*)(const void *, const void *)) bteCmp, + .atomHash = (BUN (*)(const void *)) bteHash, }, - {"bte", /* name */ - TYPE_bte, /* storage */ - true, /* linear */ - sizeof(bte), /* size */ - (ptr) &bte_nil, /* atomNull */ - (ssize_t (*)(const char *, size_t *, ptr *)) bteFromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) bteToStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) bteRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) bteWrite, /* atomWrite */ - (int (*)(const void *, const void *)) bteCmp, /* atomCmp */ - (BUN (*)(const void *)) bteHash, /* atomHash */ - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + [TYPE_bte] = { + .name = "bte", + .storage = TYPE_bte, + .linear = true, + .size = sizeof(bte), + .atomNull = (ptr) &bte_nil, + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) bteFromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) bteToStr, + .atomRead = (void *(*)(void *, stream *, size_t)) bteRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) bteWrite, + .atomCmp = (int (*)(const void *, const void *)) bteCmp, + .atomHash = (BUN (*)(const void *)) bteHash, }, - {"sht", /* name */ - TYPE_sht, /* storage */ - true, /* linear */ - sizeof(sht), /* size */ - (ptr) &sht_nil, /* atomNull */ - (ssize_t (*)(const char *, size_t *, ptr *)) shtFromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) shtToStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) shtRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) shtWrite, /* atomWrite */ - (int (*)(const void *, const void *)) shtCmp, /* atomCmp */ - (BUN (*)(const void *)) shtHash, /* atomHash */ - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + [TYPE_sht] = { + .name = "sht", + .storage = TYPE_sht, + .linear = true, + .size = sizeof(sht), + .atomNull = (ptr) &sht_nil, + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) shtFromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) shtToStr, + .atomRead = (void *(*)(void *, stream *, size_t)) shtRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) shtWrite, + .atomCmp = (int (*)(const void *, const void *)) shtCmp, + .atomHash = (BUN (*)(const void *)) shtHash, }, - {"BAT", /* name */ - TYPE_int, /* storage */ - true, /* linear */ - sizeof(bat), /* size */ - (ptr) &int_nil, /* atomNull */ - (ssize_t (*)(const char *, size_t *, ptr *)) batFromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) batToStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) batRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) batWrite, /* atomWrite */ - (int (*)(const void *, const void *)) intCmp, /* atomCmp */ - (BUN (*)(const void *)) intHash, /* atomHash */ - (int (*)(const void *)) batFix, /* atomFix */ - (int (*)(const void *)) batUnfix, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + [TYPE_bat] = { + .name = "BAT", + .storage = TYPE_int, + .linear = true, + .size = sizeof(bat), + .atomNull = (ptr) &int_nil, + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) batFromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) batToStr, + .atomRead = (void *(*)(void *, stream *, size_t)) batRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) batWrite, + .atomCmp = (int (*)(const void *, const void *)) intCmp, + .atomHash = (BUN (*)(const void *)) intHash, + .atomFix = (int (*)(const void *)) batFix, + .atomUnfix = (int (*)(const void *)) batUnfix, }, - {"int", /* name */ - TYPE_int, /* storage */ - true, /* linear */ - sizeof(int), /* size */ - (ptr) &int_nil, /* atomNull */ - (ssize_t (*)(const char *, size_t *, ptr *)) intFromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) intToStr, /* atomToStr */ - (void *(*)(void *, stream *, size_t)) intRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) intWrite, /* atomWrite */ - (int (*)(const void *, const void *)) intCmp, /* atomCmp */ - (BUN (*)(const void *)) intHash, /* atomHash */ - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ + [TYPE_int] = { + .name = "int", + .storage = TYPE_int, + .linear = true, + .size = sizeof(int), + .atomNull = (ptr) &int_nil, + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) intFromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) intToStr, + .atomRead = (void *(*)(void *, stream *, size_t)) intRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) intWrite, + .atomCmp = (int (*)(const void *, const void *)) intCmp, + .atomHash = (BUN (*)(const void *)) intHash, }, - {"oid", /* name */ + [TYPE_oid] = { + .name = "oid", #if SIZEOF_OID == SIZEOF_INT - TYPE_int, /* storage */ + .storage = TYPE_int, #else - TYPE_lng, /* storage */ + .storage = TYPE_lng, #endif - true, /* linear */ - sizeof(oid), /* size */ + .linear = true, + .size = sizeof(oid), #if SIZEOF_OID == SIZEOF_INT - (ptr) &int_nil, /* atomNull */ + .atomNull = (ptr) &int_nil, #else - (ptr) &lng_nil, /* atomNull */ + .atomNull = (ptr) &lng_nil, #endif - (ssize_t (*)(const char *, size_t *, ptr *)) OIDfromStr, /* atomFromStr */ - (ssize_t (*)(str *, size_t *, const void *)) OIDtoStr, /* atomToStr */ + .atomFromStr = (ssize_t (*)(const char *, size_t *, ptr *)) OIDfromStr, + .atomToStr = (ssize_t (*)(str *, size_t *, const void *)) OIDtoStr, #if SIZEOF_OID == SIZEOF_INT - (void *(*)(void *, stream *, size_t)) intRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) intWrite, /* atomWrite */ - (int (*)(const void *, const void *)) intCmp, /* atomCmp */ - (BUN (*)(const void *)) intHash, /* atomHash */ + .atomRead = (void *(*)(void *, stream *, size_t)) intRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) intWrite, + .atomCmp = (int (*)(const void *, const void *)) intCmp, + .atomHash = (BUN (*)(const void *)) intHash, #else - (void *(*)(void *, stream *, size_t)) lngRead, /* atomRead */ - (gdk_return (*)(const void *, stream *, size_t)) lngWrite, /* atomWrite */ - (int (*)(const void *, const void *)) lngCmp, /* atomCmp */ - (BUN (*)(const void *)) lngHash, /* atomHash */ + .atomRead = (void *(*)(void *, stream *, size_t)) lngRead, + .atomWrite = (gdk_return (*)(const void *, stream *, size_t)) lngWrite, + .atomCmp = (int (*)(const void *, const void *)) lngCmp, + .atomHash = (BUN (*)(const void *)) lngHash, #endif - 0, /* atomFix */ - 0, /* atomUnfix */ - 0, /* atomPut */ - 0, /* atomDel */ - 0, /* atomLen */ - 0, /* atomHeap */ }, - {"ptr", /* name */ - TYPE_ptr, /* storage */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list