From 64f3832893080f8faf476fdf730c51a52beb5dfa Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 18 Jun 2012 19:10:50 +0200 Subject: [PATCH] scanner: complete the enum-to-error-quark fix Turns out that the problem was not only in the wrong matching to GType enums, but also that the non-GType heuristics used to_underscores instead of to_underscores_noprefix, turning DBusError into D_Bus_Error instead of DBus_Error. Complete with various tests. https://bugzilla.gnome.org/show_bug.cgi?id=669350 --- giscanner/maintransformer.py | 2 +- giscanner/utils.py | 5 +- tests/scanner/Regress-1.0-expected.gir | 123 +++++++++++++++++++++++++++++++++ tests/scanner/regress.c | 84 ++++++++++++++++++++++ tests/scanner/regress.h | 62 +++++++++++++++++ 5 files changed, 274 insertions(+), 2 deletions(-) diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 850d242..355158b 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -901,7 +901,7 @@ the ones that failed to resolve removed.""" if not isinstance(enum, ast.Enum): continue type_name = enum.ctype - uscored = to_underscores(type_name).lower() + uscored = to_underscores_noprefix(type_name).lower() uscore_enums[uscored] = enum diff --git a/giscanner/utils.py b/giscanner/utils.py index 2263b8c..642da36 100644 --- a/giscanner/utils.py +++ b/giscanner/utils.py @@ -52,7 +52,10 @@ _upperstr_pat3 = re.compile(r'^([A-Z])([A-Z])') def to_underscores(name): """Converts a typename to the equivalent underscores name. This is used to form the type conversion macros and enum/flag - name variables""" + name variables. + In particular, and differently from to_underscores_noprefix(), + this function treats the first character differently if it is + uppercase and followed by another uppercase letter.""" name = _upperstr_pat1.sub(r'\1_\2', name) name = _upperstr_pat2.sub(r'\1_\2', name) name = _upperstr_pat3.sub(r'\1_\2', name, count=1) diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index e774948..3f2b6dd 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -32,6 +32,13 @@ and/or use gtk-doc annotations. --> Typedef'd va_list for additional reasons + + + + + @@ -70,6 +77,29 @@ use it should be. + + + + + + + + + + + + + + + c:identifier="REGRESS_TEST_UNSIGNED_VALUE2" glib:nick="value2"/> + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1640,6 +1736,13 @@ libgnome-keyring. + + + + + @@ -2175,6 +2278,12 @@ call and can be released on return. + + + + + @@ -2197,6 +2306,13 @@ call and can be released on return. + + + + + @@ -3133,6 +3249,13 @@ What we're testing here is that the scanner ignores the @a nested inside XML. + + + + + diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c index 13b1888..6ba2bdf 100644 --- a/tests/scanner/regress.c +++ b/tests/scanner/regress.c @@ -1572,6 +1572,90 @@ regress_global_get_flags_out (RegressTestFlags *v) *v = REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3; } +/* error domains */ + +GType +regress_test_error_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const GEnumValue values[] = { + { REGRESS_TEST_ERROR_CODE1, "REGRESS_TEST_ERROR_CODE1", "code1" }, + { REGRESS_TEST_ERROR_CODE2, "REGRESS_TEST_ERROR_CODE2", "code2" }, + { REGRESS_TEST_ERROR_CODE3, "REGRESS_TEST_ERROR_CODE3", "code3" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("RegressTestError"), values); + } + + return etype; +} + +GQuark +regress_test_error_quark (void) +{ + return g_quark_from_static_string ("regress-test-error"); +} + +GType +regress_test_abc_error_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const GEnumValue values[] = { + { REGRESS_TEST_ABC_ERROR_CODE1, "REGRESS_TEST_ABC_ERROR_CODE1", "code1" }, + { REGRESS_TEST_ABC_ERROR_CODE2, "REGRESS_TEST_ABC_ERROR_CODE2", "code2" }, + { REGRESS_TEST_ABC_ERROR_CODE3, "REGRESS_TEST_ABC_ERROR_CODE3", "code3" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("RegressTestABCError"), values); + } + + return etype; +} + +GQuark +regress_test_abc_error_quark (void) +{ + return g_quark_from_static_string ("regress-test-abc-error"); +} + +GType +regress_test_unconventional_error_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY(etype == 0)) { + static const GEnumValue values[] = { + { REGRESS_TEST_OTHER_ERROR_CODE1, "REGRESS_TEST_OTHER_ERROR_CODE1", "code1" }, + { REGRESS_TEST_OTHER_ERROR_CODE2, "REGRESS_TEST_OTHER_ERROR_CODE2", "code2" }, + { REGRESS_TEST_OTHER_ERROR_CODE3, "REGRESS_TEST_OTHER_ERROR_CODE3", "code3" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("RegressTestOtherError"), values); + } + + return etype; +} + +GQuark +regress_test_unconventional_error_quark (void) +{ + return g_quark_from_static_string ("regress-test-other-error"); +} + + +GQuark +regress_test_def_error_quark (void) +{ + return g_quark_from_static_string ("regress-test-def-error"); +} + +GQuark +regress_atest_error_quark (void) +{ + return g_quark_from_static_string ("regress-atest-error"); +} + /* structures */ /** diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index 4d47430..1391637 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -188,6 +188,68 @@ const gchar * regress_test_unsigned_enum_param(RegressTestEnumUnsigned e); void regress_global_get_flags_out (RegressTestFlags *v); +/* error domains */ + +typedef enum +{ + REGRESS_TEST_ERROR_CODE1 = 1, + REGRESS_TEST_ERROR_CODE2 = 2, + REGRESS_TEST_ERROR_CODE3 = 3 +} RegressTestError; + +GType regress_test_error_get_type (void); +GQuark regress_test_error_quark (void); + +/* Test weird names, with and without + c_symbol_prefix given by a GType +*/ +typedef enum +{ + REGRESS_TEST_ABC_ERROR_CODE1 = 1, + REGRESS_TEST_ABC_ERROR_CODE2 = 2, + REGRESS_TEST_ABC_ERROR_CODE3 = 3 +} RegressTestABCError; + +GType regress_test_abc_error_get_type (void); +GQuark regress_test_abc_error_quark (void); + +typedef enum +{ + REGRESS_TEST_OTHER_ERROR_CODE1 = 1, + REGRESS_TEST_OTHER_ERROR_CODE2 = 2, + REGRESS_TEST_OTHER_ERROR_CODE3 = 3 +} RegressTestOtherError; + +/* This returns a GType for RegressTestOtherError. + The difference is intentional, although it + is mainly meant for capitalization problems. +*/ +GType regress_test_unconventional_error_get_type (void); +GQuark regress_test_unconventional_error_quark (void); + +typedef enum +{ + REGRESS_TEST_DEF_ERROR_CODE0 = 0, + REGRESS_TEST_DEF_ERROR_CODE1 = 1, + REGRESS_TEST_DEF_ERROR_CODE2 = 2 +} RegressTestDEFError; + +GQuark regress_test_def_error_quark (void); + +/* the scanner used to have problem + with two uppercase letter right after + the identifier prefix, that's why + we break the RegressTest convention */ +typedef enum +{ + REGRESS_ATEST_ERROR_CODE0 = 0, + REGRESS_ATEST_ERROR_CODE1 = 1, + REGRESS_ATEST_ERROR_CODE2 = 2 +} RegressATestError; + +GQuark regress_atest_error_quark (void); + + /* constants */ #define REGRESS_INT_CONSTANT 4422 -- 2.7.4