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 628496 - Emit a warning if a class and its namespace share the same name
Emit a warning if a class and its namespace share the same name
Status: RESOLVED OBSOLETE
Product: gobject-introspection
Classification: Platform
Component: g-ir-scanner
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
: 675985 (view as bug list)
Depends on:
Blocks: 720090
 
 
Reported: 2010-09-01 11:17 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2018-02-08 11:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Support classes and namespaces with the same name. (3.21 KB, patch)
2010-09-01 11:17 UTC, Jasper St. Pierre (not reading bugmail)
rejected Details | Review
Support classes and namespaces with the same name. (2.58 KB, patch)
2010-09-01 11:25 UTC, Jasper St. Pierre (not reading bugmail)
rejected Details | Review
Support classes and namespaces with the same name. (7.08 KB, patch)
2010-09-01 15:19 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
updated patch (7.30 KB, patch)
2010-10-26 12:56 UTC, Jonathan Matthew
none Details | Review

Description Jasper St. Pierre (not reading bugmail) 2010-09-01 11:17:37 UTC
This should help things like GdkPixbuf where there
is a type "GdkPixbuf", which is the same as the
namespace.
Comment 1 Jasper St. Pierre (not reading bugmail) 2010-09-01 11:17:39 UTC
Created attachment 169233 [details] [review]
Support classes and namespaces with the same name.
Comment 2 Jasper St. Pierre (not reading bugmail) 2010-09-01 11:25:54 UTC
Created attachment 169234 [details] [review]
Support classes and namespaces with the same name.

This should help things like GdkPixbuf where there
is a type "GdkPixbuf", which is the same as the
namespace.
Comment 3 Jasper St. Pierre (not reading bugmail) 2010-09-01 15:19:03 UTC
Created attachment 169268 [details] [review]
Support classes and namespaces with the same name.

This should help things like GdkPixbuf where there
is a type "GdkPixbuf", which is the same as the
namespace.
Comment 4 Colin Walters 2010-09-01 15:25:11 UTC
What's the bug?  GdkPixbuf seems to scan fine here (after ebassi pushed an equivalent commit to what I had locally)
Comment 5 Colin Walters 2010-09-01 15:26:38 UTC
Oh sorry, I see now...
Comment 6 Colin Walters 2010-09-01 15:36:35 UTC
Review of attachment 169268 [details] [review]:

::: giscanner/gdumpparser.py
@@ +130,3 @@
                 get_type_func = self._namespace.get(name)
+                if get_type_func:
+                    to_remove.append(get_type_func)

This shouldn't be necessary if we've got the namespacing parsing working right, right?

::: giscanner/transformer.py
@@ +287,3 @@
+                        name = ident[len(prefix):]
+                        if name == "":
+                            matches.append((ns, prefix, 0))

This part seems ok; we should add a comment here or link to this bug.

@@ +289,3 @@
+                            matches.append((ns, prefix, 0))
+                        elif name == "Class": # XXX
+                            matches.append((ns, prefix+"Class", 0))

Yuck.  I'd like to try harder to figure out a less hacky fix.  We could special-case GdkPixbuf in the scanner (I did this already for Atk).

@@ +309,3 @@
                 if not prefix.endswith('_'):
                     prefix = prefix + '_'
+                if ns.name in ns.ctypes:

