コード例 #1
0
ファイル: gmp.go プロジェクト: edisonwsk/golang-on-cygwin
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.i if it needs it.  This is not inherent
// to FFI, just a mismatch between Go's convention of
// making zero values useful and gmp's decision not to.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	C.mpz_init(&z.i[0])
}
コード例 #2
0
ファイル: int.go プロジェクト: jamesadney/gmp
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.t if it needs it.  This is not inherent
// to FFI, just a mismatch between Go's convention of
// making zero values useful and gmp's decision not to.
//
// Make z a reference to another mpz_t (not z.t) by directly assigning
// z.ptr and leaving z.t uninitialized. See Rat.Denom() for an example.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	z.ptr = &z.t[0]
	C.mpz_init(z.ptr)
}
コード例 #3
0
ファイル: int.go プロジェクト: locusf/gmp
// Int promises that the zero value is a 0, but in gmp
// the zero value is a crash.  To bridge the gap, the
// init bool says whether this is a valid gmp value.
// doinit initializes z.i if it needs it.
func (z *Int) doinit() {
	if z.init {
		return
	}
	z.init = true
	C.mpz_init(&z.i[0])
	runtime.SetFinalizer(z, _Int_finalize)
}
コード例 #4
0
ファイル: secret.go プロジェクト: LegoShrimp/crypto
func (s *scalar) SetInt64(v int64) abstract.Scalar {
	vl := C.long(v)
	if int64(vl) != v {
		panic("Oops, int64 initializer doesn't fit into C.ulong")
	}
	var z C.mpz_t
	C.mpz_init(&z[0])
	C.mpz_set_si(&z[0], vl)
	C.element_set_mpz(&s.e[0], &z[0])
	C.mpz_clear(&z[0])
	return s
}