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
sanitise global data allocation; fix a void return #8
Conversation
Global data should be allocated in *.c files, and declared (with extern qualifier) in *.h Otherwise it is asking for trouble (surely it does not work on OSX). As well, a non-void function cannot have "return;" - fixed that too.
This is a part of the effort to port to OSX, see https://trac.sagemath.org/ticket/24015 |
@dimpase Thanks--this is exactly what I was going to do. I'm not sure how best to deal with |
I've replaced fmemopen with fopen. There is also an open_memstream to deal with. |
|
Is this branch tested and ready for merge? |
This pull requests appears to work on Linux. |
I have also run some tests on linux, and nothing seems to be broken. Is this enough to solve the OSX issue or should I wait to make a new release? |
For OSX we need to provide a replacement for open_memstream, or else
refactor the code using it (it is just one function, p_show).
Could you give an upper bound on the size of its output, so that we can
just allocate the buffer once and do sprintf to this buffer instead of
fprintf to the (unsupported) stream?
On 12 Oct 2017 15:07, "miguelmarco" <notifications@github.com> wrote:
I have also run some tests on linux, and nothing seems to be broken. Is
this enough to solve the OSX issue or should I wait to make a new release?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABN8HELRFZzcw07D94_uiqtzmOFMoXp8ks5srh0TgaJpZM4P2vm6>
.
|
I can't think of a bound that is not overkill on most cases. What would be the canonical way to append to a string on OSX? |
One possible solution would be to just remove the p_show function. In fact, the Sage interface doesn't even use it (it uses the homfly_polynomial_dict function which directly extracts the information from the Poly struct). However, the tests should be adapted in that case. |
to do this, we replace fscanfs with sscanfs--- the disadvantage is that we have to manually advance the place to start to read the string after each scanf; fortunately we have %n format parameter to do this easily.
OK, the latest commit at least makes |
replacing fprintf with the sprintf, and manual advancing of the string position to write to. here the annoying problem is that we don't have an automatically growing buffer, so we just allocate 100K---for the time being
to make this work on OSX, a newer than the current (7.2f) version of Boehm GC is needed; |
now the string to hold the output is grown dynamically, with a safety region.
OK, ready, tested on Linux and OSX. |
Reviewing now. |
return FALSE; | ||
} | ||
fscanf(f, "%d ", &links); | ||
sscanf(f, "%d%n", &links, &pos); | ||
f += pos; | ||
for (i=0; i<links; ++i) /* how many pieces of string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of updating the position of the f pointer could have side effects. Wouldn't it be safer to use a copy instead of the pointer passed to the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a call by value. Nothing will happen to f
outside the scope of k_read()
. (to change f
inside k_read()
, you'd need to pass &f
, i.e. its address).
lib/poly.c
Outdated
|
||
|
||
stream = open_memstream(&bp, &size); | ||
stream = (char *)GC_MALLOC(sizeof(char) * 100000); | ||
bp = stream; | ||
if (!p->len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you decide the 100000 size limit?
Besides my minor concern about the side effects of moving the f pointer (which, according to the tests, don't even seem to have any effect), looks good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a C call by value, no need to worry about side effects.
return FALSE; | ||
} | ||
fscanf(f, "%d ", &links); | ||
sscanf(f, "%d%n", &links, &pos); | ||
f += pos; | ||
for (i=0; i<links; ++i) /* how many pieces of string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a call by value. Nothing will happen to f
outside the scope of k_read()
. (to change f
inside k_read()
, you'd need to pass &f
, i.e. its address).
Ok. Let me know when it is finally ready, and I will merge it and do a new release. |
it is done in the sense of C code. You can also add the travis stuff. it reports error on OSX as GC 7.6.0 that comes semi-standard is not new enough. |
IS the travis stuff needed for building on OSX? |
Merged. The tarball is available here |
Could you also do a release on https://github.com/miguelmarco/libhomfly/releases ? |
As you might have already found out, E.g. you can test on OSX even if you don't have OSX on any machine... |
I created the release; but beware that, since the files generated by autoconf are not tracked by git, the tarball in the github release needs to go through |
Global data should be allocated in *.c
files, and declared (with extern qualifier) in *.h
Otherwise it is asking for trouble (surely it does not work on OSX).
As well, a non-void function cannot have "return;" - fixed that too.