@@ -19,8 +19,10 @@ private
19
19
debug (PRINTF ) import core.stdc.stdio ;
20
20
}
21
21
22
- /**
23
- * Keep for backward binary compatibility. This function can be removed in the future.
22
+ /*
23
+ * Superseded array assignment hook. Does not take into account destructors:
24
+ * https://issues.dlang.org/show_bug.cgi?id=13661
25
+ * Kept for backward binary compatibility. This function can be removed in the future.
24
26
*/
25
27
extern (C ) void [] _d_arrayassign(TypeInfo ti, void [] from, void [] to)
26
28
{
@@ -40,15 +42,44 @@ extern (C) void[] _d_arrayassign(TypeInfo ti, void[] from, void[] to)
40
42
}
41
43
42
44
/**
43
- * Does array assignment (not construction) from another
44
- * lvalue array of the same element type.
45
- * Handles overlapping copies.
46
- * Input:
47
- * ti TypeInfo of the element type.
48
- * dst Points target memory. Its .length is equal to the element count, not byte length.
49
- * src Points source memory. Its .length is equal to the element count, not byte length.
50
- * ptmp Temporary memory for element swapping.
51
- */
45
+ Does array assignment (not construction) from another array of the same
46
+ element type.
47
+
48
+ Handles overlapping copies.
49
+
50
+ The `_d_arrayassign_l` variant assumes the right hand side is an lvalue,
51
+ while `_d_arrayassign_r` assumes it's an rvalue, which means it doesn't have to call copy constructors.
52
+
53
+ Used for static array assignment with non-POD element types:
54
+ ---
55
+ struct S
56
+ {
57
+ ~this() {} // destructor, so not Plain Old Data
58
+ }
59
+
60
+ void main()
61
+ {
62
+ S[3] arr;
63
+ S[3] lvalue;
64
+
65
+ arr = lvalue;
66
+ // Generates:
67
+ // S _tmp;
68
+ // _d_arrayassign_l(typeid(S), (cast(void*) lvalue.ptr)[0..lvalue.length], (cast(void*) arr.ptr)[0..arr.length], & _tmp);
69
+
70
+ S[3] getRvalue() {return lvalue;}
71
+ arr = getRvalue();
72
+ // Similar, but `_d_arrayassign_r`
73
+ }
74
+ ---
75
+
76
+ Params:
77
+ ti = `TypeInfo` of the array element type.
78
+ dst = target memory. Its `.length` is equal to the element count, not byte length.
79
+ src = source memory. Its `.length` is equal to the element count, not byte length.
80
+ ptmp = Temporary memory for element swapping, must have capacity of `ti.tsize` bytes.
81
+ Returns: `dst`
82
+ */
52
83
extern (C ) void [] _d_arrayassign_l(TypeInfo ti, void [] src, void [] dst, void * ptmp)
53
84
{
54
85
debug (PRINTF ) printf(" _d_arrayassign_l(src = %p,%d, dst = %p,%d) size = %d\n " , src.ptr, src.length, dst.ptr, dst.length, ti.tsize);
@@ -131,16 +162,7 @@ unittest // Bugzilla 14024
131
162
assert (op == " YzXy" , op);
132
163
}
133
164
134
- /**
135
- * Does array assignment (not construction) from another
136
- * rvalue array of the same element type.
137
- * Input:
138
- * ti TypeInfo of the element type.
139
- * dst Points target memory. Its .length is equal to the element count, not byte length.
140
- * src Points source memory. Its .length is equal to the element count, not byte length.
141
- * It is always allocated on stack and never overlapping with dst.
142
- * ptmp Temporary memory for element swapping.
143
- */
165
+ // / ditto
144
166
extern (C ) void [] _d_arrayassign_r(TypeInfo ti, void [] src, void [] dst, void * ptmp)
145
167
{
146
168
debug (PRINTF ) printf(" _d_arrayassign_r(src = %p,%d, dst = %p,%d) size = %d\n " , src.ptr, src.length, dst.ptr, dst.length, ti.tsize);
@@ -163,9 +185,22 @@ extern (C) void[] _d_arrayassign_r(TypeInfo ti, void[] src, void[] dst, void* pt
163
185
}
164
186
165
187
/**
166
- * Do assignment to an array.
167
- * p[0 .. count] = value;
168
- */
188
+ Set all elements of an array to a single value.
189
+
190
+ ---
191
+ p[0 .. count] = value;
192
+ ---
193
+
194
+ Takes into account postblits and destructors, for Plain Old Data elements,
195
+ `rt/memset.d` is used.
196
+
197
+ Params:
198
+ p = pointer to start of array
199
+ value = bytes of the element to set. Size is derived from `ti`.
200
+ count = amount of array elements to set
201
+ ti = type info of the array element type / `value`
202
+ Returns: `p`
203
+ */
169
204
extern (C ) void * _d_arraysetassign(void * p, void * value, int count, TypeInfo ti)
170
205
{
171
206
void * pstart = p;
0 commit comments