Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add 'subclass' mode #604

Open
wants to merge 122 commits into
base: main
Choose a base branch
from
Open

WIP: Add 'subclass' mode #604

wants to merge 122 commits into from

Conversation

vhdirk
Copy link

@vhdirk vhdirk commented May 15, 2018

Based on his work in https://github.com/sdroege/gst-plugin-rs, @sdroege and I have been working on a set of traits to make subclassing glib/gtk/gst objects possible without too much boilerplate. See https://github.com/sdroege/gobject-subclass and https://github.com/sdroege/gtk-subclass.

Currently, we're generating these traits by hand, and that's a lot of (repetitive) work. In this PR, I'd like to address that by reusing parts of gir. I'm not sure if this would ever be a candidate for inclusion. If not, I'd like to kindly ask for feedback as I/we go along with this.

This is a heavy WIP, that I just started a couple of minutes ago, so there simply nothing to see here. Yet.

@vhdirk
Copy link
Author

vhdirk commented May 16, 2018

Question 1: How do I get get to the object class vfuncs? It seems those are not part of analysis in normal mode?

@EPashkin
Copy link
Member

Currently we ignore virtual-method

@vhdirk
Copy link
Author

vhdirk commented May 17, 2018

The function definitions are present in the sys crates though, as part of the class structs. So the analysis should contain those, but I'm not sure where to look...

@sdroege
Copy link
Member

sdroege commented May 17, 2018

They are in the .gir file as field and as virtual-method. The struct field in the sys crates comes from the former.

You'd have to add it to parser.rs as a very first step

src/parser.rs Outdated
@@ -153,7 +154,11 @@ impl Library {
fields.push(f);
})
}
"virtual-method" => parser.ignore_element(),
"virtual-method" => {
self.read_signal(parser, ns_id, elem).map(|v| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except that they might have annotations for the parameters and return value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured. I'll get to that later. You have to have a fair amount of knowledge of gobject/gir internals here. Which I don't have :D.

@vhdirk
Copy link
Author

vhdirk commented May 26, 2018

At this point, most big building blocks seem in place, yet it is still far from finished.

These things are currently still incomplete/lacking:

  • A lot of assumptions are made regarding the name of crates, modules, objects, classes, etc.
  • There are no imports for the subclass things (not for gobject-subclass, nor for generated traits)
  • Call arguments in the extern C functions are missing since I could not find how to reliably generate from_glib_X convertions
  • any function argument that is not a primitive type or glib object will not be converted like it should. This is primarily a problem for vectors.
  • you name it...

I'd like some feedback and/or help at this point. I've never really liked writing code generators, so I don't really feel like carrying this on my own :)

@vhdirk vhdirk force-pushed the subclass branch 2 times, most recently from b8baad8 to 8030304 Compare May 26, 2018 09:07
@vhdirk
Copy link
Author

vhdirk commented May 27, 2018

Also: I just noticed I'm missing return value signatures almost everywhere.

@sdroege
Copy link
Member

sdroege commented May 29, 2018

Thanks a lot. I'll take a look over this in the next days, but for now can you put some generated output of this somewhere?

Also my idea for manual implementations was to be able to ignore various vfuncs and then have a separate file that has those implementations only. And that file is read by GIR and inserted into the generated code (as we can't have them as separate files during compilation: parts need to be added to the same traits and impl blocks directly).

@vhdirk
Copy link
Author

vhdirk commented May 29, 2018

I have some more pending commits, but my laptop refused internet connection. All add them asap. One of the largest pending issues is that the generated traits for interfaces lack a name.

@vhdirk
Copy link
Author

vhdirk commented May 29, 2018

@sdroege
Copy link
Member

sdroege commented Jun 15, 2018

A PR making use of this is available here: gtk-rs/gobject-subclass#12

It almost completely covers the code generation for GApplication automatically.

@sdroege
Copy link
Member

sdroege commented Jun 24, 2018

Just a heads up here, callback_guard!() / CallbackGuard are deprecated now :)

@vhdirk
Copy link
Author

vhdirk commented Jun 24, 2018

I know. It's been nagging about that all morning :). I'll remove those statements soon. Should make it a wee bit easier to debug.

@vhdirk vhdirk force-pushed the subclass branch 2 times, most recently from e895709 to b8ef2ce Compare July 6, 2018 06:33
@vhdirk vhdirk force-pushed the subclass branch 3 times, most recently from 40e8025 to 77fa6b8 Compare July 6, 2018 20:30
sdroege added a commit to gtk-rs/gobject-subclass that referenced this pull request Nov 17, 2018
It needs to be regenerated by gir once
  gtk-rs/gir#604
is merged.
@vhdirk
Copy link
Author

vhdirk commented Dec 27, 2018

@sdroege I'm willing to update this PR to the new subclassing infrastructure, but it's been a while since I first made this. Since the interface has changed quite a bit, it might also make sense to start fresh. A bit of guidance towards may be needed here in order to get this accepted quicker.

@vhdirk vhdirk closed this Dec 27, 2018
@vhdirk vhdirk reopened this Dec 27, 2018
@sdroege
Copy link
Member

sdroege commented Dec 28, 2018

This now has to be updated for the new subclassing API that was merged into glib directly a few weeks ago, and for the upcoming changes to the glib_wrapper! macro that I'm currently working on for reducing the amount of code a bit more.

@vhdirk
Copy link
Author

vhdirk commented Dec 28, 2018

I figured as much. I've rebased this onto master again, but in order to make it work on the new infrastructure in glib, I'd need some time to figure out where everything has moved.

@bilelmoussaoui bilelmoussaoui mentioned this pull request Apr 1, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants