~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/runtime/iface.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include "runtime.h"
6
6
#include "arch_GOARCH.h"
7
7
#include "type.h"
 
8
#include "typekind.h"
8
9
#include "malloc.h"
9
10
 
10
11
void
19
20
        runtime·printf("(%p,%p)", e.type, e.data);
20
21
}
21
22
 
22
 
/*
23
 
 * layout of Itab known to compilers
24
 
 */
25
 
struct Itab
26
 
{
27
 
        InterfaceType*  inter;
28
 
        Type*   type;
29
 
        Itab*   link;
30
 
        int32   bad;
31
 
        int32   unused;
32
 
        void    (*fun[])(void);
33
 
};
34
 
 
35
23
static  Itab*   hash[1009];
36
24
static  Lock    ifacelock;
37
25
 
182
170
                alg->copy(size, dst, *src);
183
171
}
184
172
 
185
 
// func convT2I(typ *byte, typ2 *byte, elem any) (ret any)
186
 
#pragma textflag 7
187
 
void
188
 
runtime·convT2I(Type *t, InterfaceType *inter, ...)
 
173
#pragma textflag 7
 
174
void
 
175
runtime·typ2Itab(Type *t, InterfaceType *inter, Itab **cache, Itab *ret)
 
176
{
 
177
        Itab *tab;
 
178
 
 
179
        tab = itab(inter, t, 0);
 
180
        runtime·atomicstorep(cache, tab);
 
181
        ret = tab;
 
182
        FLUSH(&ret);
 
183
}
 
184
 
 
185
// func convT2I(typ *byte, typ2 *byte, cache **byte, elem any) (ret any)
 
186
#pragma textflag 7
 
187
void
 
188
runtime·convT2I(Type *t, InterfaceType *inter, Itab **cache, ...)
189
189
{
190
190
        byte *elem;
191
191
        Iface *ret;
 
192
        Itab *tab;
192
193
        int32 wid;
193
194
 
194
 
        elem = (byte*)(&inter+1);
 
195
        elem = (byte*)(&cache+1);
195
196
        wid = t->size;
196
 
        ret = (Iface*)(elem + runtime·rnd(wid, Structrnd));
197
 
        ret->tab = itab(inter, t, 0);
 
197
        ret = (Iface*)(elem + ROUND(wid, Structrnd));
 
198
        tab = runtime·atomicloadp(cache);
 
199
        if(!tab) {
 
200
                tab = itab(inter, t, 0);
 
201
                runtime·atomicstorep(cache, tab);
 
202
        }
 
203
        ret->tab = tab;
198
204
        copyin(t, elem, &ret->data);
199
205
}
200
206
 
209
215
 
210
216
        elem = (byte*)(&t+1);
211
217
        wid = t->size;
212
 
        ret = (Eface*)(elem + runtime·rnd(wid, Structrnd));
 
218
        ret = (Eface*)(elem + ROUND(wid, Structrnd));
213
219
        ret->type = t;
214
220
        copyin(t, elem, &ret->data);
215
221
}
272
278
        copyout(t, &i.data, ret);
273
279
}
274
280
 
 
281
void
 
282
runtime·assertI2TOK(Type *t, Iface i, bool ok)
 
283
{
 
284
        ok = i.tab!=nil && i.tab->type==t;
 
285
        FLUSH(&ok);
 
286
}
 
287
 
275
288
static void assertE2Tret(Type *t, Eface e, byte *ret);
276
289
 
277
290
// func ifaceE2T(typ *byte, iface any) (ret any)
328
341
        copyout(t, &e.data, ret);
329
342
}
330
343
 
 
344
void
 
345
runtime·assertE2TOK(Type *t, Eface e, bool ok)
 
346
{
 
347
        ok = t==e.type;
 
348
        FLUSH(&ok);
 
349
}
 
350
 
