1
0
mirror of https://github.com/golang/go synced 2024-09-25 15:10:11 -06:00
Commit Graph

7 Commits

Author SHA1 Message Date
Shenghou Ma
1e95429c3f misc/cgo/{life,stdio}, test/run.go: use test/run.go to do the cgo tests
Enhances test/run.go to support testing other directories
   Will enable stdio tests on Windows in a follow-up CL.

R=golang-dev, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/6220049
2012-08-07 09:38:35 +08:00
Russ Cox
c3f4319a24 misc/cgo: re-enable some tests
The testso directory still needs to be enabled.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5731048
2012-03-06 23:27:30 -05:00
Russ Cox
f9ca3b5d5b runtime: scheduler, cgo reorganization
* Change use of m->g0 stack (aka scheduler stack).
* Provide runtime.mcall(f) to invoke f() on m->g0 stack.
* Replace scheduler loop entry with runtime.mcall(schedule).

Runtime.mcall eliminates the need for fake scheduler states that
exist just to run a bit of code on the m->g0 stack
(Grecovery, Gstackalloc).

The elimination of the scheduler as a loop that stops and
starts using gosave and gogo fixes a bad interaction with the
way cgo uses the m->g0 stack.  Cgo runs external (gcc-compiled)
C functions on that stack, and then when calling back into Go,
it sets m->g0->sched.sp below the added call frames, so that
other uses of m->g0's stack will not interfere with those frames.
Unfortunately, gogo (longjmp) back to the scheduler loop at
this point would end up running scheduler with the lower
sp, which no longer points at a valid stack frame for
a call to scheduler.  If scheduler then wrote any function call
arguments or local variables to where it expected the stack
frame to be, it would overwrite other data on the stack.
I realized this possibility while debugging a problem with
calling complex Go code in a Go -> C -> Go cgo callback.
This wasn't the bug I was looking for, it turns out, but I believe
it is a real bug nonetheless.  Switching to runtime.mcall, which
only adds new frames to the stack and never jumps into
functions running in existing ones, fixes this bug.

* Move cgo-related code out of proc.c into cgocall.c.
* Add very large comment describing cgo call sequences.
* Simpilify, regularize cgo function implementations and names.
* Add test suite as misc/cgo/test.

Now the Go -> C path calls cgocall, which calls asmcgocall,
and the C -> Go path calls cgocallback, which calls cgocallbackg.

The shuffling, which affects mainly the callback case, moves
most of the callback implementation to cgocallback running
on the m->curg stack (not the m->g0 scheduler stack) and
only while accounted for with $GOMAXPROCS (between calls
to exitsyscall and entersyscall).

The previous callback code did not block in startcgocallback's
approximation to exitsyscall, so if, say, the garbage collector
were running, it would still barge in and start doing things
like call malloc.  Similarly endcgocallback's approximation of
entersyscall did not call matchmg to kick off new OS threads
when necessary, which caused the bug in issue 1560.

Fixes #1560.

R=iant
CC=golang-dev
https://golang.org/cl/4253054
2011-03-07 10:37:42 -05:00
Russ Cox
0432f289f7 cgo: various bug fixes
* remember #defined names, so that C.stdout can refer
  to the real name (on OS X) __stdoutp.
* better handling of #defined constant expressions
* allow n, err = C.strtol("asdf", 0, 123) to get errno as os.Error
* write all output files to current directory
* don't require gcc output if there was no input

Fixes #533.
Fixes #709.
Fixes #756.

R=r
CC=dho, golang-dev, iant
https://golang.org/cl/1734047
2010-07-14 17:17:53 -07:00
Robert Griesemer
40621d5c0d remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
2009-11-09 12:07:39 -08:00
Robert Griesemer
a074e37489 gofmt -w misc
R=rsc
http://go/go-review/1025004
2009-11-05 23:18:06 -08:00
Russ Cox
133a158bd8 8c, 8l dynamic loading support.
better mach binaries.
cgo working on darwin+linux amd64+386.
eliminated context switches - pi is 30x faster.
add libcgo to build.

on snow leopard:
  - non-cgo binaries work; all tests pass.
  - cgo binaries work on amd64 but not 386.

R=r
DELTA=2031  (1316 added, 626 deleted, 89 changed)
OCL=35264
CL=35304
2009-10-03 10:37:12 -07:00