PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/go/goruntime.swg

#
Unknown | 138 lines | 105 code | 33 blank | 0 comment | 0 complexity | 4ef904a0af4f9f57340db6f73fe9f069 MD5 | raw file
  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
 12typedef struct { char *p; int n; } _gostring_;
 13typedef 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
 25swiggo_size_assert(char, 1)
 26swiggo_size_assert(short, 2)
 27swiggo_size_assert(int, 4)
 28typedef long long swiggo_long_long;
 29swiggo_size_assert(swiggo_long_long, 8)
 30swiggo_size_assert(float, 4)
 31swiggo_size_assert(double, 8)
 32
 33#ifdef __cplusplus
 34extern "C" {
 35#endif
 36extern void crosscall2(void (*fn)(void *, int), void *, int);
 37extern void _cgo_allocate(void *, int);
 38extern void _cgo_panic(void *, int);
 39#ifdef __cplusplus
 40}
 41#endif
 42
 43static void *_swig_goallocate(size_t len) {
 44  struct {
 45    size_t len;
 46    void *ret;
 47  } a;
 48  a.len = len;
 49  crosscall2(_cgo_allocate, &a, (int) sizeof a);
 50  return a.ret;
 51}
 52
 53static void _swig_gopanic(const char *p) {
 54  struct {
 55    const char *p;
 56  } a;
 57  a.p = p;
 58  crosscall2(_cgo_panic, &a, (int) sizeof a);
 59}
 60
 61%}
 62
 63/* Boilerplate for C code when using 6g/8g.  This code is compiled
 64   with 6c/8c.  */
 65%insert(gc_header) %{
 66#include "runtime.h"
 67#include "cgocall.h"
 68
 69#ifdef _64BIT
 70#define SWIG_PARM_SIZE 8
 71#else
 72#define SWIG_PARM_SIZE 4
 73#endif
 74%}
 75
 76#else
 77
 78/* Boilerplate for C/C++ code when using gccgo.  */
 79%insert(runtime) %{
 80#define SWIGGO_GCCGO
 81
 82#ifdef __cplusplus
 83extern "C" {
 84#endif
 85extern void *_cgo_allocate(size_t);
 86extern void _cgo_panic(const char *);
 87#ifdef __cplusplus
 88}
 89#endif
 90
 91#define _swig_goallocate _cgo_allocate
 92#define _swig_gopanic _cgo_panic
 93
 94%}
 95
 96#endif
 97
 98%insert(runtime) %{
 99
100static _gostring_ _swig_makegostring(const char *p, size_t l) {
101  _gostring_ ret;
102  ret.p = (char*)_swig_goallocate(l + 1);
103  memcpy(ret.p, p, l);
104  ret.n = l;
105  return ret;
106}
107
108#define SWIG_contract_assert(expr, msg) \
109  if (!(expr)) { _swig_gopanic(msg); } else
110%}
111
112#ifndef SWIGGO_GCCGO
113
114%insert(go_header) %{
115
116import _ "runtime/cgo"
117
118%}
119
120#else
121
122%insert(go_header) %{
123
124import "syscall"
125
126type _ syscall.Sockaddr
127
128%}
129
130#endif
131
132/* Function pointers are translated by the code in go.cxx into
133   _swig_fnptr.  Member pointers are translated to _swig_memberptr.  */
134
135%insert(go_header) %{
136type _swig_fnptr *byte
137type _swig_memberptr *byte
138%}