Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 1 | // Copyright 2011 The Go Authors. All rights reserved. |
Russ Cox | f9ca3b5 | 2011-03-07 10:37:42 -0500 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Ian Lance Taylor | 17360ac | 2015-11-19 17:03:01 -0800 | [diff] [blame] | 5 | #include <string.h> |
Russ Cox | f9ca3b5 | 2011-03-07 10:37:42 -0500 | [diff] [blame] | 6 | #include <sys/types.h> |
Shenghou Ma | af1dd56 | 2013-05-18 02:55:44 +0800 | [diff] [blame] | 7 | #include <unistd.h> |
Russ Cox | f9ca3b5 | 2011-03-07 10:37:42 -0500 | [diff] [blame] | 8 | #include "_cgo_export.h" |
| 9 | |
| 10 | void |
| 11 | callback(void *f) |
| 12 | { |
Dmitriy Vyukov | fbfed49 | 2011-11-09 23:11:48 +0300 | [diff] [blame] | 13 | // use some stack space |
| 14 | volatile char data[64*1024]; |
| 15 | |
| 16 | data[0] = 0; |
Russ Cox | f9ca3b5 | 2011-03-07 10:37:42 -0500 | [diff] [blame] | 17 | goCallback(f); |
Dmitriy Vyukov | fbfed49 | 2011-11-09 23:11:48 +0300 | [diff] [blame] | 18 | data[sizeof(data)-1] = 0; |
Russ Cox | f9ca3b5 | 2011-03-07 10:37:42 -0500 | [diff] [blame] | 19 | } |
Russ Cox | c3f4319 | 2012-03-06 23:27:30 -0500 | [diff] [blame] | 20 | |
| 21 | void |
| 22 | callGoFoo(void) |
| 23 | { |
| 24 | extern void goFoo(void); |
| 25 | goFoo(); |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | IntoC(void) |
| 30 | { |
| 31 | BackIntoGo(); |
| 32 | } |
| 33 | |
Shenghou Ma | af1dd56 | 2013-05-18 02:55:44 +0800 | [diff] [blame] | 34 | #ifdef WIN32 |
| 35 | #include <windows.h> |
| 36 | long long |
| 37 | mysleep(int seconds) { |
| 38 | long long st = GetTickCount(); |
Alex Brainman | 03f3bfc | 2016-03-02 16:58:40 +1100 | [diff] [blame] | 39 | Sleep(1000 * seconds); |
Shenghou Ma | af1dd56 | 2013-05-18 02:55:44 +0800 | [diff] [blame] | 40 | return st; |
| 41 | } |
| 42 | #else |
| 43 | #include <sys/time.h> |
| 44 | long long |
| 45 | mysleep(int seconds) { |
| 46 | long long st; |
| 47 | struct timeval tv; |
| 48 | gettimeofday(&tv, NULL); |
| 49 | st = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
| 50 | sleep(seconds); |
| 51 | return st; |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | long long |
Russ Cox | c3f4319 | 2012-03-06 23:27:30 -0500 | [diff] [blame] | 56 | twoSleep(int n) |
| 57 | { |
| 58 | BackgroundSleep(n); |
Shenghou Ma | af1dd56 | 2013-05-18 02:55:44 +0800 | [diff] [blame] | 59 | return mysleep(n); |
Russ Cox | c3f4319 | 2012-03-06 23:27:30 -0500 | [diff] [blame] | 60 | } |
Dmitriy Vyukov | 9fe4a9e | 2013-07-22 21:53:20 +0400 | [diff] [blame] | 61 | |
| 62 | void |
| 63 | callGoStackCheck(void) |
| 64 | { |
| 65 | extern void goStackCheck(void); |
| 66 | goStackCheck(); |
| 67 | } |
Keith Randall | 1b6807b | 2014-09-25 07:59:01 -0700 | [diff] [blame] | 68 | |
| 69 | int |
| 70 | returnAfterGrow(void) |
| 71 | { |
| 72 | extern int goReturnVal(void); |
| 73 | goReturnVal(); |
| 74 | return 123456; |
| 75 | } |
| 76 | |
| 77 | int |
| 78 | returnAfterGrowFromGo(void) |
| 79 | { |
| 80 | extern int goReturnVal(void); |
| 81 | return goReturnVal(); |
| 82 | } |
| 83 | |
Ian Lance Taylor | 17360ac | 2015-11-19 17:03:01 -0800 | [diff] [blame] | 84 | void |
| 85 | callGoWithString(void) |
| 86 | { |
| 87 | extern void goWithString(GoString); |
| 88 | const char *str = "string passed from C to Go"; |
| 89 | goWithString((GoString){str, strlen(str)}); |
| 90 | } |