From fa8e95cd172769c337a5945cfaa4f0aeb1d128ca Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 16 Feb 2013 00:43:36 -0500 Subject: 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 --- giscanner/scannerparser.y | 6 +++--- giscanner/sourcescanner.c | 20 ++++++++++++++++++++ giscanner/sourcescanner.h | 1 + tests/scanner/Regress-1.0-expected.gir | 29 ++++++++++++++--------------- 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 @@ -44,6 +44,26 @@ ctype_free (GISourceType * type) g_slice_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) { 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. - - - - - - @@ -1963,11 +1953,6 @@ exposed to language bindings. c:type="REGRESS_Mixed_Case_Constant"> - - - @@ -3566,6 +3551,20 @@ the introspection client langage. + + + + + + + + + + + + + +