X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=types%2Fenum.c;h=2ea40ba482449885355ae3dd95f30476e6dc8cb6;hb=e6b4b4f489f66decb680245a13e9e53abfe62ede;hp=f096d5b6dc4081626087094598bc1f59f2cbb1d9;hpb=64fa3fec6c28f1d077812b4bfa06ae73b0f5999d;p=babeltrace.git diff --git a/types/enum.c b/types/enum.c index f096d5b6..2ea40ba4 100644 --- a/types/enum.c +++ b/types/enum.c @@ -16,13 +16,30 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include #include +#include #include #include +#if (__LONG_MAX__ == 2147483647L) +#define WORD_SIZE 32 +#elif (__LONG_MAX__ == 9223372036854775807L) +#define WORD_SIZE 64 +#else +#error "Unknown long size." +#endif + static struct definition *_enum_definition_new(struct declaration *declaration, struct definition_scope *parent_scope, @@ -37,7 +54,7 @@ void enum_range_set_free(void *ptr) g_array_unref(ptr); } -#if (__WORDSIZE == 32) +#if (WORD_SIZE == 32) static inline gpointer get_uint_v(uint64_t *v) { @@ -72,7 +89,7 @@ void enum_val_free(void *ptr) { g_free(ptr); } -#else /* __WORDSIZE != 32 */ +#else /* WORD_SIZE != 32 */ static inline gpointer get_uint_v(uint64_t *v) { @@ -101,7 +118,7 @@ static void enum_val_free(void *ptr) { } -#endif /* __WORDSIZE != 32 */ +#endif /* WORD_SIZE != 32 */ /* * Returns a GArray or NULL. @@ -118,7 +135,7 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration, get_uint_v(&v)); /* Range lookup */ - cds_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) { + bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) { if (iter->range.start._unsigned > v || iter->range.end._unsigned < v) continue; if (!ranges) { @@ -165,7 +182,7 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration, get_int_v(&v)); /* Range lookup */ - cds_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) { + bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) { if (iter->range.start._signed > v || iter->range.end._signed < v) continue; if (!ranges) { @@ -210,12 +227,12 @@ void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_decla array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1); g_array_set_size(array, 1); g_array_index(array, GQuark, array->len - 1) = q; -#if (__WORDSIZE == 32) +#if (WORD_SIZE == 32) valuep = g_new(uint64_t, 1); *valuep = v; -#else /* __WORDSIZE != 32 */ +#else /* WORD_SIZE != 32 */ valuep = get_uint_v(&v); -#endif /* __WORDSIZE != 32 */ +#endif /* WORD_SIZE != 32 */ g_hash_table_insert(enum_declaration->table.value_to_quark_set, valuep, array); } else { g_array_set_size(array, array->len + 1); @@ -236,12 +253,12 @@ void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declara array = g_array_sized_new(FALSE, TRUE, sizeof(GQuark), 1); g_array_set_size(array, 1); g_array_index(array, GQuark, array->len - 1) = q; -#if (__WORDSIZE == 32) +#if (WORD_SIZE == 32) valuep = g_new(int64_t, 1); *valuep = v; -#else /* __WORDSIZE != 32 */ +#else /* WORD_SIZE != 32 */ valuep = get_int_v(&v); -#endif /* __WORDSIZE != 32 */ +#endif /* WORD_SIZE != 32 */ g_hash_table_insert(enum_declaration->table.value_to_quark_set, valuep, array); } else { g_array_set_size(array, array->len + 1); @@ -263,7 +280,7 @@ void enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration struct enum_range_to_quark *rtoq; rtoq = g_new(struct enum_range_to_quark, 1); - cds_list_add(&rtoq->node, &enum_declaration->table.range_to_quark); + bt_list_add(&rtoq->node, &enum_declaration->table.range_to_quark); rtoq->range.start._signed = start; rtoq->range.end._signed = end; rtoq->quark = q; @@ -276,7 +293,7 @@ void enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declarati struct enum_range_to_quark *rtoq; rtoq = g_new(struct enum_range_to_quark, 1); - cds_list_add(&rtoq->node, &enum_declaration->table.range_to_quark); + bt_list_add(&rtoq->node, &enum_declaration->table.range_to_quark); rtoq->range.start._unsigned = start; rtoq->range.end._unsigned = end; rtoq->quark = q; @@ -364,12 +381,12 @@ void _enum_declaration_free(struct declaration *declaration) struct enum_range_to_quark *iter, *tmp; g_hash_table_destroy(enum_declaration->table.value_to_quark_set); - cds_list_for_each_entry_safe(iter, tmp, &enum_declaration->table.range_to_quark, node) { - cds_list_del(&iter->node); + bt_list_for_each_entry_safe(iter, tmp, &enum_declaration->table.range_to_quark, node) { + bt_list_del(&iter->node); g_free(iter); } g_hash_table_destroy(enum_declaration->table.quark_to_range_set); - declaration_unref(&enum_declaration->integer_declaration->p); + bt_declaration_unref(&enum_declaration->integer_declaration->p); g_free(enum_declaration); } @@ -384,11 +401,11 @@ struct declaration_enum * enum_val_equal, enum_val_free, enum_range_set_free); - CDS_INIT_LIST_HEAD(&enum_declaration->table.range_to_quark); + BT_INIT_LIST_HEAD(&enum_declaration->table.range_to_quark); enum_declaration->table.quark_to_range_set = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, enum_range_set_free); - declaration_ref(&integer_declaration->p); + bt_declaration_ref(&integer_declaration->p); enum_declaration->integer_declaration = integer_declaration; enum_declaration->p.id = CTF_TYPE_ENUM; enum_declaration->p.alignment = 1; @@ -413,7 +430,7 @@ struct definition * int ret; _enum = g_new(struct definition_enum, 1); - declaration_ref(&enum_declaration->p); + bt_declaration_ref(&enum_declaration->p); _enum->p.declaration = declaration; _enum->declaration = enum_declaration; _enum->p.ref = 1; @@ -446,7 +463,7 @@ void _enum_definition_free(struct definition *definition) definition_unref(&_enum->integer->p); free_definition_scope(_enum->p.scope); - declaration_unref(_enum->p.declaration); + bt_declaration_unref(_enum->p.declaration); if (_enum->value) g_array_unref(_enum->value); g_free(_enum);