* Add documentation about array arguments. Fixes issue 1125.
* Do not interpret x, y := z, w as special errno form. Fixes issue 952.
* Fix nested Go calls (brainman). Fixes issue 907.
R=r
CC=golang-dev
https://golang.org/cl/
2214044
Enum1 = 1,
Enum2 = 2,
};
+
+typedef unsigned char uuid_t[20];
+
+void uuid_generate(uuid_t x) {
+ x[0] = 0;
+}
+
*/
import "C"
import (
var KILO = C.KILO
+func uuidgen() {
+ var uuid C.uuid_t
+ C.uuid_generate(&uuid[0])
+}
+
func Size(name string) (int64, os.Error) {
var st C.struct_stat
p := C.CString(name)
n, err := Strtol("asdf", 123)
if n != 0 || err != os.EINVAL {
println("Strtol: ", n, err)
- panic("bad atoi2")
+ panic("bad strtol")
}
}
+func TestMultipleAssign() {
+ p := C.CString("123")
+ n, m := C.strtol(p, nil, 345), C.strtol(p, nil, 10)
+ if n != 0 || m != 234 {
+ println("Strtol x2: ", n, m)
+ panic("bad strtol x2")
+ }
+ C.free(unsafe.Pointer(p))
+}
+
var (
uint = (C.uint)(0)
ulong C.ulong
f.walk(&n.X, "expr", visit)
case *ast.AssignStmt:
f.walk(n.Lhs, "expr", visit)
- if len(n.Lhs) == 2 {
+ if len(n.Lhs) == 2 && len(n.Rhs) == 1 {
f.walk(n.Rhs, "as2", visit)
} else {
f.walk(n.Rhs, "expr", visit)
accessed by prefixing them with an underscore: if x points at
a C struct with a field named "type", x._type accesses the field.
+The standard C numeric types are available under the names
+C.char, C.schar (signed char), C.uchar (unsigned char),
+C.short, C.ushort (unsigned short), C.int, C.uint (unsigned int),
+C.long, C.ulong (unsigned long), C.longlong (long long),
+C.ulonglong (unsigned long long), C.float, C.double.
+
To access a struct, union, or enum type directly, prefix it with
struct_, union_, or enum_, as in C.struct_stat.
n, err := C.atoi("abc")
+In C, a function argument written as a fixed size array
+actually requires a pointer to the first element of the array.
+C compilers are aware of this calling convention and adjust
+the call accordingly, but Go cannot. In Go, you must pass
+the pointer to the first element explicitly: C.f(&x[0]).
+
Cgo transforms the input file into four output files: two Go source
files, a C file for 6c (or 8c or 5c), and a C file for gcc.
void
cgocallback(void (*fn)(void), void *arg, int32 argsize)
{
- Gobuf oldsched;
+ Gobuf oldsched, oldg1sched;
G *g1;
void *sp;
if(g != m->g0)
throw("bad g in cgocallback");
- oldsched = m->sched;
-
g1 = m->curg;
+ oldsched = m->sched;
+ oldg1sched = g1->sched;
startcgocallback(g1);
endcgocallback(g1);
m->sched = oldsched;
+ g1->sched = oldg1sched;
}
void