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

Side by Side Diff: src/pkg/runtime/slice.goc

Issue 116940043: code review 116940043: runtime: pass correct size to malloc (Closed)
Patch Set: diff -r e1d0077340e8 https://dvyukov%40google.com@code.google.com/p/go/ Created 9 years, 8 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 | « src/pkg/runtime/panic.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 package runtime 5 package runtime
6 #include "runtime.h" 6 #include "runtime.h"
7 #include "arch_GOARCH.h" 7 #include "arch_GOARCH.h"
8 #include "type.h" 8 #include "type.h"
9 #include "typekind.h" 9 #include "typekind.h"
10 #include "malloc.h" 10 #include "malloc.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } while(newcap1 < newcap); 115 } while(newcap1 < newcap);
116 } 116 }
117 117
118 if(newcap1 > MaxMem/typ->size) 118 if(newcap1 > MaxMem/typ->size)
119 runtime·panicstring("growslice: cap out of range"); 119 runtime·panicstring("growslice: cap out of range");
120 capmem = runtime·roundupsize(newcap1*typ->size); 120 capmem = runtime·roundupsize(newcap1*typ->size);
121 flag = 0; 121 flag = 0;
122 // Can't use FlagNoZero w/o FlagNoScan, because otherwise GC can scan un itialized memory. 122 // Can't use FlagNoZero w/o FlagNoScan, because otherwise GC can scan un itialized memory.
123 if(typ->kind&KindNoPointers) 123 if(typ->kind&KindNoPointers)
124 flag = FlagNoScan|FlagNoZero; 124 flag = FlagNoScan|FlagNoZero;
125 ret->array = runtime·mallocgc(capmem, (uintptr)typ|TypeInfo_Array, flag) ;
126 ret->len = x.len; 125 ret->len = x.len;
127 ret->cap = capmem/typ->size; 126 ret->cap = capmem/typ->size;
127 capmem = ret->cap*typ->size;
dfc 2014/07/21 10:26:04 I think this needs a short comment to explain how
dvyukov 2014/07/21 12:14:50 Done.
128 ret->array = runtime·mallocgc(capmem, (uintptr)typ|TypeInfo_Array, flag) ;
128 lenmem = x.len*typ->size; 129 lenmem = x.len*typ->size;
129 runtime·memmove(ret->array, x.array, lenmem); 130 runtime·memmove(ret->array, x.array, lenmem);
130 if(typ->kind&KindNoPointers) 131 if(typ->kind&KindNoPointers)
131 runtime·memclr(ret->array+lenmem, capmem-lenmem); 132 runtime·memclr(ret->array+lenmem, capmem-lenmem);
132 } 133 }
133 134
134 #pragma textflag NOSPLIT 135 #pragma textflag NOSPLIT
135 func copy(to Slice, fm Slice, width uintptr) (ret int) { 136 func copy(to Slice, fm Slice, width uintptr) (ret int) {
136 void *pc; 137 void *pc;
137 138
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 196 }
196 197
197 func printslice(a Slice) { 198 func printslice(a Slice) {
198 runtime·prints("["); 199 runtime·prints("[");
199 runtime·printint(a.len); 200 runtime·printint(a.len);
200 runtime·prints("/"); 201 runtime·prints("/");
201 runtime·printint(a.cap); 202 runtime·printint(a.cap);
202 runtime·prints("]"); 203 runtime·prints("]");
203 runtime·printpointer(a.array); 204 runtime·printpointer(a.array);
204 } 205 }
OLDNEW
« no previous file with comments | « src/pkg/runtime/panic.c ('k') | no next file » | no next file with comments »

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