After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 719566 - scanner: Support boolean constants
scanner: Support boolean constants
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
: 680387 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-11-29 16:04 UTC by Florian Müllner
Modified: 2017-05-04 21:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
scanner: Support boolean constants (7.46 KB, patch)
2013-11-29 16:04 UTC, Florian Müllner
reviewed Details | Review
scanner: Support boolean constants (7.51 KB, patch)
2013-11-29 17:23 UTC, Florian Müllner
committed Details | Review

Description Florian Müllner 2013-11-29 16:04:04 UTC
See patch. Basically I got fed up with consulting API docs every other time I set up an idle/timeout source ... :-)
Comment 1 Florian Müllner 2013-11-29 16:04:08 UTC
Created attachment 263142 [details] [review]
scanner: Support boolean constants

Aliasing TRUE or FALSE is not very common, but done occasionally
for extra clarity. Namely G_SOURCE_REMOVE / G_SOURCE_CONTINUE are
self-explanatory, unlike the "raw" booleans.
Comment 2 Colin Walters 2013-11-29 16:35:12 UTC
Review of attachment 263142 [details] [review]:

::: giscanner/scannerlexer.l
@@ +172,3 @@
+
+"TRUE"					{ return BOOLEAN; }
+"FALSE"					{ return BOOLEAN; }

It's worth noting C99 has "true" and "false" (lowercase).  Up to you whether or not to support...

::: giscanner/scannerparser.y
@@ +331,3 @@
+		$$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno);
+		$$->const_boolean_set = TRUE;
+		$$->const_boolean = strcmp (yytext, "TRUE") == 0 ? TRUE : FALSE;

Might as well future proof with g_ascii_strcasecmp()

::: giscanner/transformer.py
@@ +732,3 @@
+            typeval = ast.TYPE_BOOLEAN
+            value = str(symbol.const_boolean)
+            print value

Leftover debug print?
Comment 3 Florian Müllner 2013-11-29 17:23:25 UTC
Created attachment 263148 [details] [review]
scanner: Support boolean constants

(In reply to comment #2)
> It's worth noting C99 has "true" and "false" (lowercase).  Up to you whether or
> not to support...

It's an easy addition, so sure.


> Might as well future proof with g_ascii_strcasecmp()

Done.


> ::: giscanner/transformer.py
> Leftover debug print?

Whoops, indeed. Fixed.
Comment 4 Colin Walters 2013-11-29 17:50:05 UTC
Review of attachment 263148 [details] [review]:

One other comment, feel free to commit after addressing.

::: giscanner/transformer.py
@@ +731,3 @@
+        elif symbol.const_boolean is not None:
+            typeval = ast.TYPE_BOOLEAN
+            value = str(symbol.const_boolean)

So we're putting the Python stringifcation into the .gir, so it shows up as "True" or "False".  But girnode.c:parse_boolean_value() only looks for TRUE/FALSE.

I think we should:

1) Write either "TRUE" or "true" (I have no opinion on which), but not the Python "True"
2) Also change parse_boolean_value to use g_ascii_strcasecmp() to be defensive (remember .gir files can also be generated by vala)
Comment 5 Florian Müllner 2013-11-29 18:59:55 UTC
Attachment 263148 [details] pushed as e4efb97 - scanner: Support boolean constants

Adjusted as suggested and pushed, thanks!
Comment 6 André Klapper 2015-02-07 16:48:53 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 7 Emmanuele Bassi (:ebassi) 2017-05-04 21:27:11 UTC
*** Bug 680387 has been marked as a duplicate of this bug. ***