Skip to content

Conversation

@petershintech
Copy link
Contributor

  1. The extra argument, stdcall, is a bug. The return value is just a boolean.
  2. T conversion can be failed if something wrong happens in the system. So, in this case, need to raise an exception rather than assertion. I think SystemError would be the best choice for this case.

Wondering why the extra argument bug was not caught by tests. If it is missing in tests, can I have your help to add a unit test for winprompt()?

@yuyichao
Copy link
Contributor

yuyichao commented Jan 8, 2019

Copy link
Contributor

@yuyichao yuyichao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdcall has nothing to do with return type.

@petershintech
Copy link
Contributor Author

Yichao. Thanks for the information. I only checked https://docs.julialang.org/en/v1/base/c/#ccall
It seems the doc string of ccall() needs to be updated. Am I right?

@vchuravy vchuravy changed the title Remove an extra argument for ccall() and replace @assert with throw() in winprompt() Replace @assert with throw() in winprompt() Jan 8, 2019
@JeffBezanson
Copy link
Member

According to its documentation, this function can only fail if the buffer is too small. Do we have a reason to believe 1024 is always enough? If so, then the existing assertion is actually correct. (Either way though, if this happens it's our bug, since there's nothing the user/caller can do to get a bigger buffer.)

@JeffBezanson JeffBezanson added the system:windows Affects only Windows label Jan 8, 2019
@JeffBezanson
Copy link
Member

Also, when the function fails it updates the length argument to tell you how much space is needed. So an alternative fix is to handle that case and retry the call with a bigger buffer, after which an assertion would be warranted.

@petershintech
Copy link
Contributor Author

I think retrying the call with a bigger buffer is a good choice to make the code more solid, but if it fails again, we need to raise an exception rather than insert an assertion, because the outcome of the call depends on the response of an external program. If Julia allows @Assert to be deactivated in the future, the critical check can be bypassed.

@musm
Copy link
Contributor

musm commented Dec 11, 2020

#38828 addresses resizing the buffer in case of failure

@musm musm closed this Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

system:windows Affects only Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants