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

Stack overflow printing 0-d array #4562

Closed
zmaril opened this issue Oct 18, 2013 · 12 comments
Closed

Stack overflow printing 0-d array #4562

zmaril opened this issue Oct 18, 2013 · 12 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@zmaril
Copy link

zmaril commented Oct 18, 2013

println(reshape(Any[1],()))

This produces a stack overflow on my machine.

ERROR: stack overflow                                                                                                                                 
 in sub at subarray.jl:113 (repeats 21773 times)                                                                                                      
 in print_slice at datafmt.jl:220                                                                                                                     
 in cartesianmap at abstractarray.jl:1311
@magistere
Copy link
Contributor

It causes stack overflow not only for Any type:

println(reshape([1],()))

@magistere
Copy link
Contributor

I hope this can help in fixing the bug:

julia> a=reshape([1],())
0-dimensional Array{Int32,0}:
1

julia> print(STDOUT,a)
ERROR: stack overflow

julia> show(STDOUT,a)
0-dimensional Array{Int32,0}:
1
julia> @which print(STDOUT,a)
print(io::IO,X::AbstractArray{T,N}) at show.jl:900

julia> @which show(STDOUT,a)
show{T}(io::IO,x::AbstractArray{T,0}) at show.jl:861

But my modifications of show.jl are not taken into account. I assume this related to system image file.
Is it possible to make modifcations to files from julia/base without building full Julia?

@kmsquire
Copy link
Member

:

Is it possible to make modifcations to files from julia/base without
building full Julia?

No. .

@StefanKarpinski
Copy link
Sponsor Member

In this case you'd have to import Base.show or fully qualify it as Base.show, but it probably won't help since the call to show is already cached in the REPL printing code and won't get updated due to #265.

@ihnorton
Copy link
Member

But my modifications of show.jl are not taken into account. I assume this related to system image file.
Is it possible to make modifcations to files from julia/base without building full Julia?

Delete bin/sys.ji; it will be regenerated automatically the next time you start Julia to reflect the updated state of base (but note: the distribution base/ is source-only, no git history, so you will need to clone elsewhere and apply your patch in order to submit via git; see also #4287).

@magistere
Copy link
Contributor

Thanks for suggestions, but neither works for me.

@StefanKarpinski I tried both import and full qualification from REPL and from script. But neither used my modifications in base/show.jl.

@ihnorton there are 2 files in bin directory: sys.ji and sys0.ji. Deleting sys0.ji doesn't have any consequences, but deleting sys.ji causes the following error:

"Preparing Julia for first launch. This may take a while"
"You may see two git related errors. This is completely normal"
could not open file boot.jlSystem image file "c:\Programs\Julia\bin\\../bin/sys.
ji" not found

So unfortunately @kmsquire's answer is most accurate now.

P.S. Thanks to @JeffBezanson for fast fixing of this bug.

@StefanKarpinski
Copy link
Sponsor Member

Are you using a binary install?

@magistere
Copy link
Contributor

@StefanKarpinski
Copy link
Sponsor Member

Ah, yeah. You're not going to be able to compile Julia from a binary install. You have to use a source install for that.

@ihnorton
Copy link
Member

You need to run the batch script. I know that this works, at least on Win64 (in fact, I just did it). I get your error if I run julia-basic, but it works fine from julia.bat.

@magistere
Copy link
Contributor

@ihnorton Thanks, it works! After deleting sys.ji I tried to run my testing script with julia.bat <script name>. But for correct work julia.bat should be first run without any arguments to rebuild system image.

@StefanKarpinski I don't want to recompile Julia on Windows, so binary install is good for me now. But @ihnorton advice have made this unnecessary for modifications only in Julia source files.

@magistere
Copy link
Contributor

@JeffBezanson

I found that this bug can be fixed without any additional code by removing line 900 in base/show.jl:

print(io::IO, X::AbstractArray) = writedlm(io, X)

Is this acceptable solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants