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

Example in documentation causes stack overflow #12

Closed
madeleineudell opened this issue May 6, 2014 · 5 comments · Fixed by #13
Closed

Example in documentation causes stack overflow #12

madeleineudell opened this issue May 6, 2014 · 5 comments · Fixed by #13

Comments

@madeleineudell
Copy link

I'm not able to run the example in the documents. It produces a stack overflow.

julia> using StrPack

julia> @struct type TestStruct
           int1::Int32
           float1::Float32
       end
isequal (generic function with 38 methods)

julia> TestStruct(i, f) = TestStruct(convert(Int32, i), convert(Float32, f))
TestStruct (constructor with 1 method)

julia> s = TestStruct(-1, 1.2)
ERROR: stack overflow
 in TestStruct at none:1 (repeats 80000 times)
@ivarne
Copy link
Collaborator

ivarne commented May 6, 2014

This is caused by JuliaLang/julia#4026. The default constructor with convert calls are automatically created, so you don't need to manually write it anymore. When the default constructor now accepts any argument, your constructor overwrites it and calls itself recursively, and the result is a StackOverflow.

@madeleineudell
Copy link
Author

Beautiful. The following works:

using StrPack
@struct type TestStruct
    int1::Int32
    float1::Float32
end
# TestStruct(i, f) = TestStruct(convert(Int32, i), convert(Float32, f))
s = TestStruct(-1, 1.2)
iostr = IOBuffer()
pack(iostr, s)
ccall((:getvalues,"libteststruct"), Void, (Ptr{Void},), iostr.data)
seek(iostr, 0)
s2 = unpack(iostr, TestStruct)
println(s2)

On Tue, May 6, 2014 at 11:08 AM, Ivar Nesje notifications@github.comwrote:

This is caused by JuliaLang/julia#4026JuliaLang/julia#4026.
The default constructor with convert calls are automatically created, so
you don't need to manually write it anymore. When the default constructor
now accepts any argument, your constructor overwrites it and calls itself
recursively, and the result is a StackOverflow.


Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-42337814
.

Madeleine Udell
PhD Candidate in Computational and Mathematical Engineering
Stanford University
www.stanford.edu/~udell

@tkelman
Copy link

tkelman commented May 6, 2014

Good to know I'm not the only one who had this exact same problem... JuliaLang/julia#6756

@ivarne
Copy link
Collaborator

ivarne commented May 6, 2014

You are definitely not the only one, and I'm actually a little surprised that we have not seen more problems from this change (people have probably figured it out themselves). It's great that issues are raised in cases like this, especially when there is a simple documentation fix that makes it easier for the next person trying to figure out how things work.

@pao pao closed this as completed in #13 May 8, 2014
@pao
Copy link
Owner

pao commented May 8, 2014

Thanks again, @ivarne.

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

Successfully merging a pull request may close this issue.

4 participants