-
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
Use destructors for automaticaly closing of resources #13
Comments
I like it but maybe it should be under |
This would not be a big win for me. Usually one creates 1 surface for the entire app. Its not hard to destroy it at the end of your program ... or event just forget and quit and have the OS do it for you. I never had a problem with leaking Surfaces |
@treeform But are surfaces the only exposed resource? The surface is only an example here. |
@Araq Here are all of the destroys in the library: proc destroy*(cr: ptr Context)
proc destroy*(options: ptr FontOptions)
proc destroy*(font_face: ptr FontFace)
proc destroy*(scaled_font: ptr ScaledFont)
proc destroy*(path: ptr Path)
proc destroy*(surface: ptr Surface)
proc destroy*(pattern: ptr Pattern) I never had an issue with any of them, so I feel like it will not impact me in any way. It might be a cool thing to do, even if it's not a useful thing to do. Will the |
I made a minimal example. Maybe this is more correct, because type
Context* = object
impl: PContext
proc `=`(cr: var Context, original: Context) =
if cr.impl != nil: cairo_destroy(cr.impl)
cr.impl = cairo_reference(original.impl)
proc `=destroy`(cr: var Context) =
if cr.impl != nil:
cairo_destroy(cr.impl)
cr.impl = nil
proc `=sink`(cr: var Context; original: Context) =
`=destroy`(cr)
cr.impl = original.impl |
No, it's always active, however the old seq implementation (and stuff building on top like tables) ignores destructors. |
Fork exists at https://github.com/b3liever/cairo2 @treeform try it if you like |
Don't forget that we have some sort of high level cairo in gintro for some years now. I have not spent too much effort in it yet, as it does not support introspection and toggle_references, so it is different from the other gtk stuff. But it seems to work with ARC now. I don't accept pull requests, but I may accepts issues or suggestions like the "=" proc to create errors. May add it soon, also for GTK widgets and that. |
in order to do these are the steps that need to be taken:
types and procs interfacing directly with libcairo need to keep their original names
example type example proc
The "higher level" user api of this library will get shorter names like
Surface
,imageSurfaceCreate
.destructors will be attached to these types. it will look like this:
These changes will break the api of this library but will allow the user to forget the closing of resources.
The text was updated successfully, but these errors were encountered: