Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #38256 (lpad/rpad defined in terms of textwidth) #39044

Merged
merged 5 commits into from
Jun 7, 2021

Conversation

mimame
Copy link
Contributor

@mimame mimame commented Dec 30, 2020

Fix #38256 (lpad/rpad defined in terms of textwidth)

Julia is awesome and I hope to be useful 😊

@JeffBezanson
Copy link
Member

Great, thanks! This should have a NEWS entry since it could technically change the behavior of some code.

@JeffBezanson
Copy link
Member

Also the doc string needs to be changed, since it says the function pads in terms of code points.

@simeonschaub simeonschaub added needs compat annotation Add !!! compat "Julia x.y" to the docstring needs docs Documentation for this change is required needs news A NEWS entry is required for this change strings "Strings!" labels Jan 11, 2021
@mimame
Copy link
Contributor Author

mimame commented Mar 11, 2021

Hi @JeffBezanson, I'm really sorry by the delay and I hope the fix still can be backported to the 1.6 release 😞
I've updated the doc and added the entry in the NEWS.md file
Don't hesitate to require more changes I promise to pay attention

@oscardssmith
Copy link
Member

This is definitely too late to backport to 1.6. We're already in RC2. Glad this change is getting made though.

@StefanKarpinski StefanKarpinski removed needs docs Documentation for this change is required needs news A NEWS entry is required for this change labels May 7, 2021
@StefanKarpinski
Copy link
Member

It would be great to have this finished. It still needs a compat entry explaining that the behavior changed in 1.7 and the NEWS conflict needs to be fixed. Otherwise it looks good to go. Very close!

@stevengj stevengj removed the needs compat annotation Add !!! compat "Julia x.y" to the docstring label Jun 4, 2021
@stevengj
Copy link
Member

stevengj commented Jun 4, 2021

Added the compat annotation and fixed the merge conflict.

@stevengj stevengj added the merge me PR is reviewed. Merge when all tests are passing label Jun 4, 2021
@vtjnash vtjnash merged commit 708729b into JuliaLang:master Jun 7, 2021
@vtjnash
Copy link
Member

vtjnash commented Jun 8, 2021

something going wrong with this? seeing this fail sometimes on master:
https://build.julialang.org/#builders/1/builds/4447

Error in testset Tar:
Error During Test at /buildworker/worker/tester_linuxaarch64/build/share/julia/stdlib/v1.7/Tar/test/runtests.jl:879
  Got exception outside of a @test
  DivideError: integer division error
  Stacktrace:
    [1] div
      @ ./int.jl:278 [inlined]
    [2] divrem
      @ ./div.jl:162 [inlined]
    [3] divrem
      @ ./div.jl:158 [inlined]
    [4] lpad(s::String, n::Int64, p::String)
      @ Base ./strings/util.jl:352
    [5] macro expansion
      @ /buildworker/worker/tester_linuxaarch64/build/share/julia/stdlib/v1.7/Tar/test/runtests.jl:910 [inlined]
    [6] macro expansion
      @ /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Test/src/Test.jl:1282 [inlined]
    [7] macro expansion
      @ /buildworker/worker/tester_linuxaarch64/build/share/julia/stdlib/v1.7/Tar/test/runtests.jl:881 [inlined]
    [8] macro expansion
      @ /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Test/src/Test.jl:1282 [inlined]
    [9] top-level scope
      @ /buildworker/worker/tester_linuxaarch64/build/share/julia/stdlib/v1.7/Tar/test/runtests.jl:872
   [10] include
      @ ./Base.jl:417 [inlined]
   [11] macro expansion
      @ /buildworker/worker/tester_linuxaarch64/build/share/julia/test/testdefs.jl:24 [inlined]
   [12] macro expansion
      @ /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Test/src/Test.jl:1282 [inlined]
   [13] macro expansion
      @ /buildworker/worker/tester_linuxaarch64/build/share/julia/test/testdefs.jl:23 [inlined]
   [14] macro expansion
      @ ./timing.jl:368 [inlined]
   [15] runtests(name::String, path::String, isolate::Bool; seed::UInt128)
      @ Main /buildworker/worker/tester_linuxaarch64/build/share/julia/test/testdefs.jl:21
   [16] (::Distributed.var"#106#108"{Distributed.CallMsg{:call_fetch}})()
      @ Distributed /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278
   [17] run_work_thunk(thunk::Distributed.var"#106#108"{Distributed.CallMsg{:call_fetch}}, print_error::Bool)
      @ Distributed /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:63
   [18] macro expansion
      @ /buildworker/worker/package_linuxaarch64/build/usr/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278 [inlined]
   [19] (::Distributed.var"#105#107"{Distributed.CallMsg{:call_fetch}, Distributed.MsgHeader, Sockets.TCPSocket})()
      @ Distributed ./task.jl:411

@stevengj
Copy link
Member

stevengj commented Jun 8, 2021

The Tar.jl test is calling lpad("\x7f"*"\xff"^7, 11, "\0"), which now fails at divrem because the padding string "\0" has textwidth zero.

One option would be to fall back to padding by length in the case of a zero-width padding string.

shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Jun 18, 2021
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
@giordano
Copy link
Contributor

giordano commented Aug 21, 2021

This is causing problems also for me in rpaded strings sent over MPI, where I do want the length size, not the textwidth size

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Aug 26, 2021

You probably actually want the ncodeunits size in that case, right?

@giordano
Copy link
Contributor

I had tried that, but wasn't working. What I'm sending via MPI is the Vector{Char} of the string, so I believe its size corresponds to length. I replaced rpad-ing the string with fill(' ', total_length) and then copying the chars into this vector.

@StefanKarpinski
Copy link
Member

Oh, interesting. That's a very inefficient way to send a string but yes, you would want length there.

@GordStephen
Copy link
Contributor

I'm seeing a similar issue where a fixed-length Vector{Char} needs to be padded with null bytes. I'll manually pre-fill and copy the chars, but a fallback for zero-width padding strings/chars would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should lpad/rpad be defined in terms of textwidth instead of code units or have the option to do so?
10 participants