@@ -19,8 +19,10 @@ private
1919 debug (PRINTF ) import core.stdc.stdio ;
2020}
2121
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.
2426 */
2527extern (C ) void [] _d_arrayassign(TypeInfo ti, void [] from, void [] to)
2628{
@@ -40,15 +42,44 @@ extern (C) void[] _d_arrayassign(TypeInfo ti, void[] from, void[] to)
4042}
4143
4244/**
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+ */
5283extern (C ) void [] _d_arrayassign_l(TypeInfo ti, void [] src, void [] dst, void * ptmp)
5384{
5485 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
131162 assert (op == " YzXy" , op);
132163}
133164
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
144166extern (C ) void [] _d_arrayassign_r(TypeInfo ti, void [] src, void [] dst, void * ptmp)
145167{
146168 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
163185}
164186
165187/**
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+ */
169204extern (C ) void * _d_arraysetassign(void * p, void * value, int count, TypeInfo ti)
170205{
171206 void * pstart = p;
0 commit comments