Tag: 语言 互操作性

涉及C.free()的C和Go互操作性问题

我有一个Go函数,它包装了lib_proc.h的proc_name(pid,…)函数。 这是完整的C原型 : int proc_name(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 可以在这里找到/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libproc.h (至少在我的系统上)。 它遵循Go代码: package goproc /* #include “libproc.h” int call_proc_name(int pid, char *name, int name_size) { return proc_name(pid, name, name_size); } */ import “C” import “unsafe” import “strings” type DarwinProcess struct { Process } func (DarwinProcess) NameOf(pid int) string { name := […]