gircore/gir.core

Add equality check to all record types

Closed this issue · 2 comments

As C records are represented as classes an equality check between should be added to ensure that two identical instances return the information that they are identical:

implement for:

  • Typed Records (#1047)
  • Untyped Records (#1050)
  • Opaque Typed Records (#1048)
  • Opaque untyped records (#1049)

It is not yet clear if the pointer or all fields should be compared.

Edit: perhaps comparing all the members would be more appropriate? The more I think of it the more plausible it sounds.

There are records which are reference counted and records which always copied to get a new instance. Should they all behave the same and just do a member comparison?

If yes it could probably be relatively easy. Overriding the equals method of the handle which calls the equals method of the underlying structure could be a possible solution.

I think comparing just the members is what I'd expect for a type like Cairo.RectangleInt since it is more like a struct, so I'd want to be able to see whether two different rectangle instances have the same coordinates

Some types also have a function like gdk_rgba_equal() that could be used.

I looked into this topic a bit and it looks like it is not very easy with the current implementation. For example callbacks are not pointers but objects. Therefore the data must be marshaled.

It would probably be better if all types inside a struct are blittable. This should allow to use some api (Unsafe.AsRef) to get the struct without marshaling.

With marshaling in place (2 times per comparison) I could imagine a heavy performance impact in case of some filtering methods which compare structs.

Additionally structs are almost always pointers. If pointers are compared it would be expected to compare the reference (from a c point of view).

If a value check is needed this could be solved later if the structs are blitable or by some dedicated api (either generated or manually written).

In either case i think both kinds of equality could be relevant for a programmer.

So I think in the first step I'm going to implement the equality check as a reference check only.