Commit 0900ef74 authored by Daniel P. Berrangé's avatar Daniel P. Berrangé 💬
Browse files

events: 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 b0c9ebf5
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -74,8 +74,8 @@ func EventRunDefaultImpl() error {

type EventHandleCallback func(watch int, file int, events EventHandleType)

//export eventHandleCallback
func eventHandleCallback(watch int, fd int, events int, callbackID int) {
//export virGoEventHandleCallback
func virGoEventHandleCallback(watch int, fd int, events int, callbackID int) {
	callbackFunc := getCallbackId(callbackID)

	callback, ok := callbackFunc.(EventHandleCallback)
@@ -117,8 +117,8 @@ func EventRemoveHandle(watch int) error {

type EventTimeoutCallback func(timer int)

//export eventTimeoutCallback
func eventTimeoutCallback(timer int, callbackID int) {
//export virGoEventTimeoutCallback
func virGoEventTimeoutCallback(timer int, callbackID int) {
	callbackFunc := getCallbackId(callbackID)

	callback, ok := callbackFunc.(EventTimeoutCallback)
@@ -171,19 +171,19 @@ type EventTimeoutCallbackInfo struct {
}

func (i *EventHandleCallbackInfo) Invoke(watch int, fd int, event EventHandleType) {
	C.eventHandleCallbackInvoke(C.int(watch), C.int(fd), C.int(event), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
	C.virGoEventHandleCallbackInvoke(C.int(watch), C.int(fd), C.int(event), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
}

func (i *EventTimeoutCallbackInfo) Invoke(timer int) {
	C.eventTimeoutCallbackInvoke(C.int(timer), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
	C.virGoEventTimeoutCallbackInvoke(C.int(timer), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
}

func (i *EventHandleCallbackInfo) Free() {
	C.eventHandleCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
	C.virGoEventHandleCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
}

func (i *EventTimeoutCallbackInfo) Free() {
	C.eventTimeoutCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
	C.virGoEventTimeoutCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
}

type EventLoop interface {
@@ -211,8 +211,8 @@ func EventRegisterImpl(impl EventLoop) error {
	return nil
}

//export eventAddHandleFunc
func eventAddHandleFunc(fd C.int, event C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
//export virGoEventAddHandleFunc
func virGoEventAddHandleFunc(fd C.int, event C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
@@ -226,8 +226,8 @@ func eventAddHandleFunc(fd C.int, event C.int, callback uintptr, opaque uintptr,
	return C.int(eventLoopImpl.AddHandleFunc(int(fd), EventHandleType(event), cbinfo))
}

//export eventUpdateHandleFunc
func eventUpdateHandleFunc(watch C.int, event C.int) {
//export virGoEventUpdateHandleFunc
func virGoEventUpdateHandleFunc(watch C.int, event C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
@@ -235,8 +235,8 @@ func eventUpdateHandleFunc(watch C.int, event C.int) {
	eventLoopImpl.UpdateHandleFunc(int(watch), EventHandleType(event))
}

//export eventRemoveHandleFunc
func eventRemoveHandleFunc(watch C.int) {
//export virGoEventRemoveHandleFunc
func virGoEventRemoveHandleFunc(watch C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
@@ -244,8 +244,8 @@ func eventRemoveHandleFunc(watch C.int) {
	eventLoopImpl.RemoveHandleFunc(int(watch))
}

//export eventAddTimeoutFunc
func eventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
//export virGoEventAddTimeoutFunc
func virGoEventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
@@ -259,8 +259,8 @@ func eventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uint
	return C.int(eventLoopImpl.AddTimeoutFunc(int(freq), cbinfo))
}

//export eventUpdateTimeoutFunc
func eventUpdateTimeoutFunc(timer C.int, freq C.int) {
//export virGoEventUpdateTimeoutFunc
func virGoEventUpdateTimeoutFunc(timer C.int, freq C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
@@ -268,8 +268,8 @@ func eventUpdateTimeoutFunc(timer C.int, freq C.int) {
	eventLoopImpl.UpdateTimeoutFunc(int(timer), int(freq))
}

//export eventRemoveTimeoutFunc
func eventRemoveTimeoutFunc(timer C.int) {
//export virGoEventRemoveTimeoutFunc
func virGoEventRemoveTimeoutFunc(timer C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}
+36 −36
Original line number Diff line number Diff line
@@ -34,96 +34,96 @@ package libvirt
#include "events_helper.h"


void eventHandleCallback(int watch, int fd, int events, int callbackID);
void virGoEventHandleCallback(int watch, int fd, int events, int callbackID);

static void eventAddHandleHelper(int watch, int fd, int events, void *opaque)
static void virGoEventAddHandleHelper(int watch, int fd, int events, void *opaque)
{
    eventHandleCallback(watch, fd, events, (int)(intptr_t)opaque);
    virGoEventHandleCallback(watch, fd, events, (int)(intptr_t)opaque);
}


void eventTimeoutCallback(int timer, int callbackID);
void virGoEventTimeoutCallback(int timer, int callbackID);

static void eventAddTimeoutHelper(int timer, void *opaque)
static void virGoEventAddTimeoutHelper(int timer, void *opaque)
{
    eventTimeoutCallback(timer, (int)(intptr_t)opaque);
    virGoEventTimeoutCallback(timer, (int)(intptr_t)opaque);
}


int eventAddHandleFunc(int fd, int event, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void eventUpdateHandleFunc(int watch, int event);
int eventRemoveHandleFunc(int watch);
int eventAddTimeoutFunc(int freq, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void eventUpdateTimeoutFunc(int timer, int freq);
int eventRemoveTimeoutFunc(int timer);
int virGoEventAddHandleFunc(int fd, int event, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void virGoEventUpdateHandleFunc(int watch, int event);
int virGoEventRemoveHandleFunc(int watch);
int virGoEventAddTimeoutFunc(int freq, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void virGoEventUpdateTimeoutFunc(int timer, int freq);
int virGoEventRemoveTimeoutFunc(int timer);


int eventAddHandleFuncHelper(int fd, int event, virEventHandleCallback callback, void *opaque, virFreeCallback freecb)
int virGoEventAddHandleFuncHelper(int fd, int event, virEventHandleCallback callback, void *opaque, virFreeCallback freecb)
{
    return eventAddHandleFunc(fd, event, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
    return virGoEventAddHandleFunc(fd, event, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
}


void eventUpdateHandleFuncHelper(int watch, int event)
void virGoEventUpdateHandleFuncHelper(int watch, int event)
{
    eventUpdateHandleFunc(watch, event);
    virGoEventUpdateHandleFunc(watch, event);
}


int eventRemoveHandleFuncHelper(int watch)
int virGoEventRemoveHandleFuncHelper(int watch)
{
    return eventRemoveHandleFunc(watch);
    return virGoEventRemoveHandleFunc(watch);
}


int eventAddTimeoutFuncHelper(int freq, virEventTimeoutCallback callback, void *opaque, virFreeCallback freecb)
int virGoEventAddTimeoutFuncHelper(int freq, virEventTimeoutCallback callback, void *opaque, virFreeCallback freecb)
{
    return eventAddTimeoutFunc(freq, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
    return virGoEventAddTimeoutFunc(freq, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
}


void eventUpdateTimeoutFuncHelper(int timer, int freq)
void virGoEventUpdateTimeoutFuncHelper(int timer, int freq)
{
    eventUpdateTimeoutFunc(timer, freq);
    virGoEventUpdateTimeoutFunc(timer, freq);
}


int eventRemoveTimeoutFuncHelper(int timer)
int virGoEventRemoveTimeoutFuncHelper(int timer)
{
    return eventRemoveTimeoutFunc(timer);
    return virGoEventRemoveTimeoutFunc(timer);
}


void virEventRegisterImplHelper(void)
{
    virEventRegisterImplWrapper(eventAddHandleFuncHelper,
                                eventUpdateHandleFuncHelper,
                                eventRemoveHandleFuncHelper,
                                eventAddTimeoutFuncHelper,
                                eventUpdateTimeoutFuncHelper,
                                eventRemoveTimeoutFuncHelper);
    virEventRegisterImplWrapper(virGoEventAddHandleFuncHelper,
                                virGoEventUpdateHandleFuncHelper,
                                virGoEventRemoveHandleFuncHelper,
                                virGoEventAddTimeoutFuncHelper,
                                virGoEventUpdateTimeoutFuncHelper,
                                virGoEventRemoveTimeoutFuncHelper);
}


void eventHandleCallbackInvoke(int watch, int fd, int events, uintptr_t callback, uintptr_t opaque)
void virGoEventHandleCallbackInvoke(int watch, int fd, int events, uintptr_t callback, uintptr_t opaque)
{
    ((virEventHandleCallback)callback)(watch, fd, events, (void *)opaque);
}


void eventTimeoutCallbackInvoke(int timer, uintptr_t callback, uintptr_t opaque)
void virGoEventTimeoutCallbackInvoke(int timer, uintptr_t callback, uintptr_t opaque)
{
    ((virEventTimeoutCallback)callback)(timer, (void *)opaque);
}


void eventHandleCallbackFree(uintptr_t callback, uintptr_t opaque)
void virGoEventHandleCallbackFree(uintptr_t callback, uintptr_t opaque)
{
    ((virFreeCallback)callback)((void *)opaque);
}


void eventTimeoutCallbackFree(uintptr_t callback, uintptr_t opaque)
void virGoEventTimeoutCallbackFree(uintptr_t callback, uintptr_t opaque)
{
    ((virFreeCallback)callback)((void *)opaque);
}
@@ -135,7 +135,7 @@ virEventAddHandleHelper(int fd,
                        int callbackID,
                        virErrorPtr err)
{
    return virEventAddHandleWrapper(fd, events, eventAddHandleHelper,
    return virEventAddHandleWrapper(fd, events, virGoEventAddHandleHelper,
                                    (void *)(intptr_t)callbackID, NULL, err);
}

@@ -145,7 +145,7 @@ virEventAddTimeoutHelper(int timeout,
                         int callbackID,
                         virErrorPtr err)
{
    return virEventAddTimeoutWrapper(timeout, eventAddTimeoutHelper,
    return virEventAddTimeoutWrapper(timeout, virGoEventAddTimeoutHelper,
                                     (void *)(intptr_t)callbackID, NULL, err);
}

+12 −12
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ virEventRegisterImplHelper(void);


void
eventHandleCallbackInvoke(int watch,
virGoEventHandleCallbackInvoke(int watch,
			       int fd,
			       int events,
			       uintptr_t callback,
@@ -43,18 +43,18 @@ eventHandleCallbackInvoke(int watch,


void
eventTimeoutCallbackInvoke(int timer,
virGoEventTimeoutCallbackInvoke(int timer,
				uintptr_t callback,
				uintptr_t opaque);


void
eventHandleCallbackFree(uintptr_t callback,
virGoEventHandleCallbackFree(uintptr_t callback,
			     uintptr_t opaque);


void
eventTimeoutCallbackFree(uintptr_t callback,
virGoEventTimeoutCallbackFree(uintptr_t callback,
			      uintptr_t opaque);