Skip to content

Commit 6534a35

Browse files
committed
refact(Lib/os_impl): dedup MS_WINDOWS, InJs
1 parent 34f0cb9 commit 6534a35

File tree

9 files changed

+25
-18
lines changed

9 files changed

+25
-18
lines changed

src/pylib/Lib/os_impl/common.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
import ../../pyerrors/[oserr, simperr]
2+
import ./private/defined_macros
3+
export InJs
4+
import ../../pyerrors/[oserr, simperr, rterr]
35
when defined(js):
46
import ../../pyerrors/jsoserr
57
export jsoserr
@@ -13,6 +15,6 @@ import ../../pybytes/[bytesimpl, bytesbltins]
1315
import ../../version
1416
export version
1517

16-
export io_abc, oserr, simperr, strimpl, strbltins.repr, bytesimpl, bytesbltins.repr
18+
export io_abc, oserr, simperr, rterr, strimpl, strbltins.repr, bytesimpl, bytesbltins.repr
1719
export noneType
1820

src/pylib/Lib/os_impl/inheritable.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11

22
# XXX: this shall work `when defined(freertos) or defined(zephyr)`
33
# but is is meaningful?
4-
import ./private/[platform_utils, iph_utils]
4+
import ./private/[platform_utils, iph_utils, defined_macros]
55
import ../../pyerrors/oserr
66

7-
const
8-
MS_WINDOWS = defined(windows)
9-
107
when MS_WINDOWS:
118
import std/winlean
129
from std/os import raiseOSError

src/pylib/Lib/os_impl/path.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ psExp normpath, normalizedPath
4848
func relpath*[T](p: PathLike[T], start=curdir): T =
4949
mapPathLike[T] relativePath($p, $start)
5050
51-
when defined(js):
51+
when InJS:
5252
export getatime, getmtime, getctime
5353
else:
5454
template expFRetTAsF(nam, nimProc){.dirty.} =

src/pylib/Lib/os_impl/posix_like/lseek.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import ../private/iph_utils
2+
import ../private/[iph_utils, defined_macros]
33
import ./errnoHandle
44
const weirdTarget = defined(js) or defined(nimscript)
55
when not weirdTarget:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
const MS_WINDOWS* = defined(windows)
3+
when not defined(js):
4+
const ms_windows* = MS_WINDOWS
5+
else:
6+
import ../../sys_impl/genplatform
7+
let ms_windows* = getPlatform() == "win32"
8+
const InJs* = defined(js)

src/pylib/Lib/os_impl/randoms.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ else:
88

99
import ../../nimpatch/newUninit
1010
import ../../pyconfig/bootstrap_hash
11-
11+
import ./private/defined_macros
1212
#[
1313
## | Targets | Implementation | set errno
1414
## | :--- | ----: | :---
@@ -33,7 +33,7 @@ import ../../pyconfig/bootstrap_hash
3333
## .. _/dev/urandom: https://en.wikipedia.org/wiki//dev/random
3434
]#
3535

36-
const mayUseDevUrandom = not defined(js) and not defined(windows)
36+
const mayUseDevUrandom = not defined(js) and not MS_WINDOWS
3737
when mayUseDevUrandom:
3838
import ../errno_impl/errnoUtils
3939
{.define: ImportErrnoUtils.}

src/pylib/Lib/os_impl/waits.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import ../resource_impl/types
33
from ./common import raiseErrno
44
import ./util/handle_signal
55
import ./private/platform_utils
6-
const DWin = defined(windows)
7-
when DWin:
6+
import ./private/defined_macros
7+
when MS_WINDOWS:
88
import ../../private/iph_utils # with_Py_SUPPRESS_IPH
99
else:
1010
from std/posix import Pid
1111

12-
when DWin:
12+
when MS_WINDOWS:
1313
type Res = int
1414
type WAIT_TYPE = cint
1515
proc cwait(termstat: var cint, pid: cint, options: cint): Res{.importc: "_cwait", header: "<process.h>".}
@@ -38,7 +38,7 @@ else:
3838
template decl_STATUS_INIT(status; val: cint = 0) =
3939
var status: WAIT_TYPE = val
4040

41-
when not DWin and not defined(js) and not defined(nimscript):
41+
when not MS_WINDOWS and not defined(js) and not defined(nimscript):
4242
template genW(name){.dirty.} =
4343
proc name(status: WAIT_TYPE): cint{.importc, header: "<sys/wait.h>".}
4444
proc name*(status: int): bool =
@@ -79,7 +79,7 @@ when declared(c_waitpid):
7979
waitX_impl[Res](res, status, c_waitpid(pid, status, options))
8080
(res.int, handle_status(status))
8181
82-
when not DWin:
82+
when not MS_WINDOWS:
8383
proc wait(status: var WAIT_TYPE): Res{.importc, header: "<sys/wait.h>".}
8484
proc wait*(): tuple[pid: int, status: int]{.platformNoJs.} =
8585
var res: Pid
@@ -116,7 +116,7 @@ when not DWin:
116116
wait_helper(res, WAIT_STATUS_INT(status), ru)
117117
118118
proc waitstatus_to_exitcode*(status: int): int{.platformNoJs.} =
119-
when not defined(windows):
119+
when not MS_WINDOWS:
120120
decl_STATUS_INIT(wait_status, status.cint)
121121
var exitcode: cint
122122
if bool WIFEXITED(wait_status):

src/pylib/private/iph_utils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CPython/Include/internal/pycore_fileutils.h
55
]##
66

7-
const MS_WINDOWS* = defined(windows)
7+
const MS_WINDOWS = defined(windows)
88

99
when MS_WINDOWS and defined(vcc):
1010
let MSC_VER{.importc: "_MSC_VER", nodecl.}: cint

src/pylib/pyerrors/oserr.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ when defined(windows):
88
else:
99
import std/posix
1010

11-
const InJs* = defined(js)
11+
const InJs = defined(js)
1212
when InJs:
1313
import ./jsoserr
1414

0 commit comments

Comments
 (0)