-
Notifications
You must be signed in to change notification settings - Fork 24
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
free objects in the right context #139
Conversation
This fixes some of the problems in #91 |
ctx = contexts[Threads.threadid()] | ||
g1 = LibGEOS.Polygon(p, ctx) | ||
g2 = LibGEOS.Polygon(p, ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #91 it was actually tried to intersect objects that live in one context in another context. I am not sure if is that actually supported by the C library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LibGEOS.intersects(geo1 #=global context=#, geo2 #=global context=#, ctx #= local context =#)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nraynaud is that supported by the C-library? Was this on purpose or an oversight to use differenc contexts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we were trying to trigger a bug on purpose, it was before confirming that even "read only" operations are unsafe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify doing this operation in C code is it known to you whether that is safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we now know it's unsafe in C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think it might be a good idea to carry context around with objects (as already implemented in this PR) and also add an assertion in every function that contexts of all involved objects are equal. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will add assertions in a follow up PR to keep this one as small as possible.
agreed
…On Mon, Oct 17, 2022 at 3:17 PM Jan Weidner ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/test_geos_types.jl
<#139 (comment)>:
> \ No newline at end of file
+end
+
***@***.*** "Multi threading" begin
+ function f91(n)
+ # adapted from #91 (comment)
+ contexts = [LibGEOS.GEOSContext() for i=1:Threads.nthreads()]
+ p = [[[-1.,-1],[+1,-1],[+1,+1],[-1,+1],[-1,-1]]]
+ ***@***.*** :static for i=1:n
+ ctx = contexts[Threads.threadid()]
+ g1 = LibGEOS.Polygon(p, ctx)
+ g2 = LibGEOS.Polygon(p, ctx)
So I think it might be a good idea to carry context around with objects
and also add an assertion
in every function that contexts of all involved objects are equal. What do
you think?
—
Reply to this email directly, view it on GitHub
<#139 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAALOXOD5X3KOYDFJ4YJSQLWDVGYLANCNFSM6AAAAAARHBKNEI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Ok I think this PR is ready. @visr could you review? |
fixes #140 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks for the contribution!
Hi @jw3126! Could you explain why there was a memory leak in the STRTree? I wrote it initally and thought it was ok. Why does the STRTree struct have to be mutable and what is |
Sure. Generelly every
Same reason, why all other wrappers in this package are mutable. Because we need to attach finalizers and this is not possible for bitstypes.
You are talking about this right? GC.@preserve context tree geometry matches begin
GEOSSTRtree_query_r (
context.ptr,
tree.ptr,
geometry.ptr,
cfun_callback,
pointer_from_objref(matches),
)
end The thing is we only pass pointers to |
Thank you, that sounds logical! This sounds like LibGEOS objects behave like interactive ArchGDAL objects, correct? (See https://github.com/yeesian/ArchGDAL.jl/blob/master/docs/src/memory.md) |
I am not familiar with ArchGDAL, but yes it seems so. |
No description provided.