Skip to content

Commit

Permalink
Merge pull request #9 from NoobsEnslaver/fix-todo
Browse files Browse the repository at this point in the history
set Unref finalizer on *ParamSpec returned by *ObjectClass.ListProperties()
  • Loading branch information
RSWilli committed Jul 2, 2024
2 parents 6f735e0 + 6957638 commit dc839ed
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions glib/gobjectclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "C"

import (
"math"
"runtime"
"unsafe"
)

Expand Down Expand Up @@ -39,8 +40,6 @@ func (o *ObjectClass) InstallProperties(params []*ParamSpec) {
// ListProperties returns a list of the properties associated with this object.
// The default values assumed in the parameter spec reflect the values currently
// set in this object, or their defaults.
//
// Unref params after usage.
func (o *ObjectClass) ListProperties() []*ParamSpec {
var size C.guint
props := C.g_object_class_list_properties((*C.GObjectClass)(o.Instance()), &size)
Expand All @@ -51,8 +50,10 @@ func (o *ObjectClass) ListProperties() []*ParamSpec {
out := make([]*ParamSpec, 0)

for _, prop := range (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.GParamSpec)(nil))]*C.GParamSpec)(unsafe.Pointer(props))[:size:size] {
// TODO: use a finialized version that does not require an Unref
out = append(out, ToParamSpec(unsafe.Pointer(prop)))
ps := ToParamSpec(unsafe.Pointer(prop))
runtime.SetFinalizer(ps, (*ParamSpec).Unref)
out = append(out, ps)

}
return out
}
Expand Down

0 comments on commit dc839ed

Please sign in to comment.