Commit 2a0c1910 authored by Daniel P. Berrangé's avatar Daniel P. Berrangé 💬
Browse files

callbacks: use 'virGo' as prefix for all Go exports and C helpers



When "//export someMethod" is used, the Go method with the listed
name is exported in the global linker namespace. If multiple Go
modules export "someMethod" they will clash at link time.

To address this, all exported Go methods will gain a 'virGo'
prefix to scope them to libvirt's typical C namespace. The matching
C helpers will also gain 'virGo' for consistency, even if they are
static.

Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
parent 634aee05
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ func (c *AdmConnect) ConnectRegisterCloseCallback(callback AdmCloseCallback) err
	var err C.virError
	res := C.virAdmConnectRegisterCloseCallbackHelper(c.ptr, C.long(goCallbackId), &err)
	if res != 0 {
		freeCallbackId(goCallbackId)
		virGoFreeCallbackId(goCallbackId)
		return makeError(&err)
	}
	connData := admGetConnectionData(c)
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ virAdmConnectRegisterCloseCallbackHelper(virAdmConnectPtr conn,
{
    void *id = (void *)goCallbackId;
    return virAdmConnectRegisterCloseCallbackWrapper(conn, virGoAdmCloseCallbackHelper, id,
                                                     freeGoCallbackHelper, err);
                                                     virGoFreeCallbackHelper, err);
}


+3 −3
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ var goCallbackLock sync.RWMutex
var goCallbacks = make(map[int]interface{})
var nextGoCallbackId int = firstGoCallbackId

//export freeCallbackId
func freeCallbackId(goCallbackId int) {
//export virGoFreeCallbackId
func virGoFreeCallbackId(goCallbackId int) {
	goCallbackLock.Lock()
	defer goCallbackLock.Unlock()
	delete(goCallbacks, goCallbackId)
@@ -84,7 +84,7 @@ func getCallbackId(goCallbackId int) interface{} {
	ctx := goCallbacks[goCallbackId]
	if ctx == nil {
		// If this happens there must be a bug in libvirt
		panic("Callback arrived after freeCallbackId was called")
		panic("Callback arrived after virGoFreeCallbackId was called")
	}
	return ctx
}
+3 −3
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@ package libvirt
#cgo libvirt_dlopen CFLAGS: -DLIBVIRT_DLOPEN
#include "callbacks_helper.h"

extern void freeCallbackId(long);
void freeGoCallbackHelper(void *goCallbackId) {
   freeCallbackId((long)goCallbackId);
extern void virGoFreeCallbackId(long);
void virGoFreeCallbackHelper(void *goCallbackId) {
   virGoFreeCallbackId((long)goCallbackId);
}

*/
+1 −1
Original line number Diff line number Diff line
@@ -27,6 +27,6 @@
#ifndef LIBVIRT_GO_CALLBACKS_HELPER_H__
#define LIBVIRT_GO_CALLBACKS_HELPER_H__

void freeGoCallbackHelper(void *goCallbackId);
void virGoFreeCallbackHelper(void *goCallbackId);

#endif /* LIBVIRT_GO_CALLBACKS_HELPER_H__ */
Loading