Implement GetCacheMemory via struct abuse

This commit is contained in:
DataHoarder 2022-10-26 12:19:06 +02:00
parent c291cdbaa3
commit a564ce4784
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 11 additions and 3 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.gammaspectra.live/P2Pool/randomx-go-bindings
go 1.19

View file

@ -1,11 +1,10 @@
package randomx
//#cgo CFLAGS: -I./randomx
//#cgo LDFLAGS: -L${SRCDIR}/lib -lrandomx
//#cgo LDFLAGS: -lrandomx
//#cgo LDFLAGS: -lstdc++
//#cgo LDFLAGS: -static -static-libgcc -static-libstdc++ -lpthread -lm
/*
#include "randomx.h"
#include <randomx.h>
#include <time.h>
#include <stdio.h>
#include <stdint.h>
@ -109,6 +108,12 @@ func InitCache(cache *C.randomx_cache, seed []byte) {
C.randomx_init_cache(cache, unsafe.Pointer(&seed[0]), C.size_t(len(seed)))
}
func GetCacheMemory(cache *C.randomx_cache) unsafe.Pointer {
//TODO: very unsafe. Maybe fork RandomX?
//This abuses C.randomx_dataset having memory ptr in the same struct location as C.randomx_cache
return C.randomx_get_dataset_memory((*C.randomx_dataset)(cache))
}
func ReleaseCache(cache *C.randomx_cache) {
C.randomx_release_cache(cache)
}