go-unsafe-pointer.c 2.97 KB
Newer Older
1 2 3 4 5 6 7 8
/* go-unsafe-pointer.c -- unsafe.Pointer type descriptor for Go.

   Copyright 2009 The Go Authors. All rights reserved.
   Use of this source code is governed by a BSD-style
   license that can be found in the LICENSE file.  */

#include <stddef.h>

9
#include "runtime.h"
10 11 12 13 14 15 16 17
#include "go-type.h"

/* This file provides the type descriptor for the unsafe.Pointer type.
   The unsafe package is defined by the compiler itself, which means
   that there is no package to compile to define the type
   descriptor.  */

extern const struct __go_type_descriptor unsafe_Pointer
18
  __asm__ (GOSYM_PREFIX "unsafe.Pointer..d");
19

20
extern const byte unsafe_Pointer_gc[]
21
  __asm__ (GOSYM_PREFIX "unsafe.Pointer..g");
22

23 24 25 26 27 28 29 30 31
/* Used to determine the field alignment.  */
struct field_align
{
  char c;
  void *p;
};

/* The reflection string.  */
#define REFLECTION "unsafe.Pointer"
32
static const String reflection_string =
33
{
34
  (const byte *) REFLECTION,
35 36 37
  sizeof REFLECTION - 1
};

38
const byte unsafe_Pointer_gc[] = { 1 };
39

40
extern const FuncVal runtime_pointerhash_descriptor
41
  __asm__ (GOSYM_PREFIX "runtime.pointerhash..f");
42
extern const FuncVal runtime_pointerequal_descriptor
43
  __asm__ (GOSYM_PREFIX "runtime.pointerequal..f");
44

45 46
const struct __go_type_descriptor unsafe_Pointer =
{
47 48 49 50 51 52
  /* __size */
  sizeof (void *),
  /* __ptrdata */
  sizeof (void *),
  /* __hash */
  78501163U,
53
  /* __code */
54
  GO_UNSAFE_POINTER | GO_DIRECT_IFACE,
55 56 57 58 59
  /* __align */
  __alignof (void *),
  /* __field_align */
  offsetof (struct field_align, p) - 1,
  /* __hashfn */
60
  &runtime_pointerhash_descriptor,
61
  /* __equalfn */
62
  &runtime_pointerequal_descriptor,
63
  /* __gcdata */
64
  unsafe_Pointer_gc,
65 66 67
  /* __reflection */
  &reflection_string,
  /* __uncommon */
68 69
  NULL,
  /* __pointer_to_this */
70
  NULL
71 72 73 74 75 76 77
};

/* We also need the type descriptor for the pointer to unsafe.Pointer,
   since any package which refers to that type descriptor will expect
   it to be defined elsewhere.  */

extern const struct __go_ptr_type pointer_unsafe_Pointer
78
  __asm__ (GOSYM_PREFIX "type...1unsafe.Pointer");
79 80 81

/* The reflection string.  */
#define PREFLECTION "*unsafe.Pointer"
82
static const String preflection_string =
83
{
84
  (const byte *) PREFLECTION,
85 86 87
  sizeof PREFLECTION - 1,
};

88
extern const byte pointer_unsafe_Pointer_gc[]
89
  __asm__ (GOSYM_PREFIX "type...1unsafe.Pointer..g");
90

91
const byte pointer_unsafe_Pointer_gc[] = { 1 };
92

93 94 95 96
const struct __go_ptr_type pointer_unsafe_Pointer =
{
  /* __common */
  {
97 98 99 100 101 102
    /* __size */
    sizeof (void *),
    /* __ptrdata */
    sizeof (void *),
    /* __hash */
    1256018616U,
103
    /* __code */
104
    GO_PTR | GO_DIRECT_IFACE,
105 106 107 108 109
    /* __align */
    __alignof (void *),
    /* __field_align */
    offsetof (struct field_align, p) - 1,
    /* __hashfn */
110
    &runtime_pointerhash_descriptor,
111
    /* __equalfn */
112
    &runtime_pointerequal_descriptor,
113
    /* __gcdata */
114
    pointer_unsafe_Pointer_gc,
115 116 117
    /* __reflection */
    &preflection_string,
    /* __uncommon */
118 119
    NULL,
    /* __pointer_to_this */
120
    NULL
121 122 123 124
  },
  /* __element_type */
  &unsafe_Pointer
};