Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
/ gobolt Public archive

Commit

Permalink
Fix compilation errors after latest changes in seabolt
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Oct 30, 2018
1 parent b5134c7 commit 8310c8a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
20 changes: 12 additions & 8 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ func (conn *neo4jConnector) Acquire(mode AccessMode) (Connection, error) {
cMode = C.BOLT_ACCESS_MODE_READ
}

cResult := C.BoltConnector_acquire(conn.cInstance, C.BoltAccessMode(cMode))
if cResult.connection == nil {
codeText := C.GoString(C.BoltError_get_string(cResult.connection_error))
context := C.GoString(cResult.connection_error_ctx)

return nil, newConnectorError(int(cResult.connection_status), int(cResult.connection_error), codeText, context, "unable to acquire connection from connector")
cStatus := C.BoltStatus_create()
defer C.BoltStatus_destroy(cStatus)
cConnection := C.BoltConnector_acquire(conn.cInstance, C.BoltAccessMode(cMode), cStatus)
if cConnection == nil {
state := C.BoltStatus_get_state(cStatus)
code := C.BoltStatus_get_error(cStatus)
codeText := C.GoString(C.BoltError_get_string(code))
context := C.GoString(C.BoltStatus_get_error_context(cStatus))

return nil, newConnectorError(int(state), int(code), codeText, context, "unable to acquire connection from connector")
}

return &neo4jConnection{connector: conn, cInstance: cResult.connection, valueSystem: conn.valueSystem}, nil
return &neo4jConnection{connector: conn, cInstance: cConnection, valueSystem: conn.valueSystem}, nil
}

func (conn *neo4jConnector) release(connection *neo4jConnection) error {
Expand Down Expand Up @@ -172,7 +176,7 @@ func NewConnector(uri *url.URL, authToken map[string]interface{}, config *Config

if certsBuf != nil {
certsBytes := certsBuf.String()
C.BoltTrust_set_certs(cTrust, C.CString(certsBytes), C.int(certsBuf.Len()))
C.BoltTrust_set_certs(cTrust, C.CString(certsBytes), C.uint64_t(certsBuf.Len()))
}

if config.TLSSkipVerify {
Expand Down
27 changes: 15 additions & 12 deletions logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ package gobolt
/*
#include "bolt/bolt.h"
extern void go_seabolt_log_error_cb(int state, char* message);
extern void go_seabolt_log_warning_cb(int state, char* message);
extern void go_seabolt_log_info_cb(int state, char* message);
extern void go_seabolt_log_debug_cb(int state, char* message);
extern void go_seabolt_log_error_cb(void* state, char* message);
extern void go_seabolt_log_warning_cb(void* state, char* message);
extern void go_seabolt_log_info_cb(void* state, char* message);
extern void go_seabolt_log_debug_cb(void* state, char* message);
*/
import "C"
import "sync"
import (
"sync"
"unsafe"
)

// Logging is the interface that any provided logging target must satisfy for the connector
// to use
Expand All @@ -45,31 +48,31 @@ type Logging interface {
}

//export go_seabolt_log_error_cb
func go_seabolt_log_error_cb(state C.int, message *C.char) {
func go_seabolt_log_error_cb(state unsafe.Pointer, message *C.char) {
logging := lookupLogging(state)
if logging != nil && logging.ErrorEnabled() {
logging.Errorf(C.GoString(message))
}
}

//export go_seabolt_log_warning_cb
func go_seabolt_log_warning_cb(state C.int, message *C.char) {
func go_seabolt_log_warning_cb(state unsafe.Pointer, message *C.char) {
logging := lookupLogging(state)
if logging != nil && logging.WarningEnabled() {
logging.Warningf(C.GoString(message))
}
}

//export go_seabolt_log_info_cb
func go_seabolt_log_info_cb(state C.int, message *C.char) {
func go_seabolt_log_info_cb(state unsafe.Pointer, message *C.char) {
logging := lookupLogging(state)
if logging != nil && logging.InfoEnabled() {
logging.Infof(C.GoString(message))
}
}

//export go_seabolt_log_debug_cb
func go_seabolt_log_debug_cb(state C.int, message *C.char) {
func go_seabolt_log_debug_cb(state unsafe.Pointer, message *C.char) {
logging := lookupLogging(state)
if logging != nil && logging.DebugEnabled() {
logging.Debugf(C.GoString(message))
Expand All @@ -85,7 +88,7 @@ func registerLogging(key int, logging Logging) *C.struct_BoltLog {

mapLogging.Store(key, logging)

boltLog := C.BoltLog_create(C.int(key))
boltLog := C.BoltLog_create(unsafe.Pointer(&key))
if logging != nil && logging.ErrorEnabled() {
C.BoltLog_set_error_func(boltLog, C.log_func(C.go_seabolt_log_error_cb))
}
Expand All @@ -105,8 +108,8 @@ func registerLogging(key int, logging Logging) *C.struct_BoltLog {
return boltLog
}

func lookupLogging(key C.int) Logging {
if logging, ok := mapLogging.Load(int(key)); ok {
func lookupLogging(key unsafe.Pointer) Logging {
if logging, ok := mapLogging.Load(*(*int)(key)); ok {
return logging.(Logging)
}

Expand Down
10 changes: 5 additions & 5 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package gobolt
#include <stdlib.h>
#include "bolt/bolt.h"
extern void go_seabolt_server_address_resolver_cb(int state, struct BoltAddress *address, struct BoltAddressSet *resolved);
extern void go_seabolt_server_address_resolver_cb(void* state, struct BoltAddress *address, struct BoltAddressSet *resolved);
*/
import "C"
import (
Expand All @@ -38,7 +38,7 @@ import (
type URLAddressResolver func(address *url.URL) []*url.URL

//export go_seabolt_server_address_resolver_cb
func go_seabolt_server_address_resolver_cb(state C.int, address *C.struct_BoltAddress, resolved *C.struct_BoltAddressSet) {
func go_seabolt_server_address_resolver_cb(state unsafe.Pointer, address *C.struct_BoltAddress, resolved *C.struct_BoltAddressSet) {
resolver := lookupResolver(state)
if resolver != nil {
resolvedAddresses := resolver(&url.URL{Host: fmt.Sprintf("%s:%s", C.GoString(C.BoltAddress_host(address)), C.GoString(C.BoltAddress_port(address)))})
Expand Down Expand Up @@ -66,12 +66,12 @@ func registerResolver(key int, resolver URLAddressResolver) *C.struct_BoltAddres

mapResolver.Store(key, resolver)

boltResolver := C.BoltAddressResolver_create(C.int(key), C.address_resolver_func(C.go_seabolt_server_address_resolver_cb))
boltResolver := C.BoltAddressResolver_create(unsafe.Pointer(&key), C.address_resolver_func(C.go_seabolt_server_address_resolver_cb))
return boltResolver
}

func lookupResolver(key C.int) URLAddressResolver {
if resolver, ok := mapResolver.Load(int(key)); ok {
func lookupResolver(key unsafe.Pointer) URLAddressResolver {
if resolver, ok := mapResolver.Load(*(*int)(key)); ok {
return resolver.(URLAddressResolver)
}

Expand Down

0 comments on commit 8310c8a

Please sign in to comment.