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

glib.HashTable support #20

Open
2 of 4 tasks
diamondburned opened this issue Jul 19, 2021 · 4 comments
Open
2 of 4 tasks

glib.HashTable support #20

diamondburned opened this issue Jul 19, 2021 · 4 comments
Labels
blocking Issues awaiting replies enhancement New feature or request tracking Progress tracking issues

Comments

@diamondburned
Copy link
Owner

diamondburned commented Jul 19, 2021

Lots of important things need HashTable support, like some very crucial functions in libsecret. Supporting HashTable properly requires accessing a []Type from the XML, which is planned to be implemented like so:

type AnyType struct {
	// Possible variants.
	Type  *Type  `xml:"-"`
	Array *Array `xml:"-"`

	ValueType  *Type  `xml:"-"`
	ValueArray *Array `xml:"-"`
}

var _ xml.Unmarshaler = (*AnyType)(nil)

func (a *AnyType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var all struct {
		Types  []*Type  `xml:"http://www.gtk.org/introspection/core/1.0 type"`
		Arrays []*Array `xml:"http://www.gtk.org/introspection/core/1.0 array"`
	}

	if err := d.DecodeElement(&all, &start); err != nil {
		return err
	}

	if len(all.Types) > 0 {
		a.Type = all.Types[0]
	}
	if len(all.Types) > 1 {
		a.ValueType = all.Types[1]
	}

	if len(all.Arrays) > 0 {
		a.Array = all.Arrays[0]
	}
	if len(all.Arrays) > 1 {
		a.ValueArray = all.Arrays[1]
	}

	return nil
}

However, this doesn't work, as the fields are seemingly missing after UnmarshalXML.

Relevant issue: golang/go#20754.

  • C to Go conversion
  • Go to C conversion
    • map[string]string
    • map[T]T
@diamondburned
Copy link
Owner Author

Why is GIR like this?

@diamondburned
Copy link
Owner Author

Minimal reproduction of the above issue: https://play.golang.org/p/dGyj03YQHhw

@diamondburned
Copy link
Owner Author

This might be caused by AnyType's recursive mess.

A solution might be to flatten the tree: right now, CallableAttrs may have Array | Type, and Array may contain another Type (until nested arrays are supported). Type may only contain other Types.

This flattening might require replacing existing abstraction routines, however, but it should be trivial for the most parts as long as we keep AnyType but detach it away from Type and Array.

@diamondburned
Copy link
Owner Author

Issue #23 blocks this issue.

@diamondburned diamondburned added the enhancement New feature or request label Jul 24, 2021
@diamondburned diamondburned added the tracking Progress tracking issues label Aug 24, 2021
@diamondburned diamondburned added the blocking Issues awaiting replies label Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking Issues awaiting replies enhancement New feature or request tracking Progress tracking issues
Projects
None yet
Development

No branches or pull requests

1 participant