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

Replace 'cstderr.rawWrite' with 'writeToStdErr' #17288

Closed
wants to merge 1 commit into from

Conversation

ehmry
Copy link
Contributor

@ehmry ehmry commented Mar 7, 2021

Use a procedure that is easy to replace on platforms without native UNIX file descriptors.

(#17268 reattempt)

future work

  • make writeToStdErr work in VM via a magic/vmops (without resorting to --experimental:compiletimeFFI)
  • ditto for js backend, where we can map it to console.log

@ehmry ehmry marked this pull request as ready for review March 7, 2021 18:22
@ehmry
Copy link
Contributor Author

ehmry commented Mar 7, 2021

I'm not sure if these failed checks are related?

lib/system/mmdisp.nim Outdated Show resolved Hide resolved
@@ -42,7 +48,7 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
add(buf, " [")
add(buf, name exceptn)
add(buf, "]\n")
cstderr.rawWrite buf
writeFatalErr(buf.cstring, buf.len)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
writeFatalErr(buf.cstring, buf.len)
writeToStdErr buf

I don't think there's a need to introduce writeFatalErr, instead writeToStdErr should be made to work cross platform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to reuse writeToStdErr but I couldn't find an elegant way to do it, writeToStdErr is mostly used in files that are includeed into system.nim, and as I recall system/fatal is imported or included in multiple locations.

Copy link
Member

Choose a reason for hiding this comment

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

i think it's fixable, once you fix the other points i can look into how to fix that

@@ -551,6 +551,10 @@ when notJSnotNims and not defined(nimSeqsV2):
when notJSnotNims:
include "system/hti"

proc writeToStdErr(msg: cstring, length: int)
proc writeToStdErr(msg: cstring)
Copy link
Member

@timotheecour timotheecour Mar 7, 2021

Choose a reason for hiding this comment

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

how about:

  proc writeToStdErr(msg: cstring) {.inlnie.} =
    writeToStdErr(msg, msg.len)

that way, no need to define this overload proc writeToStdErr(msg: cstring) on each platform

@@ -551,6 +551,10 @@ when notJSnotNims and not defined(nimSeqsV2):
when notJSnotNims:
include "system/hti"

proc writeToStdErr(msg: cstring, length: int)
proc writeToStdErr(msg: cstring)
proc writeToStdErr(msg: string)
Copy link
Member

Choose a reason for hiding this comment

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

ditto, this could be defined directly as:

  proc writeToStdErr(msg: string) {.inline.} =
    writeToStdErr(msg.cstring, msg.len)

that way, the only proc to define on each platform is proc writeToStdErr(msg: cstring, length: int)

@@ -551,6 +551,10 @@ when notJSnotNims and not defined(nimSeqsV2):
when notJSnotNims:
include "system/hti"

proc writeToStdErr(msg: cstring, length: int)
Copy link
Member

@timotheecour timotheecour Mar 7, 2021

Choose a reason for hiding this comment

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

I'm not sure if these failed checks are related?

most likely related, and you should be able to reproduce the bug locally with smthg like
testament pcat dll or similar (these are the failing tests in CI i see)

@timotheecour timotheecour added the TODO: followup needed remove tag once fixed or tracked elsewhere label Mar 9, 2021
Use a procedure that is easy to replace on platforms without native
UNIX file descriptors.
@ehmry
Copy link
Contributor Author

ehmry commented Mar 9, 2021

I'm not happy with this patch. Its hard to know where define writeToStdErr in system because its used in include files but depends on ansi_c. Would it be better to replace this with an internal compiler builtin instead? I'm willing to make the changes but with the sytem and hardware I'm using its difficult to run the tests.

@Araq
Copy link
Member

Araq commented Mar 9, 2021

Why not add it to ansi_c.nim then. Please not another built-in.

@ehmry
Copy link
Contributor Author

ehmry commented Mar 9, 2021

Would this only be valid for C-comptible targets? This is something mostly used in the garbage collector. If it was to go into ansi_c then I would want to change the name to something like writeSystemError, because it wouldn't be UNIX standard error for some platforms.

@Araq
Copy link
Member

Araq commented Mar 9, 2021

Would this only be valid for C-comptible targets?

ansi_c.nim would contain the default implementation, you can re-define it with this pattern:

when not declared(writeError):
  proc writeError() = ...

@timotheecour
Copy link
Member

ping @ehmry this is a good PR, please continue if you can!

@ehmry
Copy link
Contributor Author

ehmry commented Mar 26, 2021

I don't know the code here well enough to make this change in a way that improves its quality, and I don't think I'm in a position to catch regressions. It would be a welcome improvement, but not something that I have problem with at the moment.

@ehmry ehmry closed this Mar 26, 2021
@ringabout ringabout added the stale Staled PR/issues; remove the label after fixing them label Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them TODO: followup needed remove tag once fixed or tracked elsewhere
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants