Commit graph

9331 commits

Author SHA1 Message Date
Matt Kline
d24b738ccc Clean up Unique alias this 2015-04-17 00:32:05 -07:00
Matt Kline
836c55197e Do not let Unique escape underlying references
See https://github.com/D-Programming-Language/phobos/pull/3139#discussion-diff-28203345
2015-04-17 00:24:22 -07:00
Matt Kline
e112ec9b7f Return Unique to malloc/free
Marking its various bits as @nogc is still proving to be a challenge
since Object.destroy is not @nogc, among other things.

We _are_ using GC.addRange and GC.removeRange to handle anything
inside the underlying type that uses GC.
Why the user would do this in conjunction with Unique is
questionable, but until we can explicitly forbid doing so, let's
not break garbage collection for them.

Note that this also makes nested structs and classes impossible,
because there is no way AFAIK to get the frame pointer into
unique()
2015-04-16 23:58:28 -07:00
Matt Kline
c5605bf2c8 Turn Unique.create into a freestanding unique()
Also cleaned up the Unique documentation a bit.
Unfortunately some of the unittests could not be used as documented
unittests because placing them in the struct gives an error about
RTInfo!(Nested) being recursvely expanded.
2015-04-13 00:04:00 -07:00
Matt Kline
dba6bd5464 Revamp and cleanup of Unique
From the related pull request
(https://github.com/D-Programming-Language/phobos/pull/3139),
there seems to be a general consensus that it is more important to
do Unique "right", even if that means breaking changes, so long as
there is a clean migration path. With that in mind, I have made the
following additional changes:

- Instead of constructors that take a RefT, Uniques can now be
  created one of two ways: via .create or .fromNested.
  See the DDocs of both for details.

- opDot is replaced with "alias _p this". A cursorty Google search
  indicates that opDot is deprecated and that alias this is the
  preferred method. Like C++'s unique_ptr, Unique now enjoys
  pointer-like operations (such as dereferencing),
  but cannot be set to null or assigned from a different pointer
  due to opAssign and the disabled postblit constructor.

- Consequently, isEmpty has been removed. Instead, just use
  is null as you would with a pointer.

- Removal of redundant unit tests

- Various comment and unit test cleanup
2015-04-06 23:25:23 -07:00
Matt Kline
b3c94c26d1 Make Unique use the GC again
It is currently impossible (or so it seems) to use malloc and
emplace to create a nested class or struct, so we'll return to
using the GC for now. We'll also restore the constructors that take
a RefT, as using new _inside_ the context of the nested class or
struct is apparently the only way to create one currently.
2015-04-05 15:44:02 -07:00
Matt Kline
6d42be9fdd Use class version of std.conv.emplace for Unique
I picked up the trick of converting a pointer into an array
using the [0 .. size] syntax from std/regex/package.d.

Unique.create is still segfaulting, but this seems to be an issue
with the class version of emplace regardless of this Unique work.
The bug can be found here:
https://issues.dlang.org/show_bug.cgi?id=14402
2015-04-03 01:29:23 -07:00
Matt Kline
a5150a043b Fix outOfMemoryError import 2015-04-03 00:57:12 -07:00
Matt Kline
db544d55d5 Issue onOutOfMemoryError on bad malloc in Unique 2015-04-03 00:45:23 -07:00
Matt Kline
f6994ea02f Improve std.typecons.Unique
Whenever D is brought up to the general programming public,
the garbage collector is quickly raised as a point of contention.
Regardless of how legitimate or well-informed these concerns are,
it would be a massive public relations boon --- and great for the language,
to boot --- if we could trot out a solid said of RAII-based smart pointers
for those who prefer to use them. We have a solid start in
std.typecons.Unique and std.typecons.RefCounted.
Unfortunately, these classes seem to be victims of bit rot and
compiler bugs of days long gone.

An overview of the changes in this commit is as follows:

- Unique's underlying data now uses malloc and free
  instead of the garbage collector. Given that many people use RAII
  smart pointers to escape the GC, it seems to make more sense to
  avoid it here. On a related note, isn't delete deprecated?
  The current destructor uses it.

- std.algorithm.move is used instead of a special release
  member function. Whether by design or by happy accident,
  move transfers ownership between Unique pointers in a very
  similar manner to C++'s std::move with std::unique_ptr.
  Along with being a familiar paradigm to C++ users,
  using move to transfer ownership makes more intuitive sense
  and builds consistency with the rest of Phobos.

- With std.algorithm.move transferring ownership, release now just
  frees the underlying pointer and nulls the Unique.

- Unique.create is no longer compiled out using version(None).
  Regardless of whether or not there is language support for
  checking uniqueness, a utility function that creates a Unique,
  taking the same arguments as the underlying type's constructor,
  is extremely useful, as demonstrated by the addition of
  make_unique to C++14.

- Because Unique.create is now in place and Unique is backed with
  malloc, constructors taking a pointer have been removed.
  This encourages the use of create as the idiomatic,
  consistent method to, well, create Unique objects.
  If one can only get a Unique by calling create or moving another
  into it, we also ensures uniqueness in one fell swoop.

- A new method, get, returns the underlying pointer, for use in
  functions and code that do not play a role in the life cycle
  of the object. Smart pointers are as much about ownership
  semantics as they are about allocating and freeing memory,
  and non-owning code should continue to refer to data using a raw
  pointer or a reference.
2015-04-02 01:17:40 -07:00
Andrei Alexandrescu
bfda092892 Merge pull request #3120 from WalterBright/rmtoLower
remove broken links to std.string.toLower etc.
2015-03-28 21:33:42 -07:00
Walter Bright
35cf4efb4d remove broken links to std.string.toLower etc. 2015-03-28 16:12:11 -07:00
Robert Schadek
4974f90d3a Merge pull request #3116 from WalterBright/improve-wrap
improve efficiency and testing of std.string.wrap
2015-03-28 14:32:01 +01:00
Robert Schadek
9cf5bacfb8 Merge pull request #3115 from todayman/typos
Typo & grammar fixes
2015-03-28 13:07:18 +01:00
Robert Schadek
382a1db4bf Merge pull request #3113 from WalterBright/column-range
upgrade std.string.column to handle ranges and nelSep
2015-03-28 02:50:18 +01:00
Walter Bright
c1014ca42d improve efficiency and testing of std.string.wrap 2015-03-27 18:40:43 -07:00
Paul O'Neil
ce690fe6e3 Typo & grammar fixes 2015-03-27 21:15:46 -04:00
Walter Bright
466773dc69 upgrade std.string.column to handle ranges and nelSep 2015-03-27 12:52:07 -07:00
H. S. Teoh
20e62954d3 Merge pull request #3100 from MetaLang/proxy-doc-fixes
Improve documentation for std.typecons.Proxy
2015-03-27 10:09:43 -07:00
H. S. Teoh
f5383ba539 Merge pull request #3110 from WalterBright/column-doc
improve doc for std.string.column
2015-03-26 16:44:12 -07:00
H. S. Teoh
8ee432ad0f Merge pull request #3111 from WalterBright/NEL
add nelSep
2015-03-26 16:08:46 -07:00
Walter Bright
c5b77ee5ea improve doc for std.string.column 2015-03-26 16:05:25 -07:00
Walter Bright
9675a1cee8 add nelSep 2015-03-26 15:16:44 -07:00
Robert Schadek
9e4dcb0a01 Merge pull request #3101 from MetaLang/tuple-doc-more-fixes
Further improvements for Tuple's documentation
2015-03-26 21:17:28 +01:00
MetaLang
749cc5ca51 Further improvements for Tuple's documentation 2015-03-26 15:54:05 -03:00
Daniel Murphy
283374b78c Merge pull request #3108 from WalterBright/outdent-doc
improve doc for std.string.outdent()
2015-03-26 21:56:58 +11:00
Walter Bright
13ec656ee9 improve doc for std.string.outdent() 2015-03-26 00:12:16 -07:00
Daniel Murphy
8340a413cf Merge pull request #3107 from WalterBright/assumeUTF-doc
improve doc for std.string.assumeUTF
2015-03-26 13:46:23 +11:00
H. S. Teoh
76aec006f6 Merge pull request #3105 from burner/logger_constraint_fix
std.logger defaultLogFunction constraint fix
2015-03-25 18:49:48 -07:00
Walter Bright
d636933656 improve doc for std.string.assumeUTF 2015-03-25 18:10:41 -07:00
H. S. Teoh
bcf0fcecac Merge pull request #3102 from MetaLang/rebindable-add-params
Improve Rebindable documentation
2015-03-25 17:29:19 -07:00
H. S. Teoh
ccccf0f8cf Merge pull request #3104 from MetaLang/alignforsize-doc-fixes
Improve alignForSize Documentation
2015-03-25 16:30:36 -07:00
Robert burner Schadek
0c3fb67ff8 std.logger defaultLogFunction constraint fix
* the defaultLogFunctions were not callable with zero arguments
2015-03-25 23:33:16 +01:00
Robert Schadek
ebb2b8ce5d Merge pull request #2999 from MartinNowak/fix14194
fix Issue 14194 - nothrow emplace for classes needed
2015-03-25 12:40:52 +01:00
Robert Schadek
876900d1f8 Merge pull request #3086 from WalterBright/iota-example
add illuminating example to std.range.iota
2015-03-25 11:43:20 +01:00
Walter Bright
e9b6c84f99 add illuminating example to std.range.iota 2015-03-24 21:11:11 -07:00
Vladimir Panteleev
33b20be7b3 Merge pull request #3103 from MetaLang/unqualref-doc-fixes
[Trivial] Add Params section to UnqualRef documentation
2015-03-25 00:19:25 +00:00
MetaLang
71a074d5cb Add Params section to UnqualRef documentation 2015-03-24 21:18:05 -03:00
MetaLang
c67867360d Improve documentation for std.typecons.Proxy 2015-03-24 21:06:42 -03:00
MetaLang
a75afe241d Improve alignForSize Documentation 2015-03-24 06:49:02 -03:00
MetaLang
65921b7739 Improve Rebindable documentation 2015-03-24 06:36:34 -03:00
Andrei Alexandrescu
f77b38705b Merge pull request #3098 from schveiguy/fixreadlnmem
Make sure the free'd lineptr doesn't leave a dangling pointer.
2015-03-23 20:31:59 -07:00
Steven Schveighoffer
5f1ab79717 Make sure the free'd lineptr doesn't leave a dangling pointer. 2015-03-23 21:30:54 -04:00
JakobOvrum
f9c309feb4 Merge pull request #3083 from rainers/win32coff_fix_unittest
Win32 COFF: fix std.process unittests
2015-03-24 02:00:26 +01:00
Robert Schadek
26d8a7154e Merge pull request #3095 from quickfur/getopt_docs
[Trivial] Add missing comma in std.getopt code example.
2015-03-23 20:33:37 +01:00
H. S. Teoh
b34307abef [Trivial] Add missing comma in std.getopt code example. 2015-03-23 11:52:46 -07:00
Martin Nowak
73b24264da Merge pull request #3089 from andralex/byLine
3x faster byLine implementation on OSX, probably faster on Linux as well
2015-03-23 16:08:36 +01:00
David Nadlinger
ec62f933ab Merge pull request #3068 from burner/algo_cmp_castSwitch
std.algo.cmp.castSwitch docu
2015-03-23 09:44:50 +01:00
Andrei Alexandrescu
37a88bfcf9 Merge pull request #3077 from burner/algo_cmp_max
std.algo.cmp.max docu
2015-03-22 22:54:08 -07:00
Andrei Alexandrescu
27fc16df0d Merge pull request #3065 from burner/algorithm_comparision_dscanner_suggestions
algorithm_comparison maintenance
2015-03-22 22:53:07 -07:00