mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
librclone: add RcloneFreeString function
See PR #5703 Based on initial work by Weng Haoyu (@wengh) in PR #5362
This commit is contained in:
parent
c7329d2ece
commit
85074f8f88
@ -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
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
|
||||
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() {}
|
||||
|
Loading…
Reference in New Issue
Block a user