From 85074f8f8866ae0f46db148008a9a0dd0d5912a2 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Mon, 11 Oct 2021 00:10:01 +0200 Subject: [PATCH] librclone: add RcloneFreeString function See PR #5703 Based on initial work by Weng Haoyu (@wengh) in PR #5362 --- librclone/README.md | 1 + librclone/librclone.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/librclone/README.md b/librclone/README.md index 5b9f7fe6d..56dbb7fc5 100644 --- a/librclone/README.md +++ b/librclone/README.md @@ -31,6 +31,7 @@ For documentation see the Go documentation for: - [RcloneInitialize](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneInitialize) - [RcloneFinalize](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneFinalize) - [RcloneRPC](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneRPC) +- [RcloneFreeString](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneFreeString) ### C Example diff --git a/librclone/librclone.go b/librclone/librclone.go index 0ad94d301..90c22a04a 100644 --- a/librclone/librclone.go +++ b/librclone/librclone.go @@ -20,6 +20,8 @@ package main /* +#include + struct RcloneRPCResult { char* Output; int Status; @@ -28,6 +30,8 @@ struct RcloneRPCResult { import "C" import ( + "unsafe" + "github.com/rclone/rclone/librclone/librclone" _ "github.com/rclone/rclone/backend/all" // import all backends @@ -79,5 +83,17 @@ func RcloneRPC(method *C.char, input *C.char) (result C.struct_RcloneRPCResult) return result } +// RcloneFreeString may be used to free the string returned by RcloneRPC +// +// If the caller has access to the C standard library, the free function can +// normally be called directly instead. In some cases the caller uses a +// runtime library which is not compatible, and then this function can be +// used to release the memory with the same library that allocated it. +// +//export RcloneFreeString +func RcloneFreeString(str *C.char) { + C.free(unsafe.Pointer(str)) +} + // do nothing here - necessary for building into a C library func main() {}