cgo

package aa

import (
"crypto/elliptic"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"math/big"
"sync"
"testing"
)

func TestName(t *testing.T) {
wg := new(sync.WaitGroup)
n := 7
wg.Add(n)
curve := secp256k1.S256()
n1 := new(big.Int).Sub(curve.Params().N, big.NewInt(1))
x, y := curve.ScalarBaseMult(n1.Bytes())
for i := 0; i < n; i++ {
go func() {
for i := 0; i < 199999; i++ {
x, y = curve.ScalarMult(x, y, n1.Bytes())
}
wg.Done()
}()
}
wg.Wait()
}

func TestNameX(t *testing.T) {
wg := new(sync.WaitGroup)
n := 7
wg.Add(n)
curve := elliptic.P256()
n1 := new(big.Int).Sub(curve.Params().N, big.NewInt(1))
x, y := curve.ScalarBaseMult(n1.Bytes())
for i := 0; i < n; i++ {
go func() {
for i := 0; i < 199999; i++ {
x, y = curve.ScalarMult(x, y, n1.Bytes())
}
wg.Done()
}()
}
wg.Wait()
}

 

 

https://uncledou.site/2021/go-cgo/

 

https://github.com/vladimirvivien/go-cshared-examples/blob/master/README.md

 

https://cloud.tencent.com/developer/article/1650525

 

package main

import "C"

//export AddFromGo
func AddFromGo(a int64, b int64) int64 {
return a + b
}

//export Len
func Len(a []byte) int {
return len(a)
}

func main() {}



go build  -buildmode=c-shared  .




/* Created by “go tool cgo” — DO NOT EDIT. */
...
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

/*
  static assertion to make sure the file is being used on architecture
  at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue.  */

#ifdef __cplusplus
extern "C" {
#endif


extern GoInt Add(GoInt p0, GoInt p1);

extern GoFloat64 Cosine(GoFloat64 p0);

extern void Sort(GoSlice p0);

extern GoInt Log(GoString p0);

#ifdef __cplusplus
}
#endif
posted @ 2024-07-15 10:40  zJanly  阅读(11)  评论(0编辑  收藏  举报