Skip to content

Commit

Permalink
fix: provider: 'cgo argument has Go pointer to unpinned Go pointer'
Browse files Browse the repository at this point in the history
  • Loading branch information
guidfort committed Sep 16, 2024
1 parent c21d1a2 commit 45ea9b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
30 changes: 15 additions & 15 deletions pkg/datalayer/nodeHandler.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* MIT License
*
* Copyright (c) 2021-2022 Bosch Rexroth AG
*
*
* Copyright (c) 2021-2024 Bosch Rexroth AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -32,39 +32,39 @@
typedef DLR_PROVIDER_NODE_CALLBACK TYPE_CB;
typedef DLR_PROVIDER_NODE_CALLBACKDATA TYPE_CBDATA;

void callCallbackC(TYPE_CB cb, TYPE_CBDATA cbdata, DLR_RESULT result, DLR_VARIANT data)
void callCallbackC(TYPE_CB cb, uint64_t cbdata, DLR_RESULT result, DLR_VARIANT data)
{
cb(cbdata, result, data);
cb((TYPE_CBDATA)cbdata, result, data);
}

extern void nodeCallbackGo(void *userdata, char *address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata, int action);
extern void nodeCallbackGo(void *userdata, char *address, DLR_VARIANT data, TYPE_CB cb, uint64_t cbdata, int action);

void nodeCallbackOnCreate(void *userdata, char *address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, data, cb, cbdata, NODE_ACTION_ON_CREATE);
nodeCallbackGo(userdata, address, data, cb, (uint64_t)cbdata, NODE_ACTION_ON_CREATE);
}

void nodeCallbackOnRemove(void *userdata, char *address, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, NULL, cb, cbdata, NODE_ACTION_ON_REMOVE);
nodeCallbackGo(userdata, address, NULL, cb, (uint64_t)cbdata, NODE_ACTION_ON_REMOVE);
}

void nodeCallbackOnBrowse(void *userdata, char *address, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, NULL, cb, cbdata, NODE_ACTION_ON_BROWSE);
nodeCallbackGo(userdata, address, NULL, cb, (uint64_t)cbdata, NODE_ACTION_ON_BROWSE);
}

void nodeCallbackOnRead(void *userdata, char *address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, data, cb, cbdata, NODE_ACTION_ON_READ);
nodeCallbackGo(userdata, address, data, cb, (uint64_t)cbdata, NODE_ACTION_ON_READ);
}

void nodeCallbackOnWrite(void *userdata, char *address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, data, cb, cbdata, NODE_ACTION_ON_WRITE);
nodeCallbackGo(userdata, address, data, cb, (uint64_t)cbdata, NODE_ACTION_ON_WRITE);
}

void nodeCallbackOnMetadata(void *userdata, char *address, TYPE_CB cb, TYPE_CBDATA cbdata)
{
nodeCallbackGo(userdata, address, NULL, cb, cbdata, NODE_ACTION_ON_METADATA);
}
nodeCallbackGo(userdata, address, NULL, cb, (uint64_t)cbdata, NODE_ACTION_ON_METADATA);
}
11 changes: 5 additions & 6 deletions pkg/datalayer/nodeHandler.go
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2021-2022 Bosch Rexroth AG
// Copyright (c) 2021-2024 Bosch Rexroth AG
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,15 +41,14 @@ typedef enum NODE_ACTION {
NODE_ACTION_ON_METADATA,
}NODE_ACTION;
extern void callCallbackC(TYPE_CB cb, TYPE_CBDATA cbdata, DLR_RESULT result, DLR_VARIANT data);
extern void callCallbackC(TYPE_CB cb, uint64_t cbdata, DLR_RESULT result, DLR_VARIANT data);
extern void nodeCallbackOnCreate(void* userdata, char* address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata);
extern void nodeCallbackOnRemove(void* userdata, char* address, TYPE_CB cb, TYPE_CBDATA cbdata);
extern void nodeCallbackOnBrowse(void* userdata, char* address, TYPE_CB cb, TYPE_CBDATA cbdata);
extern void nodeCallbackOnRead(void* userdata, char* address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata);
extern void nodeCallbackOnWrite(void* userdata, char* address, DLR_VARIANT data, TYPE_CB cb, TYPE_CBDATA cbdata);
extern void nodeCallbackOnMetadata(void* userdata, char* address, TYPE_CB cb, TYPE_CBDATA cbdata);
*/
extern void nodeCallbackOnMetadata(void* userdata, char* address, TYPE_CB cb, TYPE_CBDATA cbdata);*/
import "C"
import (
"sync"
Expand All @@ -75,7 +74,7 @@ type nodeUserData struct {
}

//export nodeCallbackGo
func nodeCallbackGo(cuserdata unsafe.Pointer, caddress *C.char, cdata C.DLR_VARIANT, cb C.TYPE_CB, cbdata C.TYPE_CBDATA, action C.int) {
func nodeCallbackGo(cuserdata unsafe.Pointer, caddress *C.char, cdata C.DLR_VARIANT, cb C.TYPE_CB, cbdata C.ulong, action C.int) {
var i int = *(*int)(cuserdata)
var userdata *nodeUserData = nodeLookup(i)
address := C.GoString(caddress)
Expand Down Expand Up @@ -118,7 +117,7 @@ func getNodeUserdata(channels ProviderNodeChannels) unsafe.Pointer {
}

// createCallbackC closure to hide C types
func createCallbackC(cb C.TYPE_CB, cbdata C.TYPE_CBDATA) ProviderNodeCallback {
func createCallbackC(cb C.TYPE_CB, cbdata C.ulong) ProviderNodeCallback {
return func(result Result, data *Variant) {
if data == nil {
C.callCallbackC(cb, cbdata, C.DLR_RESULT(result), nil)
Expand Down

0 comments on commit 45ea9b2

Please sign in to comment.