-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
Hi, i have .so file, generated from golang code:
package main
import "C"
import (
"sort"
)
//export Sort
func Sort(vals []int) {
sort.Ints(vals)
}
func main() {}and I have .h file:
typedef long GoInt;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
extern void Sort(GoSlice vals);i try to pass GoSlice from php to golang, but i get exception "Attempt to perform assign of owned C pointer":
<?php
$hFile = __DIR__ . '/ffi.h';
$soFile = __DIR__ . '/ffi.so';
$ffi = \FFI::cdef(file_get_contents($hFile), $soFile);
var_dump(createGoSlice([1,2,3], $ffi);
function createGoSlice(array $data, \FFI $ffi)
{
$slice = $ffi->new('GoSlice');
$slice->data = \FFI::new(\FFI::type('int[2]'));
// $slice->data = \FFI::new(\FFI::arrayType(\FFI::type('int'), [2]));
$slice->len = count($data);
$slice->cap = count($data);
return $slice;
}How can i set property data of GoSlice?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels