Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Typed filter functions for queries with boolean/number/string results #43

Merged
merged 4 commits into from
Feb 22, 2018

Conversation

juanjux
Copy link
Contributor

@juanjux juanjux commented Feb 22, 2018

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@juanjux juanjux self-assigned this Feb 22, 2018
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Typo

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Remove unneeded include

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@@ -79,6 +79,15 @@ func ptrToNode(ptr C.uintptr_t) *uast.Node {
return (*uast.Node)(unsafe.Pointer(uintptr(ptr)))
}

func initFilter(node *uast.Node, xpath string) (*C.char, int, C.uintptr_t) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be great to have a comment that this function acquires findMutex and caller should unlock it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the second thought, it's better to return some closer func() that caller should defer.

It can include SetGCPercent as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

if !C.Filter(ptr, cquery) {
error := C.Error()
return nil, fmt.Errorf("UastFilter() failed: %s", C.GoString(error))
errorf := fmt.Errorf("UastFilter() failed: %s", C.GoString(error))
C.free(unsafe.Pointer(error))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 3 lines can be moved to a separate function, so no caller will be able to leak it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

func initFilter(node *uast.Node, xpath string) (*C.char, int, C.uintptr_t) {
findMutex.Lock()
cquery := pool.getCstring(xpath)
gcpercent := debug.SetGCPercent(-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is GC stopped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo cult... it was before for the existing functions, I guess the previous programmer found it was needed to avoid problems with C variables, I'll try to remove it and do some intensive testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some testing with a loop and millions of calls and I didn't find any problem, so I've removed the calls to disable/reenable the GC. We should remember this in case there are odd problems in the future that could be causes by this, but I didn't see any need to disable the GC on cgo documentation.

tools/bindings.h Outdated
if (!c_ok) {
*ok = 0;
}
*ok = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be in else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups...

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@juanjux
Copy link
Contributor Author

juanjux commented Feb 22, 2018

@dennwc changes done, please check initFilter and deferFilter again, I'm not sure what did you mean by a closer func so maybe that's not it.

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>

Remove unneded import

Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
@juanjux juanjux merged commit 2a3f77b into bblfsh:master Feb 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants