diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-02-16 00:43:36 -0500 |
---|---|---|
committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-02-16 00:48:59 -0500 |
commit | fa8e95cd172769c337a5945cfaa4f0aeb1d128ca (patch) | |
tree | 812dbcc5fdfeb267327661b7a4016d1b228d48d5 | |
parent | a21f3238c8701f79f98486101123c6de01e439ea (diff) | |
download | gobject-introspection-fa8e95cd172769c337a5945cfaa4f0aeb1d128ca.tar.gz |
sourcescanner: Fix symbolic references in enum members
We need to copy the source symbols, otherwise we'll
overwrite their values. This isn't good.
https://bugzilla.gnome.org/show_bug.cgi?id=693939
-rw-r--r-- | giscanner/scannerparser.y | 6 | ||||
-rw-r--r-- | giscanner/sourcescanner.c | 20 | ||||
-rw-r--r-- | giscanner/sourcescanner.h | 1 | ||||
-rw-r--r-- | tests/scanner/Regress-1.0-expected.gir | 29 | ||||
-rw-r--r-- | tests/scanner/regress.h | 10 |
5 files changed, 48 insertions, 18 deletions
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index 773e9612..3457b499 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -366,15 +366,15 @@ unary_expression $$ = $2; break; case UNARY_MINUS: - $$ = $2; + $$ = gi_source_symbol_copy ($2); $$->const_int = -$2->const_int; break; case UNARY_BITWISE_COMPLEMENT: - $$ = $2; + $$ = gi_source_symbol_copy ($2); $$->const_int = ~$2->const_int; break; case UNARY_LOGICAL_NEGATION: - $$ = $2; + $$ = gi_source_symbol_copy ($2); $$->const_int = !gi_source_symbol_get_const_boolean ($2); break; default: diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c index 1b775b46..339bd897 100644 --- a/giscanner/sourcescanner.c +++ b/giscanner/sourcescanner.c @@ -45,6 +45,26 @@ ctype_free (GISourceType * type) } GISourceSymbol * +gi_source_symbol_copy (GISourceSymbol * symbol) +{ + GISourceSymbol *new_symbol = gi_source_symbol_new (symbol->type, + symbol->source_filename, + symbol->line); + new_symbol->ident = g_strdup (symbol->ident); + + if (symbol->base_type) + new_symbol->base_type = gi_source_type_copy (symbol->base_type); + if (symbol->const_int_set) + new_symbol->const_int = symbol->const_int; + else if (symbol->const_double_set) + new_symbol->const_double = symbol->const_double_set; + else if (symbol->const_string != NULL) + new_symbol->const_string = g_strdup (symbol->const_string); + + return new_symbol; +} + +GISourceSymbol * gi_source_symbol_ref (GISourceSymbol * symbol) { symbol->ref_count++; diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h index 1c0a8b0b..f67ae6bd 100644 --- a/giscanner/sourcescanner.h +++ b/giscanner/sourcescanner.h @@ -162,6 +162,7 @@ GISourceSymbol * gi_source_symbol_new (GISourceSymbolType type gboolean gi_source_symbol_get_const_boolean (GISourceSymbol *symbol); GISourceSymbol * gi_source_symbol_ref (GISourceSymbol *symbol); void gi_source_symbol_unref (GISourceSymbol *symbol); +GISourceSymbol * gi_source_symbol_copy (GISourceSymbol *symbol); /* Private */ void gi_source_scanner_add_symbol (GISourceScanner *scanner, diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 65628943..22c4b0db 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -1908,16 +1908,6 @@ exposed to language bindings.</doc> </parameter> </parameters> </callback> - <constant name="GUINT64_CONSTANT" - value="18446744073709551615" - c:type="REGRESS_GUINT64_CONSTANT"> - <type name="guint64" c:type="guint64"/> - </constant> - <constant name="GUINT64_CONSTANTA" - value="18446744073709551615" - c:type="REGRESS_GUINT64_CONSTANTA"> - <type name="TestTypeGUInt64" c:type="RegressTestTypeGUInt64"/> - </constant> <constant name="G_GINT64_CONSTANT" value="1000" c:type="REGRESS_G_GINT64_CONSTANT"> @@ -1963,11 +1953,6 @@ exposed to language bindings.</doc> c:type="REGRESS_Mixed_Case_Constant"> <type name="gint" c:type="gint"/> </constant> - <constant name="NEGATIVE_INT_CONSTANT" - value="-42" - c:type="REGRESS_NEGATIVE_INT_CONSTANT"> - <type name="gint" c:type="gint"/> - </constant> <constant name="STRING_CONSTANT" value="Some String" c:type="REGRESS_STRING_CONSTANT"> @@ -3566,6 +3551,20 @@ the introspection client langage.</doc> <type name="gint" c:type="gint"/> </field> </record> + <enumeration name="TestReferenceEnum" c:type="RegressTestReferenceEnum"> + <member name="0" value="4" c:identifier="REGRESS_TEST_REFERENCE_0"> + </member> + <member name="1" value="2" c:identifier="REGRESS_TEST_REFERENCE_1"> + </member> + <member name="2" value="54" c:identifier="REGRESS_TEST_REFERENCE_2"> + </member> + <member name="3" value="4" c:identifier="REGRESS_TEST_REFERENCE_3"> + </member> + <member name="4" value="216" c:identifier="REGRESS_TEST_REFERENCE_4"> + </member> + <member name="5" value="-217" c:identifier="REGRESS_TEST_REFERENCE_5"> + </member> + </enumeration> <record name="TestSimpleBoxedA" c:type="RegressTestSimpleBoxedA" glib:type-name="RegressTestSimpleBoxedA" diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index f243a14c..ba82ca83 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -189,6 +189,16 @@ GType regress_test_enum_unsigned_get_type (void) G_GNUC_CONST; GType regress_test_flags_get_type (void) G_GNUC_CONST; #define REGRESS_TEST_TYPE_FLAGS (regress_test_flags_get_type ()) +typedef enum +{ + REGRESS_TEST_REFERENCE_0 = 2 + 2, + REGRESS_TEST_REFERENCE_1 = 1 + 1, + REGRESS_TEST_REFERENCE_2 = 6 * 9, + REGRESS_TEST_REFERENCE_3 = REGRESS_TEST_REFERENCE_1 + REGRESS_TEST_REFERENCE_1, + REGRESS_TEST_REFERENCE_4 = REGRESS_TEST_REFERENCE_2 * REGRESS_TEST_REFERENCE_3, + REGRESS_TEST_REFERENCE_5 = ~REGRESS_TEST_REFERENCE_4, +} RegressTestReferenceEnum; + /* this is not registered with GType */ typedef enum { |