-
Notifications
You must be signed in to change notification settings - Fork 12
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
#75 destroy hooks #81
#75 destroy hooks #81
Conversation
This is a version of using destructors where PixBuf is not a value object, but the pointer to GdkPixbuf directly. You can simply revert this commit to return to the prior version where PixBuf is a value object wrapping GdkPixBuf. That version is known to work.
Adding a |
By adding the path flag to the nim compilation command we can ensure that the owlkettle version used to compile the examples is the **local** version, not one globally installed.
@can-lehmann We're running into the scenario that to support 1.6 we need destructors of type To achieve 1.6. compatibility all it takes is change the signatures: My question would be whether the plan is for owlkettle 3.0 to support nim 1.6 still or not.
The third approach looks like this: when(NimMajor >= 2):
proc `=destroy`(pixbuf: PixbufObj) =
if isNil(pixbuf.gdk):
return
g_object_unref(pointer(pixbuf.gdk))
else:
proc `=destroy`(pixbuf: var PixbufObj) =
if isNil(pixbuf.gdk):
return
g_object_unref(pointer(pixbuf.gdk))
----
when(NimMajor >= 2):
proc `=destroy`(buffer: TextBufferObj) =
g_object_unref(pointer(buffer.gtk))
else:
proc `=destroy`(buffer: var TextBufferObj) =
g_object_unref(pointer(buffer.gtk)) Which path do we want to go down? Regarding destructors for #76 I'll look into it. |
This is a measure for better support of both nim 1.6. and nim 2.0 2.0 no longer supports lock-levels where they are deprecated. So the locks:0 pragma is also deprecated and should be removed. Nim 1.6. meanwhile will spit out warnings over undefined lock levels if the examples are compiled without the pragma. Thus customPragmas was created to define a `locker` pragma. That pragma does nothing on nim2.0 and contains the locks:0 pragma on nim 1.6., satisfying both versions and limiting warning noise.
proc `=destroy`(x: T) = Nim 1.6 desires its destructor hooks to be defined as proc `=destroy`(x: var T) = That is deprecated in nim 2.0. To satisfy both, the new destructor hooks were put behind a when statement
I think we can move forward with 3. for now. You could use a |
I'm actually somewhat torn here. Feel free to overrule me here and I'll still implement it, this is just my current instinct/gut-feeling from my very limited experience with owlkettle and GTK. |
I agree, I would do something like: template destructor(name, typ, body: untyped) =
when NimMajor >= 2:
proc `=destroy`(name: typ) =
body
else:
proc `=destroy`(name: var typ) =
body
destructor(pixbuf, Pixbuf):
... |
Applied the template to TextBuf, PixBuf and Stylesheet and streamlined the two creation procs for textbuf and pixbuf as suggested. |
Are the |
Logically speaking they should be required, because a copy means the ref count for gtk goes up by one and they must be informed of that so that they can handle memory management. |
Since it is a |
Which is a fair point but in that case I'd still want to have the copy-hook, just for "correctness" even if nobody should ever do that. |
Looks good! |
This is a branch containing 2 approaches to the entire destructor semantics:
To go back to the first attempt, just revert the second commit.