Skip to content
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

Fixing afbarnard/go-lbfgsb#4 #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

idavydov
Copy link

@idavydov idavydov commented Oct 14, 2016

Hi, I have created a pull request fixing #4. I testes it in go v1.7.1.

Since Go v1.6 Go code may pass a Go pointer to C provided that the Go
memory to which it points does not contain any Go pointers. I create a
synchronized map which stores all the go-objects we need to be able to
retrive. registerCallback is used to register a new object and return
its' index, lookupCallback returns the object by its' index,
unregisterCallback unregisters an object from the map
(callbackFunctions). Now instead of passing pointers to struct with a
pointer, we pass a pointer to int which identifies the apropriate
structure. Type assertion is used to convert interface{} to an actual
object. We do this in order to have unified code for passing objective
function callbacks and log function callbacks.

Since Go v1.6 Go code may pass a Go pointer to C provided that the Go
memory to which it points does not contain any Go pointers. I create a
synchronized map which stores all the go-objects we need to be able to
retrive. registerCallback is used to register a new object and return
its' index, lookupCallback returns the object by its' index,
unregisterCallback unregisters an object from the map
(callbackFunctions). Now instead of passing pointers to struct with a
pointer, we pass a pointer to int which identifies the apropriate
structure. Type assertion is used to convert interface{} to an actual
object. We do this in order to have unified code for passing objective
function callbacks and log function callbacks.
Now registerCallback returns an uint. It is always > 0. If the map is
filled, i.e. all uints are used (highly unlikely), registration function
will panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant