diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-05-16 18:30:46 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-05-16 19:07:45 +0200 |
commit | 5eb9927aae076200bb7ba3f22c33b0a7c97c5643 (patch) | |
tree | f80210439a5d8995ebf189bce7f2e141fcb1caec /libphobos/src/std/outbuffer.d | |
parent | 682e587f1021241758f7dfe0b22651008622a312 (diff) | |
download | gcc-5eb9927aae076200bb7ba3f22c33b0a7c97c5643.zip gcc-5eb9927aae076200bb7ba3f22c33b0a7c97c5643.tar.gz gcc-5eb9927aae076200bb7ba3f22c33b0a7c97c5643.tar.bz2 |
d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.
D front-end changes:
- Import dmd v2.100.0.
- Add bit fields to D, enabled via the -fpreview=bitfields switch.
- Removed the -ftransition=markdown and -frevert=markdown switches.
- Added new trait `__traits(classInstanceAlignment)' to provide the
required data alignment for classes.
- The check for `pragma(crt_constructor)' and `pragma(crt_destructor)'
linkage has been relaxed to allow all `void()' signatures.
- ImportC parser now recognizes the `typeof(...)' operator.
D runtime changes:
- Import druntime v2.100.0.
Phobos changes:
- Import phobos v2.100.0.
- To comply with dip1000, `std.socket.Socket` methods now accept only
`scope' arrays.
- The `fill', `alignSize', `align2', and `align4' methods of
`std.outbuffer.OutBuffer' have been extended to allow specifying a custom
value when pre-filling or padding the buffer.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 60bfa0ee7.
* dmd/VERSION: Update version to v2.100.0.
* d-builtins.cc (d_init_versions): Update for new front-end interface.
* d-codegen.cc (d_decl_context): Use resolvedLinkage to get
declaration linkage.
(build_struct_literal): Track offset in bits.
* d-gimplify.cc (d_gimplify_modify_expr): Check both operands for a
bit-field reference.
* d-lang.cc (d_handle_option): Handle -fpreview=bitfields, remove
-frevert=markdown and -ftransition=vmarkdown.
(d_post_options): Set flag_rtti and flag_exceptions if -fno-druntime
was seen on command-line.
(d_parse_file): Update for new front-end interface.
(d_type_promotes_to): Use resolvedLinkage to get declaration linkage.
* decl.cc (make_thunk): Likewise.
* expr.cc (ExprVisitor::visit (CatAssignExp *)): Remove lowering for
appending of an element or array to another array.
* lang.opt (fpreview=bitfields): New option.
(frevert=markdown): Remove.
(ftransition=vmarkdown): Remove.
* types.cc (layout_aggregate_members): Ignore anonymous fields in
total count.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime 94bd5bcb.
* libdruntime/Makefile.am (ALL_DRUNTIME_INSTALL_DSOURCES): Add
$(DRUNTIME_DSOURCES_ELF).
(ALL_DRUNTIME_SOURCES): Likewise.
(DRUNTIME_DSOURCES_ELF): New variable.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 3a1cd9a01.
* testsuite/libphobos.init_fini/custom_gc.d: Update test.
Diffstat (limited to 'libphobos/src/std/outbuffer.d')
-rw-r--r-- | libphobos/src/std/outbuffer.d | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/libphobos/src/std/outbuffer.d b/libphobos/src/std/outbuffer.d index c434481..92af9a9 100644 --- a/libphobos/src/std/outbuffer.d +++ b/libphobos/src/std/outbuffer.d @@ -173,21 +173,40 @@ class OutBuffer } /**************************************** - * Append nbytes of 0 to the internal buffer. + * Append nbytes of val to the internal buffer. + * Params: + * nbytes = Number of bytes to fill. + * val = Value to fill, defaults to 0. */ - void fill0(size_t nbytes) + void fill(size_t nbytes, ubyte val = 0) { reserve(nbytes); - data[offset .. offset + nbytes] = 0; + data[offset .. offset + nbytes] = val; offset += nbytes; } + /**************************************** + * Append nbytes of 0 to the internal buffer. + * Param: + * nbytes - number of bytes to fill. + */ + void fill0(size_t nbytes) + { + fill(nbytes); + } + /********************************** - * 0-fill to align on power of 2 boundary. + * Append bytes until the buffer aligns on a power of 2 boundary. + * + * By default fills with 0 bytes. + * + * Params: + * alignsize = Alignment value. Must be power of 2. + * val = Value to fill, defaults to 0. */ - void alignSize(size_t alignsize) + void alignSize(size_t alignsize, ubyte val = 0) in { assert(alignsize && (alignsize & (alignsize - 1)) == 0); @@ -200,7 +219,35 @@ class OutBuffer { auto nbytes = offset & (alignsize - 1); if (nbytes) - fill0(alignsize - nbytes); + fill(alignsize - nbytes, val); + } + /// + @safe unittest + { + OutBuffer buf = new OutBuffer(); + buf.write(cast(ubyte) 1); + buf.align2(); + assert(buf.toBytes() == "\x01\x00"); + buf.write(cast(ubyte) 2); + buf.align4(); + assert(buf.toBytes() == "\x01\x00\x02\x00"); + buf.write(cast(ubyte) 3); + buf.alignSize(8); + assert(buf.toBytes() == "\x01\x00\x02\x00\x03\x00\x00\x00"); + } + /// ditto + @safe unittest + { + OutBuffer buf = new OutBuffer(); + buf.write(cast(ubyte) 1); + buf.align2(0x55); + assert(buf.toBytes() == "\x01\x55"); + buf.write(cast(ubyte) 2); + buf.align4(0x55); + assert(buf.toBytes() == "\x01\x55\x02\x55"); + buf.write(cast(ubyte) 3); + buf.alignSize(8, 0x55); + assert(buf.toBytes() == "\x01\x55\x02\x55\x03\x55\x55\x55"); } /// Clear the data in the buffer @@ -211,23 +258,27 @@ class OutBuffer /**************************************** * Optimize common special case alignSize(2) + * Params: + * val = Value to fill, defaults to 0. */ - void align2() + void align2(ubyte val = 0) { if (offset & 1) - write(cast(byte) 0); + write(cast(byte) val); } /**************************************** * Optimize common special case alignSize(4) + * Params: + * val = Value to fill, defaults to 0. */ - void align4() + void align4(ubyte val = 0) { if (offset & 3) { auto nbytes = (4 - offset) & 3; - fill0(nbytes); + fill(nbytes, val); } } |