www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Adding expandTilde to phobos' std.path

reply Grzegorz Adam Hankiewicz <gradhanews ya.com> writes:
I didn't know exactly how unit tests are performed for private
functions, so in the end I decided to not make any for them (though
I would). Contribution is public domain to be included in the
lib. Tell me if it will go in or no, or you want to make changes.

I couldn't persuade ddoc to generate two examples. Putting the
dashed line between the two seems to be understood as "end of
examples", which discards the second example as preformatted and
highlighted text.  It would be better for html formatting with
CSS if the separator could be specified between both, since each
example could be boxed individually.

With this function now it would be possible to use -Dd~/something
and have it work as expected.

begin 664 d_expandTilde.diff
M26YD97 Z('-R8R]P:&]B;W,O<W1D+V,O<W1D;&EB+F0*/3T]/3T]/3T]/3T]
M/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]
M/3T]/3T]/3T]/0HM+2T <W)C+W!H;V)O<R]S=&0O8R]S=&1L:6(N9`DH<F5V
M:7-I;VX ,3`I"BLK*R!S<F,O<&AO8F]S+W-T9"]C+W-T9&QI8BYD"2AW;W)K
M:6YG(&-O<'DI"D!`("TT,"PW("LT,"PR-B!`0`H "6EN="`H*F-O;7!A<F4I
M*'9O:60 *F5L96TQ+"!V;VED("IE;&5M,BDI.PT*(`T*("` ("!C:&%R*B!G
M971E;G8H8VAA<BHI.PT**R` ("!I;G0 ("!S971E;G8H8VAA<BHL(&-H87(J

M0V]U;&1N)W0 9FEN9"!T:&5S92!D969I;F5D+"!))VT <')E<W5M:6YG('1H
M97D 87)E(&EN="X-"BMT>7!E9&5F(&EN="!U:61?=#L-"BMT>7!E9&5F(&EN
M="!G:61?=#L-

M7W5I9#L-"BL ("` 9VED7W0 <'=?9VED.PT**R` ("!C:&%R("IP=U]G96-O
M<SL-"BL ("` 8VAA<B`J<'=?9&ER.PT**R` ("!C:&%R("IP=U]S:&5L;#L-



M;F1O;2AI;G0 ;G5M*3L-"DEN9&5X.B!S<F,O<&AO8F]S+W-T9"]P871H+F0*
M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VYM96YT('9A<FEA8FQE(&1O97-N)W0-"BL *B!M871C:"!T:&4 =F%L=64 

M:&4 96YV:7)O;FUE;G0 =F%R:6%B;&4 =F5R<VEO;B!I<R!U<V5D+"!T:&4 
M<&%T:"!W;VXG=`T**R`J(&)E(&UO9&EF:65D(&EF('1H92!E;G9I<F]N;65N
M="!V87)I86)L92!D;V5S;B=T(&5X:7-T+B!7:&5N('1H90T**R`J(&1A=&%B
M87-E('9E<G-I;VX :7, =7-E9"P =&AE('!A=&  =V]N)W0 8F4 ;6]D:69I
M960 :68 =&AE('5S97(-"BL *B!D;V5S;B=T(&5X:7-T(&EN('1H92!D871A
M8F%S92!O<B!T:&5R92!I<R!N;W0 96YO=6=H(&UE;6]R>2!T;PT**R`J('!E

M87, 9'5M;7D 9F]R(%=I;F1O=W, 870 =&AE(&UO;65N="X-"BL * T**R`J
M(%)E='5R;G,Z(&EN<'5T4&%T:"!W:71H('1H92!T:6QD92!E>'!A;F1E9"P 
M;W( :G5S="!I;G!U=%!A=& -"BL *B!I9B!I="!C;W5L9"!N;W0 8F4 97AP

M>&%M<&QE<SH-"BL *B`M+2TM+0T**R`J(&EM<&]R="!S=&0N<&%T:#L-"BL 
M* T**R`J('9O:60 <')O8V5S<U]F:6QE*&-H87);72!F:6QE;F%M92D-"BL 


M="!S=&0N<&%T:#L-

M(%)%4T]54D-%7T1)4CL ("` +R\ 5&AI<R!G971S(&5X<&%N9&5D(&EN(&UA



M+2T-"BL *B!697)S:6]N.B!!=F%I;&%B;&4 <VEN8V4 =C`N,30S+ T**R`J
M($%U=&AO<G,Z($=R>F5G;W)Z($%D86T 2&%N:VEE=VEC>BP 5&AO;6%S($MU
M96AN92X-"BL *B\-"BMC:&%R6UT 97AP86YD5&EL9&4H8VAA<EM=(&EN<'5T

M<V5R="AS97`N;&5N9W1H(#T



M=%!A=& N;&5N9W1H(#T
M"BL)("` (')E='5R;B!E>'!A;F1&<F]M16YV:7)O;FUE;G0H:6YP=710871H
M*3L-"BL ("` ("` (&5L<V4-"BL)("` (')E='5R;B!E>'!A;F1&<F]M1&%T
M86)A<V4H:6YP=710871H*3L-"BL ("` ?0T**R` ("!E;'-E('9E<G-I;VXH
M5VEN9&]W<RD >PT**PDO+R!0=70 :&5R92!R96%L('=I;F1O=W, :6UP;&5M




M86YD5&EL9&4N=6YI='1E<W1<;B(I.PT**PT**R` ("`O+R!2971R:65V92!T
M:&4 8W5R<F5N="!H;VUE('9A<FEA8FQE+ T**R` ("!C:&%R*B!C7VAO;64 
M/2!G971E;G8H(DA/344B*3L-"BL-"BL ("` +R\ 5&5S=&EN9R!W:&5N('1H
M97)E(&ES(&YO(&5N=FER;VYM96YT('9A<FEA8FQE+ T**R` ("!U;G-E=&5N
M=B B2$]-12(I.PT**R` ("!A<W-E<G0H97AP86YD5&EL9&4H(GXO(BD /3T 




M("!A<W-E<G0H97AP86YD5&EL9&4H(GXO(BD /3T (F1M9"]T97-T+R(I.PT*
M*R` ("!A<W-E<G0H97AP86YD5&EL9&4H(GXB*2`]/2`B9&UD+W1E<W0B*3L-
M"BL-"BL ("` +R\ 5&AE('-A;64L(&)U="!W:71H(&$ =F%R:6%B;&4 96YD


M("!A<W-E<G0H97AP86YD5&EL9&4H(GXO(BD /3T (F1M9"]T97-T+R(I.PT*
M*R` ("!A<W-E<G0H97AP86YD5&EL9&4H(GXB*2`]/2`B9&UD+W1E<W0B*3L-
M"BL-"BL ("` +R\ 4F5C;W9E<B!O<FEG:6YA;"!(3TU%('9A<FEA8FQE(&)E
M9F]R92!C;VYT:6YU:6YG+ T**R` ("!I9B`H8U]H;VUE*0T**PES971E;G8H



M97)T*&5X<&%N9%1I;&1E*")^<F]O="(I(#T]("(O<F]O="(I.PT**R` ("!A
M<W-E<G0H97AP86YD5&EL9&4H(GYR;V]T+R(I(#T]("(O<F]O="\B*3L-"BL 
M("` 87-S97)T*&5X<&%N9%1I;&1E*")^261O;G1E>&ES="]H97DB*2`]/2`B

M('1H92!T:6QD92!F<F]M('!A=&  =VET:"!T:&4 96YV:7)O;FUE;G0 =F%R
M:6%B;&4 2$]-12X-"BL *B\-"BMP<FEV871E(&-H87);72!E>'!A;F1&<F]M




M344B*3L-"BL ("` :68 *&AO;64 /3T ;G5L;"D-"BL ("` ("` (')E='5R
M;B!P871H.PT**PT**R` ("!R971U<FX 8V]M8FEN94-0871H5VET:$10871H

M('!A=&  9G)O;2!A($, <W1R:6YG('1O('1H92!R96UA:6YD97( ;V8 <&%T
M:"X-"BL * T**R`J(%1H92!L87-T('!A=&  <V5P87)A=&]R(&9R;VT 8U]P
M871H(&ES(&1I<V-A<F1E9"X 5&AE(')E<W5L=`T**R`J(&ES(&IO:6YE9"!T
M;R!P871H6V-H87)?<&]S("XN(&QE;F=T:%T :68 8VAA<E]P;W, :7, <VUA
M;&QE< T**R`J('1H86X ;&5N9W1H+"!O=&AE<G=I<V4 <&%T:"!I<R!N;W0 
M87!P96YD960 =&\ 8U]P871H+ T**R`J+PT**W!R:79A=&4 8VAA<EM=(&-O


M;&PI.PT**R` ("!A<W-E<G0H<&%T:"YL96YG=&  /B`P*3L-"BL ("` 87-S
M97)T*&-H87)?<&]S(#X

M="!E;F0 /2`P.PT**R` ("!W:&EL92`H8U]P871H6V5N9%T (3T ,"D-"BL 
M("` ("` (&5N9"LK.PT**PT**R` ("`O+R!$;R!W92!A<'!E;F0 <V]M971H




M,"`N+B!E;F0 +2`Q73L-"BL)96QS90T**R` ("` ("` ("` (')E='5R;B!C

M("` +R\ 665S+B!297!L86-E('=I=&  ;W( =VET:&]U="!L87-T('!A=&  








M871H*0T**WL-"BL ("` 87-S97)T*'!A=& N;&5N9W1H(#X ,B!\?"`H<&%T
M:"YL96YG=&  /3T ,B`F)B!P871H6S%=("$]('-E<%LP72DI.PT**R` ("!A
M<W-E<G0H<&%T:%LP72`]/2`G?B<I.PT**PT**R` ("`O+R!%>'1R86-T('5S
M97)N86UE+"!S96%R8VAI;F< 9F]R('!A=&  <V5P87)A=&]R+ T**R` ("!C


M"BL ("` ("` ('5S97)N86UE(#T
M.PT**PEL87-T7V-H87( /2!U<V5R;F%M92YL96YG=&  *R`Q.PT**R` ("!]



M;W( =&AE(&=E='!W;F%M7W(H*2!F=6YC=&EO;BX-"BL ("` <&%S<W=D(')E
M<W5L=#L-"BL ("` 8V]N<W0 :6YT(&5X=')A7VUE;6]R>5]S:7IE(#T -2`J




M.PT**R` ("!I9B`H9V5T<'=N86U?<BAU<V5R;F%M92P )G)E<W5L="P 97AT
M<F%?;65M;W)Y+"!E>'1R85]M96UO<GE?<VEZ92P-"BL ("` ("` ("` ("`F
M=F5R:69Y*2`A/2`P*0T**R` ("` ("` 9V]T;R!F<F5E7VUE;3L-"BL-"BL 
M("` +R\ 1F%I;'5R92!I9B!V97)I9GD 9&]E<VXG="!P;VEN="!A="!R97-U
M;'0N(%1H<F]W(&UE;6]R>2!E<G)O<C\-"BL ("` :68 *'9E<FEF>2`A/2`F
M<F5S=6QT*0T**R` ("` ("` 9V]T;R!F<F5E7VUE;3L-"BL-"BL ("` <&%T

M+"!L87-T7V-H87(I.PT**PT**V9R965?;65M. T**R` ("!F<F5E*&5X=')A

`
end
Jan 08 2006
next sibling parent reply Chris Lajoie <ctlajoie___remove___this___ ___gmail.com> writes:
Grzegorz Adam Hankiewicz wrote:
 I didn't know exactly how unit tests are performed for private
 functions, so in the end I decided to not make any for them (though
 I would). Contribution is public domain to be included in the
 lib. Tell me if it will go in or no, or you want to make changes.
 
 I couldn't persuade ddoc to generate two examples. Putting the
 dashed line between the two seems to be understood as "end of
 examples", which discards the second example as preformatted and
 highlighted text.  It would be better for html formatting with
 CSS if the separator could be specified between both, since each
 example could be boxed individually.
 
 With this function now it would be possible to use -Dd~/something
 and have it work as expected.
certainly no offense intended, but wouldn't it be easier to eliminate the extra step and just attach the revised file? instead of posting diffs (and whatever the other one is.. CVS diff I think). as a user I'd just like to see the code you wrote. Chris
Jan 09 2006
parent Grzegorz Adam Hankiewicz <gradhafakedontuse ya.com> writes:
The Mon, 09 Jan 2006 12:21:01 -0700, Chris Lajoie wrote:
 certainly no offense intended, but wouldn't it be easier to eliminate 
 the extra step and just attach the revised file?
Diffs are to make Walter's job easier. Besides, I've just seen the new .143 release, and it's there so you can try now yourself.
Jan 14 2006
prev sibling parent reply Grzegorz Adam Hankiewicz <gradhafakedontuse ya.com> writes:
Walter, I would like you to explain the change you did to
combineCPathWithDPath. There you have:

    // Create our own copy, as lifetime of c_path is undocumented
    char[] cp = c_path[0 .. end].dup;

    // Do we append something from path?
    if (char_pos < path.length)
        cp ~= path[char_pos .. length];

    return cp;

I don't understand your comment about the lifetime of c_path. Is it
because it's a char instead of const char?  AFAICS, in both cases
the char comes from memory which won't go away, or will it?

And then, there's not much lifetime either for
combineCPathWithDPath. Wouldn't it be the same to rewrite that
block as:

    // Do we append something from path?
    if (char_pos < path.length)
        return c_path[0 .. end] ~ path[char_pos .. length];
    else
        return c_path[0 .. end].dup;

Is (should be?) any of the blocks more optimal in terms of internal
memory copies? Will the compiler optimise the second block better
because the duplication of c_path happens in the same statement
where the appending of path?

What would be the best way to find out with the compiler? How would
I find out what asm is being produced? Even if I don't know asm,
I would expect the optimal block to be shorter, right?
Jan 15 2006
parent "Walter Bright" <newshound digitalmars.com> writes:
"Grzegorz Adam Hankiewicz" <gradhafakedontuse ya.com> wrote in message 
news:pan.2006.01.15.13.26.57.290795 ya.com...
 Walter, I would like you to explain the change you did to
 combineCPathWithDPath. There you have:

    // Create our own copy, as lifetime of c_path is undocumented
    char[] cp = c_path[0 .. end].dup;

    // Do we append something from path?
    if (char_pos < path.length)
        cp ~= path[char_pos .. length];

    return cp;

 I don't understand your comment about the lifetime of c_path. Is it
 because it's a char instead of const char?  AFAICS, in both cases
 the char comes from memory which won't go away, or will it?
As I recall, in one case it was a pointer to memory returned from getenv(), which doesn't document the lifetime of it. For the other case c_path was potentially a pointer to memory that was later explicitly free'd by the function.
 And then, there's not much lifetime either for
 combineCPathWithDPath. Wouldn't it be the same to rewrite that
 block as:

    // Do we append something from path?
    if (char_pos < path.length)
        return c_path[0 .. end] ~ path[char_pos .. length];
    else
        return c_path[0 .. end].dup;
No, because if char_pos==length, then c_path[0..end] is possibly returned, and no copy is made, although the current implementation of internal/gc/gc._d_arraycat() will always dup it. To future proof the code, it shouldn'd assume that ~ will always make a copy.
 Is (should be?) any of the blocks more optimal in terms of internal
 memory copies? Will the compiler optimise the second block better
 because the duplication of c_path happens in the same statement
 where the appending of path?

 What would be the best way to find out with the compiler? How would
 I find out what asm is being produced? Even if I don't know asm,
 I would expect the optimal block to be shorter, right?
The compiler doesn't control allocations, the runtime library does. Check out the routines in internal/gc/gc.d
Jan 15 2006