Example #1
0
File: class.go Project: hexid/gopy
//export goClassNatSet
func goClassNatSet(obj unsafe.Pointer, idx int, obj2 unsafe.Pointer) int {
	field := getField(idx)
	item := unsafe.Pointer(uintptr(obj) + field.Offset)

	// This is the new value we are being asked to set
	value := newObject((*C.PyObject)(obj2))

	switch field.Type.Kind() {
	case reflect.Int:
		v := int(C.PyLong_AsLong(c(value)))
		if exceptionRaised() {
			return -1
		}
		i := (*int)(item)
		*i = v
		return 0
	}

	raise(NotImplementedError.ErrV(None))
	return -1
}
Example #2
0
// long PyLong_AsLong(PyObject *pylong)
// Return a C long representation of the contents of pylong. If pylong is greater than LONG_MAX, an OverflowError is raised and -1 will be returned.
//
// long PyLong_AsLongAndOverflow(PyObject *pylong, int *overflow)
// Return a C long representation of the contents of pylong. If pylong is greater than LONG_MAX or less than LONG_MIN, set *overflow to 1 or -1, respectively, and return -1; otherwise, set *overflow to 0. If any other exception occurs (for example a TypeError or MemoryError), then -1 will be returned and *overflow will be 0.
//
// New in version 2.7.
func PyLong_AsLong(self *PyObject) int64 {
	return int64(C.PyLong_AsLong(topy(self)))
}
Example #3
0
func (l *Long) Int64() int64 {
	// TODO: AsLongLong doesn't work for me on windows...
	return int64(C.PyLong_AsLong(c(l)))
}