We can't look in the namespace *contents* in this function, that would introduce ordering issues and make the function effectively nondeterministic.
Comment 7 Jonathan Matthew 2010-10-26 12:56:19 UTC
Created attachment 173253 [details] [review]
updated patch
Comment 8 Jonathan Matthew 2010-10-26 12:58:04 UTC
I kind of wanted to emit a warning in _split_type_and_symbol_prefix, since it's currently a fatal error, but that would cause the test to fail.
Comment 9 Colin Walters 2010-10-26 13:31:12 UTC
(In reply to comment #7)
> Created an attachment (id=173253) [details] [review]
> updated patch

I'm still not sure we want this.  The example given of GdkPixbuf was just a missing --identifier-prefix=Gdk.  

So we do want GdkPixbuf.Pixbuf, not GdkPixbuf.GdkPixbuf.  Are there other libraries which would be fixed with this patch?
Comment 10 Jonathan Matthew 2010-10-26 21:00:55 UTC
I'm working on introspection support for rhythmbox, which uses RhythmDB as both a namespace and a class name.  I could throw everything into one namespace and end up with slightly ugly things like RB.RhythmDB, but I'd prefer this solution.
Comment 11 Jasper St. Pierre (not reading bugmail) 2010-10-27 13:12:13 UTC
This looks a bit cleaner than what I did.

Colin and I talked it over in #introspection on IRC
back when I submitted the original patch:

  * For now, it was too messy a patch, and the use case
    for back could be fixed very easily.

  * When introspecting failed (GdkPixbuf.GdkPixbuf),
    there was a very misleading assert or IndexError
    or something else like that. It looks that someone
    finally added an error for that...


The big dirty part in my patch way back when was when I
was checking the namespace contents. I don't see that here:
if the test works, that's wonderful (still not sure if it
was me being stupid or subsequent fixes in the repo).

The small dirty parts are checking for "Class", "Iface"
and "Interface", but I'd rather special-case GObject
than special-case Rhythmbox or ATK.
Comment 12 Colin Walters 2010-10-27 14:41:05 UTC
(In reply to comment #10)
> I'm working on introspection support for rhythmbox, which uses RhythmDB as both
> a namespace and a class name.  I could throw everything into one namespace and
> end up with slightly ugly things like RB.RhythmDB, but I'd prefer this
> solution.

You do want it to be RhythmDB.RhythmDB?  All the other cases where this came up we thought the --strip-prefix option was better.

It feels inconsistent, since everything else will be stripped, i.e. RhythmDB.Entry but RhythmDB.RhythmDB?  Supporting this in the code is ugly too as you found out.

Are there any obvious things to rename it to?  RhythmDBContext?  RhythmDBMaster?

If you feel strongly about it we can add this patch, but I just want to explore options more.
Comment 13 Jonathan Matthew 2010-10-27 15:00:00 UTC
I don't really have a strong opinion on what name it gets, I just want it to work somehow, and renaming the class seemed like more work than doing this.  I tried out the approach of putting everything in the RB namespace, and that actually seems OK, so I'm not going to push for this any further.

Initially I wasn't getting the 'this class ends up with no name' error message, but instead I was getting a .gir with 'name=""' in various places, so I guess I should at least fix that.
Comment 14 Simon Feltman 2014-01-04 15:52:14 UTC
*** Bug 675985 has been marked as a duplicate of this bug. ***
Comment 15 Simon Feltman 2014-01-04 15:53:59 UTC
Note that bug 675985 had the idea to use a rename annotation to fix this (also had a patch which seemed to break other things though).
Comment 16 Simon Feltman 2014-01-04 16:44:38 UTC
I've also added a patch to bug 706898 (stripping _t on struct names) which takes yet another approach. Adding a new g-ir-scanner flag (--identifier-filter-cmd). This would allow the problem described here to be fixed externally to the library  with minimal code changes to g-ir-scanner.
Comment 17 Bastien Nocera 2014-09-20 18:09:40 UTC
Hit that with gnome-pocket/GnomePocket as well (in https://git.gnome.org/browse/gnome-pocket/)
Comment 18 Bastien Nocera 2014-09-20 18:11:33 UTC
Could we at least add a warning explaining the problem and pointing to this bug? Took me a good hour to find what the problem was...
Comment 19 André Klapper 2015-02-07 17:14:47 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 20 Emmanuele Bassi (:ebassi) 2018-01-25 15:33:52 UTC
Re-titling for clarity.
Comment 21 GNOME Infrastructure Team 2018-02-08 11:58:22 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gobject-introspection/issues/34.