Add helper function for passing Go string slices to C; document some functions that won't be ported

This commit is contained in:
2026-01-31 21:35:11 -05:00
parent 4ea47594ae
commit 52793fd343
3 changed files with 21 additions and 17 deletions
+15
View File
@@ -27,6 +27,21 @@ func getPascalStringFromBytes(goBytes []byte) C.PascalString {
}
}
// getCPascalStringArrayFromStringSlice converts a Go slice
// of strings to a C array of pascal strings.
func getCPascalStringArrayFromStringSlice(goSlice []string) *C.PascalString {
// allocate C array for PascalStrings
cArrPtr := (*C.PascalString)(C.malloc(C.size_t(len(goSlice)) * C.size_t(C.sizeof_PascalString)))
// populate the array with the decrypted lines
cArr := (*[1 << 30]C.PascalString)(unsafe.Pointer(cArrPtr))[:len(goSlice):len(goSlice)]
for i := range goSlice {
cArr[i] = getPascalString(goSlice[i])
}
return cArrPtr
}
// GetPascalStringFromCString is a helper meant to be used from C.
//
//export GetPascalStringFromCString
+5 -5
View File
@@ -111,11 +111,11 @@ int main() {
- [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error
- [ ] RunJob() (*syncListsT, error)
- [ ] synccommon
- [ ] AddFolderLocal(vanityPath string) error
- [ ] RenameLocal(oldVanityPath, newVanityPath string) error
- [ ] ShearAgeFileLocal(vanityPath string) error
- [ ] ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)
- [X] ~~AddFolderLocal(vanityPath string) error~~ (not for use outside of libmutton)
- [X] ~~RenameLocal(oldVanityPath, newVanityPath string) error~~ (not for use outside of libmutton)
- [X] ~~ShearAgeFileLocal(vanityPath string) error~~ (not for use outside of libmutton)
- [X] ~~ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)~~ (not for use outside of libmutton)
- [ ] WalkEntryDir() ([]string, []string, error)
- [ ] GetAllEntryData() (EntryMapT, error)
- [X] ~~GetAllEntryData() (EntryMapT, error)~~ (not easy to port to C; also not needed)
- [ ] syncserver
- [ ] GetRemoteDataFromServer(clientDeviceID string)
+1 -12
View File
@@ -4,8 +4,6 @@ package main
// #include "types.h"
import "C"
import (
"unsafe"
"github.com/rwinkhart/libmutton/crypt"
"github.com/rwinkhart/rcw/wrappers"
)
@@ -28,16 +26,7 @@ func DecryptFileToSlice(realPath, rcwPassword C.PascalString) (*C.char, *C.Pasca
return nil, nil, 0
}
// allocate C array for PascalStrings
cLinesPtr := (*C.PascalString)(C.malloc(C.size_t(len(lines)) * C.size_t(C.sizeof_PascalString)))
// populate the array with the decrypted lines
cLinesSlice := (*[1 << 30]C.PascalString)(unsafe.Pointer(cLinesPtr))[:len(lines):len(lines)]
for i, line := range lines {
cLinesSlice[i] = getPascalString(line)
}
return nil, cLinesPtr, C.int(len(lines))
return nil, getCPascalStringArrayFromStringSlice(lines), C.int(len(lines))
}
// EncryptBytes returns: