Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: misc/cgo/test/callback_c_gccgo.c

Issue 152570049: [dev.power64] code review 152570049: all: merge default into dev.power64 (Closed)
Patch Set: diff -r 36f7fc9495481ed67a159eea0eb2fac35b7c46a5 https://code.google.com/p/go Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « misc/cgo/test/callback_c_gc.c ('k') | misc/cgo/test/cgo_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build gccgo 5 // +build gccgo
6 6
7 #include "_cgo_export.h" 7 #include "_cgo_export.h"
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
8 11
9 /* Test calling panic from C. This is what SWIG does. */ 12 /* Test calling panic from C. This is what SWIG does. */
10 13
11 extern void _cgo_panic(const char *); 14 extern void _cgo_panic(const char *);
15 extern void *_cgo_allocate(size_t);
12 16
13 void 17 void
14 callPanic(void) 18 callPanic(void)
15 { 19 {
16 _cgo_panic("panic from C"); 20 _cgo_panic("panic from C");
17 } 21 }
22
23 /* Test calling cgo_allocate from C. This is what SWIG does. */
24
25 typedef struct List List;
26 struct List
27 {
28 List *next;
29 int x;
30 };
31
32 void
33 callCgoAllocate(void)
34 {
35 int i;
36 List *l, *head, **tail;
37 ········
38 // Make sure this doesn't crash.
39 // And make sure it returns non-nil.
40 if(_cgo_allocate(0) == 0) {
41 fprintf(stderr, "callCgoAllocate: alloc 0 returned nil\n");
42 exit(2);
43 }
44
45 head = 0;
46 tail = &head;
47 for(i=0; i<100; i++) {
48 l = _cgo_allocate(sizeof *l);
49 l->x = i;
50 l->next = 0;
51 *tail = l;
52 tail = &l->next;
53 }
54 ········
55 gc();
56 ········
57 l = head;
58 for(i=0; i<100; i++) {
59 if(l->x != i) {
60 fprintf(stderr, "callCgoAllocate: lost memory\n");
61 exit(2);
62 }
63 l = l->next;
64 }
65 if(l != 0) {
66 fprintf(stderr, "callCgoAllocate: lost memory\n");
67 exit(2);
68 }
69 }
70
OLDNEW
« no previous file with comments | « misc/cgo/test/callback_c_gc.c ('k') | misc/cgo/test/cgo_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b