www.digitalmars.com         C & C++   DMDScript  

D.gnu - bug: stringz

reply d d.com writes:
If you pass a static char array to toStringz, the post-condition 

assert(strlen(result) == string.length);

maybe violated:


DMD doesn't have this AssertError.

------------------------------------
$ cat strz.d
import std.string;

int main()
{
char[4] buf;
buf[2] = '\000';
toStringz(buf);
return 0;
}

$ gdmd  strz.d
$ ./strz
Error: AssertError Failure std/string.d(230)

$ gdmd
gdc (GCC) 3.3.6 (gdc 0.14, using dmd 0.127)
Copyright (C) 2003 Free Software Foundation, Inc.
Jul 08 2005
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
d d.com wrote:

 DMD doesn't have this AssertError.
That is just because DMD doesn't have *any* contracts enabled in the Phobos library...
 import std.string;
 
 int main()
 {
 char[4] buf;
 buf[2] = '\000';
 toStringz(buf);
 return 0;
 }
The contract of toStringz says: no NUL chars, so that is why it is complaining about this. You can compile libgphobos.a with -release, if you want to avoid the asserts/contracts ? (just like you can recompile libphobos.a without -release, if you do want them ?) Not a bug. --anders
Jul 09 2005
next sibling parent d d.com writes:
 DMD doesn't have this AssertError.

 import std.string;
 
 int main()
 {
 char[4] buf;
 buf[2] = '\000';
 toStringz(buf);
 return 0;
 }
That is just because DMD doesn't have *any* contracts enabled in the Phobos library...
Good to know that. (Cross-post to digitalmars.D.bugs)
The contract of toStringz says: no NUL chars,
..
Not a bug.
Where the contract is said? If in the pre-condition, then I agree. Now it fails in the post-condition, definately a bug. This is a reason I love DbC: everything has to be explicit.
Jul 09 2005
prev sibling parent reply d d.com writes:
You can compile libgphobos.a with -release,
if you want to avoid the asserts/contracts ?
(just like you can recompile libphobos.a
  without -release, if you do want them ?)
I think the default installation should install 2 versions of libphobos.a: -- one optimized version with -release, so all the checking is turned-off for maximal speed. -- one debug version with checking turned-on. I just noticed my programm runs so slow with GDD. After adding -profile option, I found out that 99% (the top 7 entry) of the time is spent on checking (the top 2 takes 98.61% time on invariant): ------------------------------------------------------------------------- Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 75.52 3026.31 3026.31 _D3gcx4Pool11__invariantFZv 23.09 3951.46 925.15 _D3gcx3Gcx11__invariantFZv 0.32 3964.15 12.69 _D9invariant12_d_invariantFC6ObjectZv 0.18 3971.50 7.35 _D3gcx4Pool9InvariantFZv 0.18 3978.81 7.31 _D3gcx3Gcx11fullcollectFPvZk 0.12 3983.57 4.76 _D3gcx4Pool5opCmpFPS3gcx4PoolZi 0.09 3987.20 3.63 _D3gcx3Gcx4markFPvPvZv .. .. ------------------------------------------------------------------------- This is crazy! By any means, please provide two versions of libphobos.a in the default installation! If only one is provided, please install the ***optimized*** version!!! (How many ordinary D programmer would care about the contract inside libphobos.a? how would you expect them to do with it when the contract fails inside libphobos.a?) Otherwise, people will feel bad about D's performance claim! and nobody is going to use it.
Aug 04 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
d d.com wrote:

 I think the default installation should install 2 versions of libphobos.a:
 
 -- one optimized version with -release, so all the checking is turned-off for
 maximal speed.
 
 -- one debug version with checking turned-on.
 
 I just noticed my programm runs so slow with GDD.  After adding -profile
option,
 I found out that 99% (the top 7 entry) of the time is spent on checking (the
top
 2 takes 98.61% time on invariant):
Strange, I'm pretty sure that it used to build Phobos with -frelease ? Something must have changed there in the last couple of GDC versions... And I agreee, the default libgphobos.a (notice: "G") lib should be built without the contracts - perhaps another version with them on. --anders
Aug 05 2005
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
d d.com wrote:

 $ gdmd
 gdc (GCC) 3.3.6 (gdc 0.14, using dmd 0.127)
 Copyright (C) 2003 Free Software Foundation, Inc.
Hmm, wonder why my Mac OS X build doesn't say that ? gdc (GCC) 3.3.6 Copyright (C) 2003 Free Software Foundation, Inc. Do I have to add something to the build or platform ? OK, found it - it had been "sneaked" into the setup-gcc.sh... Using a special setup to build the Mac OS X version (gdcmac) and do the extra patches and the installer packaging etc. etc. I'll add it to the gdc 0.15 build, or something like that. :-) --anders
Jul 10 2005