A function that returns an interface type and returns a value
that requires memory allocation will try to allocate while
appearing to be in a syscall. This patch lets that work.
From-SVN: r201226
uintptr npages;
MSpan *s;
void *v;
+ bool incallback;
m = runtime_m();
g = runtime_g();
- if(g->status == Gsyscall)
- dogc = 0;
+
+ incallback = false;
+ if(m->mcache == nil && g->ncgo > 0) {
+ // For gccgo this case can occur when a cgo or SWIG function
+ // has an interface return type and the function
+ // returns a non-pointer, so memory allocation occurs
+ // after syscall.Cgocall but before syscall.CgocallDone.
+ // We treat it as a callback.
+ runtime_exitsyscall();
+ m = runtime_m();
+ incallback = true;
+ dogc = false;
+ }
+
if(runtime_gcwaiting && g != m->g0 && m->locks == 0 && dogc) {
runtime_gosched();
m = runtime_m();
runtime_racemalloc(v, size, m->racepc);
m->racepc = nil;
}
+
+ if(incallback)
+ runtime_entersyscall();
+
return v;
}