331
351
// func convI2E(elem any) (ret any)
332
352
void
333
353
runtime·convI2E(Iface i, Eface ret)
387
407
runtime·convI2I(InterfaceType* inter, Iface i, Iface ret)
388
408
{
389
409
        Itab *tab;
390
 
        
 
410
 
391
411
        ret.data = i.data;
392
412
        if((tab = i.tab) == nil)
393
413
                ret.tab = nil;
526
546
}
527
547
 
528
548
static uintptr
529
 
ifacehash1(void *data, Type *t)
 
549
ifacehash1(void *data, Type *t, uintptr h)
530
550
{
531
551
        Alg *alg;
532
 
        uintptr size, h;
 
552
        uintptr size;
533
553
        Eface err;
534
554
 
535
555
        if(t == nil)
543
563
                runtime·newErrorString(runtime·catstring(runtime·gostringnocopy((byte*)"hash of unhashable type "), *t->string), &err);
544
564
                runtime·panic(err);
545
565
        }
546
 
        h = 0;
547
566
        if(size <= sizeof(data))
548
567
                alg->hash(&h, size, &data);
549
568
        else
552
571
}
553
572
 
554
573
uintptr
555
 
runtime·ifacehash(Iface a)
 
574
runtime·ifacehash(Iface a, uintptr h)
556
575
{
557
576
        if(a.tab == nil)
558
 
                return 0;
559
 
        return ifacehash1(a.data, a.tab->type);
 
577
                return h;
 
578
        return ifacehash1(a.data, a.tab->type, h);
560
579
}
561
580
 
562
581
uintptr
563
 
runtime·efacehash(Eface a)
 
582
runtime·efacehash(Eface a, uintptr h)
564
583
{
565
 
        return ifacehash1(a.data, a.type);
 
584
        return ifacehash1(a.data, a.type, h);
566
585
}
567
586
 
568
587
static bool
666
685
}
667
686
 
668
687
void
669
 
reflect·unsafe_New(Eface typ, void *ret)
670
 
{
671
 
        Type *t;
672
 
 
673
 
        // Reflect library has reinterpreted typ
674
 
        // as its own kind of type structure.
675
 
        // We know that the pointer to the original
676
 
        // type structure sits before the data pointer.
677
 
        t = (Type*)((Eface*)typ.data-1);
678
 
 
679
 
        if(t->kind&KindNoPointers)
680
 
                ret = runtime·mallocgc(t->size, FlagNoPointers, 1, 1);
681
 
        else
682
 
                ret = runtime·mal(t->size);
683
 
        FLUSH(&ret);
684
 
}
685
 
 
686
 
void
687
 
reflect·unsafe_NewArray(Eface typ, uint32 n, void *ret)
688
 
{
689
 
        uint64 size;
690
 
        Type *t;
691
 
 
692
 
        // Reflect library has reinterpreted typ
693
 
        // as its own kind of type structure.
694
 
        // We know that the pointer to the original
695
 
        // type structure sits before the data pointer.
696
 
        t = (Type*)((Eface*)typ.data-1);
697
 
        
698
 
        size = n*t->size;
699
 
        if(t->kind&KindNoPointers)
700
 
                ret = runtime·mallocgc(size, FlagNoPointers, 1, 1);
701
 
        else
702
 
                ret = runtime·mal(size);
 
688
reflect·unsafe_New(Type *t, void *ret)
 
689
{
 
690
        ret = runtime·cnew(t);
 
691
        FLUSH(&ret);
 
692
}
 
693
 
 
694
void
 
695
reflect·unsafe_NewArray(Type *t, intgo n, void *ret)
 
696
{
 
697
        ret = runtime·cnewarray(t, n);
 
698
        FLUSH(&ret);
 
699
}
 
700
 
 
701
void
 
702
reflect·typelinks(Slice ret)
 
703
{
 
704
        extern Type *typelink[], *etypelink[];
 
705
        static int32 first = 1;
 
706
        ret.array = (byte*)typelink;
 
707
        ret.len = etypelink - typelink;
 
708
        ret.cap = ret.len;
703
709
        FLUSH(&ret);
704
710
}