Skip to content

Commit

Permalink
Potential fix for hillu#22
Browse files Browse the repository at this point in the history
At this point this is just an experiment. It causes go vet to raise a warning, so these needs further validation before merging.
  • Loading branch information
plusvic committed Jan 26, 2018
1 parent 11748d7 commit 7275017
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler.go
Expand Up @@ -16,7 +16,7 @@ package yara
#include <yara.h>
void compilerCallback(int, char*, int, char*, void*);
void compilerCallback(int, char*, int, char*, uintptr_t);
*/
import "C"
import (
Expand All @@ -27,8 +27,8 @@ import (
)

//export compilerCallback
func compilerCallback(errorLevel C.int, filename *C.char, linenumber C.int, message *C.char, userData unsafe.Pointer) {
c := callbackData.Get(*(*uintptr)(userData)).(*Compiler)
func compilerCallback(errorLevel C.int, filename *C.char, linenumber C.int, message *C.char, userData uintptr) {
c := callbackData.Get(userData).(*Compiler)
msg := CompilerMessage{
Filename: C.GoString(filename),
Line: int(linenumber),
Expand Down Expand Up @@ -108,7 +108,7 @@ func (c *Compiler) AddFile(file *os.File, namespace string) (err error) {
defer C.free(unsafe.Pointer(filename))
id := callbackData.Put(c)
defer callbackData.Delete(id)
C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), unsafe.Pointer(&id))
C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), unsafe.Pointer(id))
numErrors := int(C.yr_compiler_add_file(c.cptr, fh, ns, filename))
if numErrors > 0 {
var buf [1024]C.char
Expand All @@ -132,7 +132,7 @@ func (c *Compiler) AddString(rules string, namespace string) (err error) {
defer C.free(unsafe.Pointer(crules))
id := callbackData.Put(c)
defer callbackData.Delete(id)
C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), unsafe.Pointer(&id))
C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), unsafe.Pointer(id))
numErrors := int(C.yr_compiler_add_string(c.cptr, crules, ns))
if numErrors > 0 {
var buf [1024]C.char
Expand Down

0 comments on commit 7275017

Please sign in to comment.