~laney/ubuntu/quantal/swig2.0/guile-2.0

« back to all changes in this revision

Viewing changes to Lib/go/goruntime.swg

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2010-12-19 18:25:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101219182559-8lh77o66bo890jwo
Tags: 2.0.1-1
* Merge new upstream release 2.0.1.
* Remove dependency on quilt and usage in debian/rules, the new source
  format will take care of that.
* Remove patch fix-cleaning.diff (applied upstream).
* Remove patch keep_docs.diff (applied upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ------------------------------------------------------------
 
2
 * goruntime.swg
 
3
 *
 
4
 * Go runtime code for the various generated files.
 
5
 * ------------------------------------------------------------ */
 
6
 
 
7
%insert(runtime) %{
 
8
#include <stdio.h>
 
9
#include <stdlib.h>
 
10
#include <string.h>
 
11
 
 
12
typedef struct { char *p; int n; } _gostring_;
 
13
typedef struct { void* array; unsigned int len; unsigned int cap; } _goslice_;
 
14
 
 
15
%}
 
16
 
 
17
#ifndef SWIGGO_GCCGO
 
18
/* Boilerplate for C/C++ code when using 6g/8g.  This code is compiled
 
19
   with gcc.  */
 
20
%insert(runtime) %{
 
21
 
 
22
#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
 
23
#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n)
 
24
 
 
25
swiggo_size_assert(char, 1)
 
26
swiggo_size_assert(short, 2)
 
27
swiggo_size_assert(int, 4)
 
28
typedef long long swiggo_long_long;
 
29
swiggo_size_assert(swiggo_long_long, 8)
 
30
swiggo_size_assert(float, 4)
 
31
swiggo_size_assert(double, 8)
 
32
 
 
33
extern
 
34
#ifdef __cplusplus
 
35
"C"
 
36
#endif
 
37
void crosscall2(void (*fn)(void *, int), void *, int);
 
38
 
 
39
extern
 
40
#ifdef __cplusplus
 
41
"C"
 
42
#endif
 
43
void _swig_gc_allocate(void *, int);
 
44
static void *_swig_allocate(int len) {
 
45
  struct {
 
46
    int len;
 
47
    void *ret;
 
48
  } a;
 
49
  a.len = len;
 
50
  crosscall2(_swig_gc_allocate, &a, (int) sizeof a);
 
51
  return a.ret;
 
52
}
 
53
 
 
54
extern
 
55
#ifdef __cplusplus
 
56
"C"
 
57
#endif
 
58
void _swig_gc_makegostring(void *, int);
 
59
static _gostring_ _swig_makegostring(const char *p, size_t l) {
 
60
  struct {
 
61
    const char *p;
 
62
    int l;
 
63
    _gostring_ ret;
 
64
  } a;
 
65
  a.p = p;
 
66
  a.l = l;
 
67
  crosscall2(_swig_gc_makegostring, &a, (int) sizeof a);
 
68
  return a.ret;
 
69
}
 
70
 
 
71
extern
 
72
#ifdef __cplusplus
 
73
"C"
 
74
#endif
 
75
void _swig_gc_gopanic(void *, int);
 
76
static void _swig_gopanic(const char *p) {
 
77
  struct {
 
78
    const char *p;
 
79
    int l;
 
80
  } a;
 
81
  a.p = p;
 
82
  a.l = strlen(p);
 
83
  crosscall2(_swig_gc_gopanic, &a, (int) sizeof a);
 
84
}
 
85
 
 
86
%}
 
87
 
 
88
/* Boilerplate for C code when using 6g/8g.  This code is compiled
 
89
   with 6c/8c.  */
 
90
%insert(gc_header) %{
 
91
#include "runtime.h"
 
92
#include "cgocall.h"
 
93
 
 
94
#pragma dynimport initcgo initcgo "libcgo.so"
 
95
#pragma dynimport libcgo_thread_start libcgo_thread_start "libcgo.so"
 
96
#pragma dynimport libcgo_set_scheduler libcgo_set_scheduler "libcgo.so"
 
97
 
 
98
#ifdef _64BIT
 
99
#define SWIG_PARM_SIZE 8
 
100
#else
 
101
#define SWIG_PARM_SIZE 4
 
102
#endif
 
103
%}
 
104
 
 
105
/* 6g/8g C boilerplate that is only needed once in a program.  This
 
106
   only gets added to the file if nothing is imported.  */
 
107
%insert(gc_once) %{
 
108
 
 
109
extern void ·_swig_internal_allocate(void);
 
110
#pragma dynexport _swig_gc_allocate _swig_gc_allocate
 
111
void _swig_gc_allocate(void *a, int32 n) {
 
112
        cgocallback(·_swig_internal_allocate, a, n);
 
113
}
 
114
 
 
115
void ·_swig_allocatememory(int32 len, byte *ret) {
 
116
        ret = mal(len);
 
117
        FLUSH(&ret);
 
118
}
 
119
 
 
120
extern void ·_swig_internal_makegostring(void);
 
121
#pragma dynexport _swig_gc_makegostring _swig_gc_makegostring
 
122
void _swig_gc_makegostring(void *a, int32 n) {
 
123
        cgocallback(·_swig_internal_makegostring, a, n);
 
124
}
 
125
 
 
126
void ·_swig_allocatestring(byte *p, int32 l, String ret) {
 
127
        ret.str = mal(l+1);
 
128
        mcpy(ret.str, p, l);
 
129
        ret.len = l;
 
130
        FLUSH(&ret);
 
131
}
 
132
 
 
133
extern void ·_swig_internal_gopanic(void);
 
134
#pragma dynexport _swig_gc_gopanic _swig_gc_gopanic
 
135
void _swig_gc_gopanic(void *a, int32 n) {
 
136
        cgocallback(·_swig_internal_gopanic, a, n);
 
137
}
 
138
 
 
139
%}
 
140
 
 
141
/* Go code that is only needed once in a program.  This is only added
 
142
   to the file if nothing is imported.  */
 
143
%insert(go_once) %{
 
144
func _swig_allocatememory(int) *byte
 
145
func _swig_internal_allocate(len int) *byte {
 
146
        return _swig_allocatememory(len)
 
147
}
 
148
 
 
149
func _swig_allocatestring(*byte, int) string
 
150
func _swig_internal_makegostring(p *byte, l int) string {
 
151
        return _swig_allocatestring(p, l)
 
152
}
 
153
 
 
154
func _swig_internal_gopanic(p *byte, l int) {
 
155
        panic(_swig_allocatestring(p, l))
 
156
}
 
157
%}
 
158
 
 
159
#else
 
160
 
 
161
/* Boilerplate for C/C++ code when using gccgo.  */
 
162
%insert(runtime) %{
 
163
#define SWIGGO_GCCGO
 
164
 
 
165
extern
 
166
#ifdef __cplusplus
 
167
"C"
 
168
#endif
 
169
void *__go_alloc (size_t);
 
170
 
 
171
static void *_swig_allocate(int len) {
 
172
  return __go_alloc(len);
 
173
}
 
174
 
 
175
static _gostring_ _swig_makegostring(const char *p, size_t l) {
 
176
  _gostring_ ret;
 
177
  ret.p = (char*)__go_alloc(l);
 
178
  memcpy(ret.p, p, l);
 
179
  ret.n = l;
 
180
  return ret;
 
181
}
 
182
 
 
183
extern
 
184
#ifdef __cplusplus
 
185
"C"
 
186
#endif
 
187
void __go_panic_msg(const char *);
 
188
#define _swig_gopanic __go_panic_msg
 
189
 
 
190
%}
 
191
 
 
192
#endif
 
193
 
 
194
%insert(runtime) %{
 
195
#define SWIG_contract_assert(expr, msg) \
 
196
  if (!(expr)) { _swig_gopanic(msg); } else
 
197
%}
 
198