refactor(app): 改为直接 import io,用 io.File / io.MODE
不再用 'import io as fileio' 别名:20 个文件统一 'import io', 所有 fileio.X 调用点改为 io.X(win32.fileio 等模块路径出现在注释里的保持原样)。
This commit is contained in:
1 parent
94515ddf12
commit
3febb87abf
20 files changed
+104
-104
No files matched your search
@@ -6,7 +6,7 @@ import stdlib
|
||||
import memhub
|
||||
import viperlib
|
||||
import vthreading
|
||||
import io as fileio
|
||||
import io
|
||||
import win32.win32file
|
||||
import win32.win32base
|
||||
import win32.win32process as win32process
|
||||
@@ -125,7 +125,7 @@ def WriteCallSidecar(temp_dir: str, sha1: str, text: str) -> int:
|
||||
if vpath is None:
|
||||
VLogger.error(f"--traceback: failed to build .vpcall path (sha1={sha1}), aborting compilation", "TRACEBACK")
|
||||
return 1
|
||||
vf: fileio.File* = fileio.File(vpath, fileio.MODE.W)
|
||||
vf: io.File* = io.File(vpath, io.MODE.W)
|
||||
if vf.closed:
|
||||
VLogger.error(f"--traceback: failed to write .vpcall (cannot open {vpath}), aborting compilation", "TRACEBACK")
|
||||
stdlib.free(vpath)
|
||||
@@ -150,7 +150,7 @@ def _tb_basename_is_traceback(file_path: str) -> int:
|
||||
def TranslateFileGetTrans(mb: memhub.MemBuddy*, file_path: str, sha1_val: str, current_package: str = None, declare_only: int = 0, temp_dir: str = None, pre_allow_dep_inject: int = 0) -> HandlesTranslator.Translator*:
|
||||
"""Translate one file and return a Translator (caller dumps IR); None on failure."""
|
||||
if file_path is None: return None
|
||||
f: fileio.File* = fileio.File(file_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(file_path, io.MODE.R)
|
||||
# Fail-fast: a path that cannot be opened (e.g. an App source resolved against the wrong root)
|
||||
# used to return None silently, and the caller only reported "cannot be translated".
|
||||
if f.closed: VLogger.error(f"cannot open source file: {file_path}", "Translate")
|
||||
@@ -198,7 +198,7 @@ def TranslateFileGetTrans(mb: memhub.MemBuddy*, file_path: str, sha1_val: str, c
|
||||
td_len_vpi: sizet = len(temp_dir)
|
||||
pyi_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_vpi, sha1_val, "vpi")
|
||||
if pyi_path is not None:
|
||||
pf: fileio.File* = fileio.File(pyi_path, fileio.MODE.W)
|
||||
pf: io.File* = io.File(pyi_path, io.MODE.W)
|
||||
if not pf.closed:
|
||||
pf.write(pyi_buf, pyi_pos)
|
||||
pf.close()
|
||||
@@ -347,7 +347,7 @@ def write_ir_to_file(ir_buf: bytes, ir_len: sizet, output_dir: str, module_name:
|
||||
if path is None: return 1
|
||||
|
||||
# open the file for writing
|
||||
f: fileio.File* = fileio.File(path, fileio.MODE.W)
|
||||
f: io.File* = io.File(path, io.MODE.W)
|
||||
if f.closed: return 1
|
||||
|
||||
written: int64 = f.write(ir_buf, ir_len)
|
||||
@@ -546,7 +546,7 @@ def _phase2_write_cmd(cmd: str) -> None:
|
||||
"""--phase2command mode: append the command to the bat file without executing it."""
|
||||
global _phase2_bat_init
|
||||
if _phase2_cmd_path is None or cmd is None: return
|
||||
f: fileio.File* = fileio.File(_phase2_cmd_path, fileio.MODE.A)
|
||||
f: io.File* = io.File(_phase2_cmd_path, io.MODE.A)
|
||||
if f.closed:
|
||||
VLogger.error("phase2command: failed to open bat", "phase2cmd")
|
||||
return
|
||||
@@ -1493,7 +1493,7 @@ def _tb_read_pe_layout(mb: memhub.MemBuddy*, exe_path: str) -> TbPeLayout*:
|
||||
"""Read (ImageBase, SizeOfImage, .text RVA) from the PE headers."""
|
||||
lay: TbPeLayout* = TbPeLayout()
|
||||
if lay is None: return None
|
||||
f: fileio.File* = fileio.File(exe_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(exe_path, io.MODE.R)
|
||||
if f.closed: return lay
|
||||
HEAD: sizet = 4096
|
||||
head: bytes = mb.alloc(HEAD)
|
||||
@@ -1890,7 +1890,7 @@ def _tb_cp_add_fr(mb: memhub.MemBuddy*, cp: TbCallParse*, sym: str, file: str, d
|
||||
|
||||
def _tb_read_whole(mb: memhub.MemBuddy*, path: str) -> str:
|
||||
"""Read the whole file into a NUL-terminated string; None on failure."""
|
||||
f: fileio.File* = fileio.File(path, fileio.MODE.R)
|
||||
f: io.File* = io.File(path, io.MODE.R)
|
||||
if f.closed: return None
|
||||
sz: LONGLONG = f.size()
|
||||
if sz < 0:
|
||||
@@ -2450,7 +2450,7 @@ def WriteStackMap(mb: memhub.MemBuddy*, exe_path: str) -> int:
|
||||
VLogger.error("--traceback: failed to allocate sidecar path buffer, aborting compilation", "TRACEBACK")
|
||||
return 1
|
||||
viperlib.snprintf(map_path, map_len, "%s.stackmap", exe_path)
|
||||
mf: fileio.File* = fileio.File(map_path, fileio.MODE.W)
|
||||
mf: io.File* = io.File(map_path, io.MODE.W)
|
||||
if mf.closed:
|
||||
VLogger.error(f"--traceback: failed to write sidecar file (cannot open {map_path}), aborting compilation", "TRACEBACK")
|
||||
return 1
|
||||
|
||||
@@ -3,7 +3,7 @@ import string
|
||||
import stdlib
|
||||
import memhub
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import win32.win32base
|
||||
import ast
|
||||
import mlirlite
|
||||
@@ -119,7 +119,7 @@ def _RewriteDepsTxt(temp_dir: str, sha1: str, deps_str: str) -> None:
|
||||
td_len: sizet = string.strlen(temp_dir)
|
||||
dpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "deps.txt")
|
||||
if dpath is None: return
|
||||
df: fileio.File* = fileio.File(dpath, fileio.MODE.W)
|
||||
df: io.File* = io.File(dpath, io.MODE.W)
|
||||
if not df.closed:
|
||||
dl: sizet = string.strlen(deps_str)
|
||||
if dl > 0: df.write(deps_str, dl)
|
||||
@@ -456,7 +456,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
|
||||
# Read file contents
|
||||
file_path_r: str = entry_r.Path
|
||||
f_r: fileio.File* = fileio.File(file_path_r, fileio.MODE.R)
|
||||
f_r: io.File* = io.File(file_path_r, io.MODE.R)
|
||||
if f_r.closed:
|
||||
p1a_fl += 1
|
||||
continue
|
||||
@@ -586,7 +586,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {entry_pv.Path} | failed to generate the vpi path", "Phase1")
|
||||
continue
|
||||
vf_pv: fileio.File* = fileio.File(vpi_path_pv, fileio.MODE.R)
|
||||
vf_pv: io.File* = io.File(vpi_path_pv, io.MODE.R)
|
||||
if not vf_pv.closed:
|
||||
vf_pv.close()
|
||||
stdlib.free(vpi_path_pv)
|
||||
@@ -594,7 +594,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
stdlib.free(vpi_path_pv)
|
||||
# Read the file, parse the AST, generate the vpi
|
||||
file_path_pv: str = entry_pv.Path
|
||||
f_pv: fileio.File* = fileio.File(file_path_pv, fileio.MODE.R)
|
||||
f_pv: io.File* = io.File(file_path_pv, io.MODE.R)
|
||||
if f_pv.closed:
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | cannot open the source file", "Phase1")
|
||||
@@ -642,7 +642,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
if pyi_pos_pv > 0:
|
||||
pyi_path_pv: str = StubMergerCollect._sliced_path(temp_dir, dir_len_pv, sha1_pv, "vpi")
|
||||
if pyi_path_pv is not None:
|
||||
pf_pv: fileio.File* = fileio.File(pyi_path_pv, fileio.MODE.W)
|
||||
pf_pv: io.File* = io.File(pyi_path_pv, io.MODE.W)
|
||||
if not pf_pv.closed:
|
||||
pf_pv.write(pyi_buf_pv, pyi_pos_pv)
|
||||
pf_pv.close()
|
||||
@@ -722,7 +722,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
force_translate: int = 0
|
||||
vpi_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "vpi")
|
||||
if vpi_path_1b is not None:
|
||||
vf_1b: fileio.File* = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
vf_1b: io.File* = io.File(vpi_path_1b, io.MODE.R)
|
||||
if not vf_1b.closed:
|
||||
vbuf_1b: bytes = stdlib.malloc(1048576)
|
||||
if vbuf_1b is not None:
|
||||
@@ -757,13 +757,13 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
VLogger.info(f"contains a class definition, forcing translation: {rp}(sha1={sha1})", "Phase1")
|
||||
else:
|
||||
# Skip already-existing stubs (on-demand translation)
|
||||
sf: fileio.File* = fileio.File(stub_path, fileio.MODE.R)
|
||||
sf: io.File* = io.File(stub_path, io.MODE.R)
|
||||
if not sf.closed:
|
||||
sf.close()
|
||||
# Check that text.ll exists too (vtable scan needs it)
|
||||
text_path: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "text.ll")
|
||||
if text_path is not None:
|
||||
tf: fileio.File* = fileio.File(text_path, fileio.MODE.R)
|
||||
tf: io.File* = io.File(text_path, io.MODE.R)
|
||||
if not tf.closed:
|
||||
tf.close()
|
||||
# The sidecar ({sha1}.meta) and online FULL artifact ({sha1}.full.ll) must also exist;
|
||||
@@ -771,7 +771,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
meta_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "meta")
|
||||
meta_ok_1b: int = 0
|
||||
if meta_path_1b is not None:
|
||||
mf_chk: fileio.File* = fileio.File(meta_path_1b, fileio.MODE.R)
|
||||
mf_chk: io.File* = io.File(meta_path_1b, io.MODE.R)
|
||||
if not mf_chk.closed:
|
||||
mf_chk.close()
|
||||
meta_ok_1b = 1
|
||||
@@ -779,7 +779,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
full_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "full.ll")
|
||||
full_ok_1b: int = 0
|
||||
if full_path_1b is not None:
|
||||
ff_chk: fileio.File* = fileio.File(full_path_1b, fileio.MODE.R)
|
||||
ff_chk: io.File* = io.File(full_path_1b, io.MODE.R)
|
||||
if not ff_chk.closed:
|
||||
ff_chk.close()
|
||||
full_ok_1b = 1
|
||||
@@ -804,7 +804,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
|
||||
# Read file contents
|
||||
file_path: str = entry.Path
|
||||
f: fileio.File* = fileio.File(file_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(file_path, io.MODE.R)
|
||||
if f is None:
|
||||
VLogger.error(f"cannot open (f=None): {file_path}", "Phase1")
|
||||
failed += 1
|
||||
@@ -864,7 +864,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
# is only a fallback when the vpi is missing.
|
||||
vpi_path_1b: str = StubMergerCollect._sliced_path(temp_dir, dir_len, sha1, "vpi")
|
||||
if vpi_path_1b is not None:
|
||||
vf_1b: fileio.File* = fileio.File(vpi_path_1b, fileio.MODE.R)
|
||||
vf_1b: io.File* = io.File(vpi_path_1b, io.MODE.R)
|
||||
vpi_exists_1b: int = 0
|
||||
if not vf_1b.closed:
|
||||
vf_1b.close()
|
||||
@@ -874,7 +874,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
if pyi_buf is not None:
|
||||
pyi_pos: sizet = StubConverter._GeneratePyiFromAst(mb, tree, entry.Path, pyi_buf, Phase1.PYI_BUF_SIZE)
|
||||
if pyi_pos > 0:
|
||||
pf_1b: fileio.File* = fileio.File(vpi_path_1b, fileio.MODE.W)
|
||||
pf_1b: io.File* = io.File(vpi_path_1b, io.MODE.W)
|
||||
if not pf_1b.closed:
|
||||
pf_1b.write(pyi_buf, pyi_pos)
|
||||
pf_1b.close()
|
||||
@@ -948,7 +948,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
dir_len_p1: sizet = string.strlen(temp_dir)
|
||||
stub_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "stub.ll")
|
||||
if stub_path_p1 is not None:
|
||||
sf_p1: fileio.File* = fileio.File(stub_path_p1, fileio.MODE.W)
|
||||
sf_p1: io.File* = io.File(stub_path_p1, io.MODE.W)
|
||||
if not sf_p1.closed:
|
||||
sf_p1.write(stub_buf, stub_len)
|
||||
sf_p1.close()
|
||||
@@ -969,7 +969,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
# save text.ll
|
||||
text_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "text.ll")
|
||||
if text_path_p1 is not None:
|
||||
tf_p1: fileio.File* = fileio.File(text_path_p1, fileio.MODE.W)
|
||||
tf_p1: io.File* = io.File(text_path_p1, io.MODE.W)
|
||||
if not tf_p1.closed:
|
||||
tf_p1.write(text_buf, text_len)
|
||||
tf_p1.close()
|
||||
@@ -987,7 +987,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
full_len_p1: sizet = string.strlen(full_buf_p1)
|
||||
full_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "full.ll")
|
||||
if full_path_p1 is not None:
|
||||
ff_p1: fileio.File* = fileio.File(full_path_p1, fileio.MODE.W)
|
||||
ff_p1: io.File* = io.File(full_path_p1, io.MODE.W)
|
||||
if not ff_p1.closed:
|
||||
ff_p1.write(full_buf_p1, full_len_p1)
|
||||
ff_p1.close()
|
||||
@@ -1009,7 +1009,7 @@ def RunPhase1(mb: memhub.MemBuddy*, includes_dir: str, temp_dir: str, log: VLogg
|
||||
# save dependencies(_imported_modules) for Phase B
|
||||
deps_path_p1: str = StubMergerCollect._sliced_path(temp_dir, dir_len_p1, sha1, "deps.txt")
|
||||
if deps_path_p1 is not None:
|
||||
df_p1: fileio.File* = fileio.File(deps_path_p1, fileio.MODE.W)
|
||||
df_p1: io.File* = io.File(deps_path_p1, io.MODE.W)
|
||||
if not df_p1.closed:
|
||||
if tr._imported_modules is not None:
|
||||
dl: sizet = string.strlen(tr._imported_modules)
|
||||
|
||||
@@ -2,7 +2,7 @@ from stdint import *
|
||||
import string
|
||||
import stdlib
|
||||
import memhub
|
||||
import io as fileio
|
||||
import io
|
||||
import ast
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.IncludesScanner as IncludesScanner
|
||||
@@ -52,7 +52,7 @@ def _ScanClassInheritance(mb: memhub.MemBuddy*, result: IncludesScanner.ScanResu
|
||||
|
||||
# read the file
|
||||
file_path: str = entry.Path
|
||||
f: fileio.File* = fileio.File(file_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(file_path, io.MODE.R)
|
||||
if f.closed: continue
|
||||
|
||||
# read_all's capacity includes the terminator (reads at most cap-1 bytes); longer files are truncated
|
||||
@@ -215,7 +215,7 @@ def _PreRegisterAllGenericTemplates(mb: memhub.MemBuddy*, result: IncludesScanne
|
||||
if entry_pg is None or entry_pg.Sha1 is None: continue
|
||||
# read the file
|
||||
file_path_pg: str = entry_pg.Path
|
||||
f_pg: fileio.File* = fileio.File(file_path_pg, fileio.MODE.R)
|
||||
f_pg: io.File* = io.File(file_path_pg, io.MODE.R)
|
||||
if f_pg.closed: continue
|
||||
# read_all's capacity includes the terminator (reads at most cap-1 bytes); longer files are truncated
|
||||
if f_pg.size() >= Phase1.SRC_BUF_SIZE:
|
||||
|
||||
@@ -5,7 +5,7 @@ import string
|
||||
import stdlib
|
||||
import memhub
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import win32.win32file
|
||||
import win32.win32base
|
||||
import sys
|
||||
@@ -218,7 +218,7 @@ def _PreRegisterAppGenericTemplates(mb: memhub.MemBuddy*, entries: SrcFileEntry*
|
||||
ent_pa: SrcFileEntry* = (SrcFileEntry*)(ea_pa)
|
||||
if ent_pa is None or ent_pa.Path is None or ent_pa.Sha1 is None: continue
|
||||
# Read the file
|
||||
f_pa: fileio.File* = fileio.File(ent_pa.Path, fileio.MODE.R)
|
||||
f_pa: io.File* = io.File(ent_pa.Path, io.MODE.R)
|
||||
if f_pa.closed: continue
|
||||
# read_all's capacity includes the terminator (reads at most cap-1 bytes); longer files are truncated
|
||||
if f_pa.size() >= SRC_BUF_SIZE:
|
||||
@@ -382,7 +382,7 @@ def _PhaseATextLLExists(temp_dir: str, td_len: sizet, sha1: str) -> int:
|
||||
if temp_dir is None or td_len == 0 or sha1 is None or string.strlen(sha1) < 2: return 0
|
||||
tpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "text.ll")
|
||||
if tpath is None: return 0
|
||||
tf: fileio.File* = fileio.File(tpath, fileio.MODE.R)
|
||||
tf: io.File* = io.File(tpath, io.MODE.R)
|
||||
exists: int = 0
|
||||
if not tf.closed:
|
||||
tf.close()
|
||||
@@ -407,7 +407,7 @@ def _PhaseADumpNode(temp_dir: str, td_len: sizet, sha1: str, depth: int, prefix:
|
||||
# Fallback: read {temp_dir}/{prefix}/{sha1}.deps.txt (Phase1 already wrote it for includes)
|
||||
dpath: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "deps.txt")
|
||||
if dpath is not None:
|
||||
df: fileio.File* = fileio.File(dpath, fileio.MODE.R)
|
||||
df: io.File* = io.File(dpath, io.MODE.R)
|
||||
if not df.closed:
|
||||
deps = stdlib.malloc(PA_DEPS_MAX_STR)
|
||||
if deps is not None:
|
||||
@@ -570,7 +570,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
# _sha1_map.txt 落在构建目录(temp 的上一级),方便直接按 SHA1 反查源文件
|
||||
map_path_am: bytes = StubMergerCollect.Sha1MapPath(mb, temp_dir)
|
||||
if map_path_am is not None:
|
||||
mf: fileio.File* = fileio.File(map_path_am, fileio.MODE.A)
|
||||
mf: io.File* = io.File(map_path_am, io.MODE.A)
|
||||
line_am: bytes = stdlib.malloc(512)
|
||||
# First fill the in-memory store (no file I/O), then write _sha1_map.txt
|
||||
app_filled: int = 0
|
||||
@@ -626,7 +626,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | failed to build vpi path", "PhaseA")
|
||||
continue
|
||||
vf_vp2: fileio.File* = fileio.File(vpi_path_vp2, fileio.MODE.R)
|
||||
vf_vp2: io.File* = io.File(vpi_path_vp2, io.MODE.R)
|
||||
if not vf_vp2.closed:
|
||||
vf_vp2.close()
|
||||
vpi_skipped_p2 += 1
|
||||
@@ -635,7 +635,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
stdlib.free(vpi_path_vp2)
|
||||
# Read the source -> parse the AST -> generate the vpi (rel_path = ent_vp2.Path: vpi content does
|
||||
# not depend on it; it is only used for fatal_error attribution, pointing at this source file)
|
||||
f_vp2: fileio.File* = fileio.File(ent_vp2.Path, fileio.MODE.R)
|
||||
f_vp2: io.File* = io.File(ent_vp2.Path, io.MODE.R)
|
||||
if f_vp2.closed:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | cannot open source file", "PhaseA")
|
||||
@@ -691,7 +691,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
if pyi_pos_vp2 > 0:
|
||||
pyi_path_vp2: str = StubMergerCollect._sliced_path(temp_dir, td_len_vpa, ent_vp2.Sha1, "vpi")
|
||||
if pyi_path_vp2 is not None:
|
||||
pf_vp2: fileio.File* = fileio.File(pyi_path_vp2, fileio.MODE.W)
|
||||
pf_vp2: io.File* = io.File(pyi_path_vp2, io.MODE.W)
|
||||
if pf_vp2.closed:
|
||||
# Silent here used to mean "no App .vpi at all" and every cross-module
|
||||
# return-type lookup later failed. Report the exact path instead.
|
||||
@@ -944,7 +944,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
# Save stub.ll (sliced path: temp_dir/{sha1 prefix}/{sha1}.stub.ll)
|
||||
stub_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "stub.ll")
|
||||
if stub_path_a is not None:
|
||||
sf_a: fileio.File* = fileio.File(stub_path_a, fileio.MODE.W)
|
||||
sf_a: io.File* = io.File(stub_path_a, io.MODE.W)
|
||||
if not sf_a.closed:
|
||||
sf_a.write(stub_buf_a, stub_len_a)
|
||||
sf_a.close()
|
||||
@@ -960,7 +960,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
# Save text.ll (sliced path)
|
||||
text_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "text.ll")
|
||||
if text_path_a is not None:
|
||||
tf_a: fileio.File* = fileio.File(text_path_a, fileio.MODE.W)
|
||||
tf_a: io.File* = io.File(text_path_a, io.MODE.W)
|
||||
if not tf_a.closed:
|
||||
tf_a.write(text_buf_a, text_len_a)
|
||||
tf_a.close()
|
||||
@@ -977,7 +977,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
full_len_a: sizet = string.strlen(full_buf_a)
|
||||
full_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "full.ll")
|
||||
if full_path_a is not None:
|
||||
ffa: fileio.File* = fileio.File(full_path_a, fileio.MODE.W)
|
||||
ffa: io.File* = io.File(full_path_a, io.MODE.W)
|
||||
if not ffa.closed:
|
||||
ffa.write(full_buf_a, full_len_a)
|
||||
ffa.close()
|
||||
@@ -994,7 +994,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
# Save dependencies (_imported_modules) for Phase B (sliced path)
|
||||
deps_path_a: str = StubMergerCollect._sliced_path(temp_dir, td_len_pa, ent.Sha1, "deps.txt")
|
||||
if deps_path_a is not None:
|
||||
df_a: fileio.File* = fileio.File(deps_path_a, fileio.MODE.W)
|
||||
df_a: io.File* = io.File(deps_path_a, io.MODE.W)
|
||||
if not df_a.closed:
|
||||
if tr_a._imported_modules is not None:
|
||||
dl_a: sizet = string.strlen(tr_a._imported_modules)
|
||||
@@ -1346,7 +1346,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
inc_stub_len: sizet = string.strlen(inc_stub_buf)
|
||||
inc_stub_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "stub.ll")
|
||||
if inc_stub_path is not None:
|
||||
isf: fileio.File* = fileio.File(inc_stub_path, fileio.MODE.W)
|
||||
isf: io.File* = io.File(inc_stub_path, io.MODE.W)
|
||||
if not isf.closed:
|
||||
isf.write(inc_stub_buf, inc_stub_len)
|
||||
isf.close()
|
||||
@@ -1359,7 +1359,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
inc_text_len: sizet = string.strlen(inc_text_buf)
|
||||
inc_text_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "text.ll")
|
||||
if inc_text_path is not None:
|
||||
itf: fileio.File* = fileio.File(inc_text_path, fileio.MODE.W)
|
||||
itf: io.File* = io.File(inc_text_path, io.MODE.W)
|
||||
if not itf.closed:
|
||||
itf.write(inc_text_buf, inc_text_len)
|
||||
itf.close()
|
||||
@@ -1374,7 +1374,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
inc_full_len: sizet = string.strlen(inc_full_buf)
|
||||
inc_full_path: str = StubMergerCollect._sliced_path(temp_dir, td_len_mi, inc_sha1_mi, "full.ll")
|
||||
if inc_full_path is not None:
|
||||
ifff: fileio.File* = fileio.File(inc_full_path, fileio.MODE.W)
|
||||
ifff: io.File* = io.File(inc_full_path, io.MODE.W)
|
||||
if not ifff.closed:
|
||||
ifff.write(inc_full_buf, inc_full_len)
|
||||
ifff.close()
|
||||
@@ -1403,19 +1403,19 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
diag_stub_ex: int = 0
|
||||
diag_text_ex: int = 0
|
||||
if diag_full is not None:
|
||||
df_diag_f: fileio.File* = fileio.File(diag_full, fileio.MODE.R)
|
||||
df_diag_f: io.File* = io.File(diag_full, io.MODE.R)
|
||||
if not df_diag_f.closed:
|
||||
diag_full_ex = 1
|
||||
df_diag_f.close()
|
||||
stdlib.free(diag_full)
|
||||
if diag_stub is not None:
|
||||
df_diag_s: fileio.File* = fileio.File(diag_stub, fileio.MODE.R)
|
||||
df_diag_s: io.File* = io.File(diag_stub, io.MODE.R)
|
||||
if not df_diag_s.closed:
|
||||
diag_stub_ex = 1
|
||||
df_diag_s.close()
|
||||
stdlib.free(diag_stub)
|
||||
if diag_text is not None:
|
||||
df_diag_t: fileio.File* = fileio.File(diag_text, fileio.MODE.R)
|
||||
df_diag_t: io.File* = io.File(diag_text, io.MODE.R)
|
||||
if not df_diag_t.closed:
|
||||
diag_text_ex = 1
|
||||
df_diag_t.close()
|
||||
@@ -1533,7 +1533,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str, ou
|
||||
obj_path_pc: str = StubMergerCollect._sliced_path(includes_binary_dir, ibd_len_pc, rsha1_pc, "obj")
|
||||
if obj_path_pc is not None:
|
||||
# Check whether the .obj file exists
|
||||
cf_pc: fileio.File* = fileio.File(obj_path_pc, fileio.MODE.R)
|
||||
cf_pc: io.File* = io.File(obj_path_pc, io.MODE.R)
|
||||
if not cf_pc.closed:
|
||||
cf_pc.close()
|
||||
# The .obj exists; append to final_obj_paths
|
||||
|
||||
@@ -6,7 +6,7 @@ import viperlib
|
||||
import lib.core.VLogger as VLogger
|
||||
from json.__parser import parse as json_parse
|
||||
from json import JsonValue, JSON_OBJECT, JSON_INT
|
||||
import io as fileio
|
||||
import io
|
||||
|
||||
|
||||
# Config - project configuration
|
||||
@@ -58,7 +58,7 @@ def Load_project_config(path: str) -> int:
|
||||
if _mbuddy is None: return 1
|
||||
|
||||
# Open file
|
||||
f: fileio.File* = fileio.File(path, fileio.MODE.R)
|
||||
f: io.File* = io.File(path, io.MODE.R)
|
||||
if f is None: return 1
|
||||
if f.closed: return 1
|
||||
|
||||
@@ -231,9 +231,9 @@ def _join_flags_array(flags_val: JsonValue*) -> str:
|
||||
def _join_path(rel: str, project_dir: str) -> str:
|
||||
"""Join a relative path with project_dir, expanding env vars and normalizing it."""
|
||||
if rel is None: return None
|
||||
# Env var expansion: only when '%' present (fileio.ExpandEnvironmentPath returns None on
|
||||
# Env var expansion: only when '%' present (io.ExpandEnvironmentPath returns None on
|
||||
# failure/no '%'); on failure keep the original string unchanged.
|
||||
ep: str = fileio.ExpandEnvironmentPath(rel)
|
||||
ep: str = io.ExpandEnvironmentPath(rel)
|
||||
if ep is not None: rel = ep
|
||||
# Absolute paths (starting with / or \) stay unchanged
|
||||
if rel[0] == '/' or rel[0] == '\\': return rel
|
||||
|
||||
@@ -6,7 +6,7 @@ import viperlib
|
||||
import hashlib
|
||||
import win32.win32file
|
||||
import win32.win32base
|
||||
import io as fileio
|
||||
import io
|
||||
|
||||
|
||||
# Utils - project utility functions (SHA1 hashing, directory cleanup)
|
||||
@@ -86,7 +86,7 @@ def JoinPath(a: str, b: str) -> str:
|
||||
def read_file_to_buf(path: str, buf_size: sizet) -> bytes:
|
||||
"""Read a whole file into a null-terminated malloc buffer, or None."""
|
||||
if path is None or buf_size <= 0: return None
|
||||
sf: fileio.File* = fileio.File(path, fileio.MODE.R)
|
||||
sf: io.File* = io.File(path, io.MODE.R)
|
||||
if sf.closed: return None
|
||||
buf: bytes = stdlib.malloc(buf_size)
|
||||
if buf is None:
|
||||
|
||||
@@ -10,7 +10,7 @@ import sys
|
||||
import memhub
|
||||
import mlirlite
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HT
|
||||
import lib.Stub.StubMerger.StubMergerStore as StubMergerStore
|
||||
@@ -1078,7 +1078,7 @@ def _ensure_vpi_ret_annot_loaded(src_sha1: str, temp_dir: str) -> int:
|
||||
# makes every lookup miss when the project uses slice level 0 or 2.
|
||||
vpi_path: str = _vpi_build_path(temp_dir, src_sha1, ".vpi")
|
||||
if vpi_path is None: return 0
|
||||
f: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
if f.closed:
|
||||
stdlib.free(vpi_path)
|
||||
return 0
|
||||
@@ -1649,7 +1649,7 @@ def _ensure_vpi_param_annot_loaded(src_sha1: str, temp_dir: str) -> int:
|
||||
# makes every lookup miss when the project uses slice level 0 or 2.
|
||||
vpi_path: str = _vpi_build_path(temp_dir, src_sha1, ".vpi")
|
||||
if vpi_path is None: return 0
|
||||
f: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
if f.closed:
|
||||
stdlib.free(vpi_path)
|
||||
return 0
|
||||
@@ -2196,7 +2196,7 @@ def _vpi_register_typedef_closure(pool: memhub.MemBuddy*, import_mods: str, temp
|
||||
# avoiding a StubMergerCollect cyclic dependency)
|
||||
vpi_path_r: str = _vpi_build_path(temp_dir, sha1_r, ".vpi")
|
||||
if vpi_path_r is None: continue
|
||||
f_r: fileio.File* = fileio.File(vpi_path_r, fileio.MODE.R)
|
||||
f_r: io.File* = io.File(vpi_path_r, io.MODE.R)
|
||||
if f_r.closed:
|
||||
stdlib.free(vpi_path_r)
|
||||
continue
|
||||
@@ -2614,7 +2614,7 @@ def PreRegisterVpiDefaults(pool: memhub.MemBuddy*, temp_dir: str) -> int:
|
||||
if sha1[0] == '\0': continue
|
||||
fpath: str = _vpi_build_path(temp_dir, sha1, ".vpi")
|
||||
if fpath is None: continue
|
||||
vf: fileio.File* = fileio.File(fpath, fileio.MODE.R)
|
||||
vf: io.File* = io.File(fpath, io.MODE.R)
|
||||
stdlib.free(fpath)
|
||||
if vf.closed: continue
|
||||
vbuf: bytes = stdlib.malloc(VPI_READ_BUF_SIZE)
|
||||
@@ -2779,7 +2779,7 @@ def PreRegisterVpiEnums(pool: memhub.MemBuddy*, temp_dir: str) -> int:
|
||||
if sha1[0] == '\0': continue
|
||||
fpath: str = _vpi_build_path(temp_dir, sha1, ".vpi")
|
||||
if fpath is None: continue
|
||||
vf: fileio.File* = fileio.File(fpath, fileio.MODE.R)
|
||||
vf: io.File* = io.File(fpath, io.MODE.R)
|
||||
stdlib.free(fpath)
|
||||
if vf.closed: continue
|
||||
vbuf: bytes = stdlib.malloc(VPI_READ_BUF_SIZE)
|
||||
@@ -2851,7 +2851,7 @@ def LookupSignDefaultsByName(pool: memhub.MemBuddy*, sha1: str, name: str, kinds
|
||||
if temp_dir is None: return -1
|
||||
fpath: str = _vpi_build_path(temp_dir, sha1, ".vpi")
|
||||
if fpath is None: return -1
|
||||
vf: fileio.File* = fileio.File(fpath, fileio.MODE.R)
|
||||
vf: io.File* = io.File(fpath, io.MODE.R)
|
||||
stdlib.free(fpath)
|
||||
if vf.closed: return -1
|
||||
vbuf: bytes = stdlib.malloc(VPI_READ_BUF_SIZE)
|
||||
@@ -2978,7 +2978,7 @@ def _ParseVpiIntoModuleImpl(pool: memhub.MemBuddy*, mod: mlirlite.LLVMModule*, v
|
||||
if pool is None or mod is None or vpi_path is None or trans is None: return 0
|
||||
|
||||
# 1. read the .vpi file
|
||||
f: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
if f.closed: return 0
|
||||
vpi_buf: bytes = stdlib.malloc(VPI_READ_BUF_SIZE)
|
||||
if vpi_buf is None:
|
||||
@@ -3377,7 +3377,7 @@ def _ensure_dep_vpi_injected(pool: memhub.MemBuddy*, mod: mlirlite.LLVMModule*,
|
||||
if path_i is None: return 0
|
||||
if sub_len_i > 0: viperlib.snprintf(path_i, path_len_i, "%s/%s/%s.vpi", temp_dir, sub_i, dep_sha1)
|
||||
else: viperlib.snprintf(path_i, path_len_i, "%s/%s.vpi", temp_dir, dep_sha1)
|
||||
vf_i: fileio.File* = fileio.File(path_i, fileio.MODE.R)
|
||||
vf_i: io.File* = io.File(path_i, io.MODE.R)
|
||||
if vf_i.closed:
|
||||
stdlib.free(path_i)
|
||||
return 0
|
||||
@@ -4332,7 +4332,7 @@ def _repl_stub_path(sha1: str, ext: str) -> str:
|
||||
def _repl_stub_readtext(path: str) -> str:
|
||||
"""Read stub text (stdlib.malloc, caller frees); None if missing or over the size cap."""
|
||||
if path is None: return None
|
||||
f: fileio.File* = fileio.File(path, fileio.MODE.R)
|
||||
f: io.File* = io.File(path, io.MODE.R)
|
||||
if f is None or f.closed: return None
|
||||
sz: sizet = f.size()
|
||||
if sz <= 0 or sz >= _REPL_STUB_TXT_CAP:
|
||||
|
||||
@@ -6,7 +6,7 @@ import stdlib
|
||||
import mlirlite
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import io as fileio
|
||||
import io
|
||||
import viperlib
|
||||
import sys
|
||||
import ast
|
||||
@@ -451,7 +451,7 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy*, source_dir: str, temp_dir: str,
|
||||
td_len_w: sizet = string.strlen(temp_dir)
|
||||
deps_path_w: str = StubMergerCollect._sliced_path(temp_dir, td_len_w, sha1_r2, "deps.txt")
|
||||
if deps_path_w is not None:
|
||||
df_w: fileio.File* = fileio.File(deps_path_w, fileio.MODE.W)
|
||||
df_w: io.File* = io.File(deps_path_w, io.MODE.W)
|
||||
if not df_w.closed:
|
||||
dl_w: sizet = string.strlen(deps_r2)
|
||||
if dl_w > 0: df_w.write(deps_r2, dl_w)
|
||||
@@ -503,7 +503,7 @@ def LoadFullIR(temp_dir: str, sha1: str, out_buf: bytes, out_size: sizet) -> siz
|
||||
td_len: sizet = string.strlen(temp_dir)
|
||||
p: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1, "full.ll")
|
||||
if p is None: return 0
|
||||
f: fileio.File* = fileio.File(p, fileio.MODE.R)
|
||||
f: io.File* = io.File(p, io.MODE.R)
|
||||
stdlib.free(p)
|
||||
out_buf[0] = '\0'
|
||||
if f.closed: return 0
|
||||
@@ -567,7 +567,7 @@ def LoadDepVpiIntoModule(pool: memhub.MemBuddy*, mod: mlirlite.LLVMModule*, impo
|
||||
vpi_path: str = StubMergerCollect._sliced_path(temp_dir, td_len, sha1_val, "vpi")
|
||||
if vpi_path is not None:
|
||||
# Check that the .vpi file exists (is readable)
|
||||
vf: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
vf: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
if not vf.closed:
|
||||
vf.close()
|
||||
# Parse the .vpi via VpiReader and inject declares (the error context frame is kept by the caller HandlesTranslator)
|
||||
|
||||
@@ -5,7 +5,7 @@ import stdlib
|
||||
import mlirlite
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import io as fileio
|
||||
import io
|
||||
import viperlib
|
||||
import sys
|
||||
import ast
|
||||
@@ -42,7 +42,7 @@ def _sliced_path(temp_dir: str, td_len: sizet, sha1: str, ext: str) -> str:
|
||||
sub_len = string.strlen(subdir_buf)
|
||||
|
||||
# Ensure subdir {temp_dir}/{subdir} exists.
|
||||
# Otherwise fileio.File(MODE.W) fails silently (file.closed==True) and the reader returns 0.
|
||||
# Otherwise io.File(MODE.W) fails silently (file.closed==True) and the reader returns 0.
|
||||
dir_path_len: sizet = td_len + sub_len + 2
|
||||
dir_path: bytes = stdlib.malloc(dir_path_len)
|
||||
if dir_path is not None:
|
||||
@@ -115,7 +115,7 @@ def WriteIncludesSha1Map(mb: memhub.MemBuddy*, temp_dir: str, scan_result: Inclu
|
||||
if map_path is None: return 1
|
||||
|
||||
# Open the file for writing (CREATE_ALWAYS)
|
||||
f: fileio.File* = fileio.File(map_path, fileio.MODE.W)
|
||||
f: io.File* = io.File(map_path, io.MODE.W)
|
||||
stdlib.free(map_path)
|
||||
if f.closed: return 1
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import stdlib
|
||||
import mlirlite
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import io as fileio
|
||||
import io
|
||||
import viperlib
|
||||
import sys
|
||||
import ast
|
||||
@@ -40,7 +40,7 @@ def WriteModuleMeta(mod: mlirlite.LLVMModule*, temp_dir: str, td_len: sizet, sha
|
||||
return 1
|
||||
# 与其他模块一致用指针形式:File 是类(构造函数返回实例指针),值形式在部分编译器
|
||||
# 上会读不到真实句柄状态(closed 恒为默认值)。
|
||||
mf: fileio.File* = fileio.File(mpath, fileio.MODE.W)
|
||||
mf: io.File* = io.File(mpath, io.MODE.W)
|
||||
if mf.closed:
|
||||
VLogger.error(f"meta write: cannot open {mpath}", "Meta")
|
||||
return 1
|
||||
@@ -126,7 +126,7 @@ def _MetaHasDef(temp_dir: str, td_len: sizet, sha1: str) -> int:
|
||||
if mpath is None: return -1
|
||||
# 指针形式(见 WriteModuleMeta 注释):值形式读不到真实的 closed/handle 状态,
|
||||
# 文件不存在时 mf.closed 仍为默认 false,会把"读不到 meta"误判成"可读且无 DEF"。
|
||||
mf: fileio.File* = fileio.File(mpath, fileio.MODE.R)
|
||||
mf: io.File* = io.File(mpath, io.MODE.R)
|
||||
stdlib.free(mpath)
|
||||
if mf.closed: return -1
|
||||
mbuf: bytes = stdlib.malloc(StubMerger.STUB_READ_BUF_SIZE)
|
||||
|
||||
@@ -5,7 +5,7 @@ import stdlib
|
||||
import mlirlite
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import io as fileio
|
||||
import io
|
||||
import viperlib
|
||||
import sys
|
||||
import ast
|
||||
|
||||
@@ -2,7 +2,7 @@ from stdint import *
|
||||
import string
|
||||
import stdio
|
||||
import stdlib
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.core.VLogger as VLogger
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ define DIAG_MAX_FRAMES = 32 # 调用链上限(与 TypeGenMixin.TRACE_MAX 对
|
||||
struct DiagEntry:
|
||||
# 字段名不要与"本模块 import 的类名"重名:TPC 的类型/符号表按**非限定名**索引
|
||||
# (Gen.structs / SymbolTable / _mangle_func_name),曾把本字段的 `File` 与
|
||||
# `win32.fileio.File` 撞在一起,导致同模块 `fileio.File(...)` 的构造调用把
|
||||
# `win32.fileio.File` 撞在一起,导致同模块 `io.File(...)` 的构造调用把
|
||||
# `File.__before_init__` 的 self 形参解析成 `i8**`(llvmlite: "Type of #1 arg
|
||||
# mismatch: i8** != %"...fileio.File"*")。故此处用 FileName 而非 File。
|
||||
FileName: str # 当前帧(错误点)文件
|
||||
@@ -198,7 +198,7 @@ def free_entry(ent: DiagEntry*) -> int:
|
||||
def read_source_line(file_path: str, lineno: int) -> str:
|
||||
"""读第 lineno 行;返回 stdlib 分配的缓冲(调用方 free),读不到返回 None"""
|
||||
if file_path is None or lineno <= 0: return None
|
||||
f: fileio.File* = fileio.File(file_path, fileio.MODE.R)
|
||||
f: io.File* = io.File(file_path, io.MODE.R)
|
||||
if f.closed: return None
|
||||
# Allocate by actual file size: a fixed 256KB buffer truncated large files so late line
|
||||
# numbers were unreadable. The 64MB cap guards against reading abnormally huge files.
|
||||
|
||||
@@ -6,7 +6,7 @@ import string
|
||||
import stdio
|
||||
import stdlib
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HT
|
||||
import lib.Stub.StubMerger.StubMergerStore as StubMergerStore
|
||||
@@ -475,7 +475,7 @@ novirtual class AssignGenMixin:
|
||||
if name is None: return None
|
||||
fp: str = self.Gen.TypeGenResolve.get_current_file()
|
||||
if fp is None: return None
|
||||
f: fileio.File* = fileio.File(fp, fileio.MODE.R)
|
||||
f: io.File* = io.File(fp, io.MODE.R)
|
||||
if f.closed: return None
|
||||
BUF_SZ: sizet = 1048576
|
||||
buf: bytes = stdlib.malloc(BUF_SZ)
|
||||
@@ -900,7 +900,7 @@ novirtual class AssignGenMixin:
|
||||
self.RecoverFound = 0
|
||||
fp: str = self.Gen.TypeGenResolve.get_current_file()
|
||||
if fp is None or name is None or out is None: return 0
|
||||
f: fileio.File* = fileio.File(fp, fileio.MODE.R)
|
||||
f: io.File* = io.File(fp, io.MODE.R)
|
||||
if f.closed: return 0
|
||||
BUF_SZ: sizet = 1048576
|
||||
buf: bytes = stdlib.malloc(BUF_SZ)
|
||||
|
||||
@@ -11,7 +11,7 @@ import string
|
||||
import stdio
|
||||
import stdlib
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import win32.win32file as win32file
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.Stub.StubMerger as StubMerger
|
||||
@@ -366,7 +366,7 @@ novirtual class CallGenBase:
|
||||
if buf is None:
|
||||
stdlib.free(vpi_path)
|
||||
return None
|
||||
vf: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
vf: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
stdlib.free(vpi_path)
|
||||
if vf.closed:
|
||||
stdlib.free(buf)
|
||||
@@ -1678,7 +1678,7 @@ novirtual class CallGenBase:
|
||||
stdlib.free(subdir_buf)
|
||||
|
||||
# read text.ll by actual size (a fixed buffer would truncate large modules); 64MB cap
|
||||
tf: fileio.File* = fileio.File(path_buf, fileio.MODE.R)
|
||||
tf: io.File* = io.File(path_buf, io.MODE.R)
|
||||
if tf.closed:
|
||||
stdlib.free(path_buf)
|
||||
return None
|
||||
|
||||
@@ -10,7 +10,7 @@ import string
|
||||
import stdlib
|
||||
import sys
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.core.Gen.Translator as HT
|
||||
import lib.core.Gen.Type.TypeSpec as TSpec
|
||||
|
||||
@@ -6,7 +6,7 @@ import string
|
||||
import stdio
|
||||
import stdlib
|
||||
import viperlib
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.Stub.StubMerger as StubMerger
|
||||
import lib.core.VLogger as VLogger
|
||||
import lib.Projectrans.Config as Config
|
||||
@@ -73,7 +73,7 @@ novirtual class ExprGenCdef(ExprGenBase.ExprGenBase):
|
||||
if buf is None: return None
|
||||
viperlib.snprintf(buf, path_len, "%s/%s", base_dir, rel_used)
|
||||
# existence check: if missing under SourceDir and IncludesDir differs, retry IncludesDir
|
||||
pf_chk: fileio.File* = fileio.File(buf, fileio.MODE.R)
|
||||
pf_chk: io.File* = io.File(buf, io.MODE.R)
|
||||
if pf_chk.closed:
|
||||
pf_chk.close()
|
||||
if Config.IncludesDir is not None and base_dir != Config.IncludesDir:
|
||||
@@ -83,7 +83,7 @@ novirtual class ExprGenCdef(ExprGenBase.ExprGenBase):
|
||||
buf = stdlib.malloc(path_len2)
|
||||
if buf is None: return None
|
||||
viperlib.snprintf(buf, path_len2, "%s/%s", Config.IncludesDir, rel_used)
|
||||
pf_chk2: fileio.File* = fileio.File(buf, fileio.MODE.R)
|
||||
pf_chk2: io.File* = io.File(buf, io.MODE.R)
|
||||
if pf_chk2.closed:
|
||||
pf_chk2.close()
|
||||
stdlib.free(buf)
|
||||
@@ -227,7 +227,7 @@ novirtual class ExprGenCdef(ExprGenBase.ExprGenBase):
|
||||
if pyi_buf is None:
|
||||
stdlib.free(pyi_path)
|
||||
return -1
|
||||
pf: fileio.File* = fileio.File(pyi_path, fileio.MODE.R)
|
||||
pf: io.File* = io.File(pyi_path, io.MODE.R)
|
||||
need_py_fallback: int = 0
|
||||
bytes_read: LONG = 0
|
||||
if pf.closed:
|
||||
@@ -313,7 +313,7 @@ novirtual class ExprGenCdef(ExprGenBase.ExprGenBase):
|
||||
VLogger.error(err_buf, "XMOD-CD")
|
||||
stdlib.free(pyi_buf)
|
||||
return -1
|
||||
pf = fileio.File(src_path, fileio.MODE.R)
|
||||
pf = io.File(src_path, io.MODE.R)
|
||||
stdlib.free(src_path)
|
||||
if pf.closed:
|
||||
stdlib.free(pyi_buf)
|
||||
|
||||
@@ -8,7 +8,7 @@ import stdlib
|
||||
import viperlib
|
||||
import stdio
|
||||
import sys
|
||||
import io as fileio
|
||||
import io
|
||||
import lib.Stub.StubMerger as StubMerger
|
||||
import lib.core.CompilerFactory as CompilerFactory
|
||||
import lib.core.Gen.Translator as HT
|
||||
@@ -488,7 +488,7 @@ novirtual class ImportsGenMixin:
|
||||
stdio.printf(' File "%s", line %d\n', file_name, lineno)
|
||||
# Show the source line's content (read line lineno for quick location)
|
||||
if lineno > 0 and file_name is not None:
|
||||
f_err: fileio.File* = fileio.File(file_name, fileio.MODE.R)
|
||||
f_err: io.File* = io.File(file_name, io.MODE.R)
|
||||
if not f_err.closed:
|
||||
line_buf_err: bytes = stdlib.malloc(512)
|
||||
if line_buf_err is not None:
|
||||
@@ -534,7 +534,7 @@ novirtual class ImportsGenMixin:
|
||||
path_buf[sep_pos] = '\0'
|
||||
string.strcat(path_buf, mod_name)
|
||||
string.strcat(path_buf, ".vp")
|
||||
fex: fileio.File* = fileio.File(path_buf, fileio.MODE.R)
|
||||
fex: io.File* = io.File(path_buf, io.MODE.R)
|
||||
if not fex.closed:
|
||||
fex.close()
|
||||
stdlib.free(path_buf)
|
||||
|
||||
@@ -17,7 +17,7 @@ import lib.core.CompilerFactory as CompilerFactory
|
||||
import lib.Projectrans.Config as Config
|
||||
|
||||
import lib.core.Gen.Type.TypeGenBase as TypeGenBase
|
||||
import io as fileio
|
||||
import io
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -972,7 +972,7 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase):
|
||||
if b_buf is None:
|
||||
stdlib.free(b_path)
|
||||
return None
|
||||
bf: fileio.File* = fileio.File(b_path, fileio.MODE.R)
|
||||
bf: io.File* = io.File(b_path, io.MODE.R)
|
||||
stdlib.free(b_path)
|
||||
if bf.closed:
|
||||
stdlib.free(b_buf)
|
||||
@@ -1144,7 +1144,7 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase):
|
||||
if m_buf is None:
|
||||
stdlib.free(m_path)
|
||||
return None
|
||||
mf: fileio.File* = fileio.File(m_path, fileio.MODE.R)
|
||||
mf: io.File* = io.File(m_path, io.MODE.R)
|
||||
stdlib.free(m_path)
|
||||
if mf.closed:
|
||||
stdlib.free(m_buf)
|
||||
|
||||
@@ -4,7 +4,7 @@ import string
|
||||
import stdlib
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import io as fileio
|
||||
import io
|
||||
import hashlib
|
||||
import viperlib
|
||||
import lib.Projectrans.Utils as Utils
|
||||
@@ -119,7 +119,7 @@ def compute_file_sha1(pool: memhub.MemBuddy*, file_path: str) -> str:
|
||||
BUF_SIZE: sizet = 1048576
|
||||
# Refuse larger files: hashing only the first 1 MiB gives two files that differ later the same
|
||||
# SHA1, and the SHA1 keys the stub/cache files (colliding modules would reuse each other's IR).
|
||||
sf_sz: fileio.File* = fileio.File(file_path, fileio.MODE.R)
|
||||
sf_sz: io.File* = io.File(file_path, io.MODE.R)
|
||||
if sf_sz.closed: return None
|
||||
too_big: int = 0
|
||||
if sf_sz.size() >= BUF_SIZE: too_big = 1
|
||||
|
||||
@@ -6,7 +6,7 @@ import viperlib
|
||||
import mlirlite
|
||||
import memhub
|
||||
import ast
|
||||
import io as fileio
|
||||
import io
|
||||
import win32.win32file as win32file
|
||||
import win32.win32base as win32base
|
||||
import win32.win32process as win32process
|
||||
@@ -931,7 +931,7 @@ def _repl_gen_includes_vpi(mb: memhub.MemBuddy*, sr: IncludesScanner.ScanResult*
|
||||
mb.reset_to(fm)
|
||||
continue
|
||||
# Existing stub -> reuse.
|
||||
vf: fileio.File* = fileio.File(vpi_path, fileio.MODE.R)
|
||||
vf: io.File* = io.File(vpi_path, io.MODE.R)
|
||||
if not vf.closed:
|
||||
vf.close()
|
||||
stdlib.free(vpi_path)
|
||||
@@ -939,7 +939,7 @@ def _repl_gen_includes_vpi(mb: memhub.MemBuddy*, sr: IncludesScanner.ScanResult*
|
||||
mb.reset_to(fm)
|
||||
continue
|
||||
# Read source file (1MB cap matching Phase1/BuildPipeline SRC_BUF_SIZE).
|
||||
f: fileio.File* = fileio.File(ent.Path, fileio.MODE.R)
|
||||
f: io.File* = io.File(ent.Path, io.MODE.R)
|
||||
if f.closed:
|
||||
stdlib.free(vpi_path)
|
||||
ReplIncVpiFail += 1
|
||||
@@ -990,7 +990,7 @@ def _repl_gen_includes_vpi(mb: memhub.MemBuddy*, sr: IncludesScanner.ScanResult*
|
||||
# Pass the absolute ent.Path as rel_path: vpi fatal_error reads source lines via it.
|
||||
pos: sizet = StubConverter._GeneratePyiFromAst(mb, tree, ent.Path, pyi_buf, _REPL_VPI_BUF_CAP)
|
||||
if pos > 0:
|
||||
pf: fileio.File* = fileio.File(vpi_path, fileio.MODE.W)
|
||||
pf: io.File* = io.File(vpi_path, io.MODE.W)
|
||||
if not pf.closed:
|
||||
pf.write(pyi_buf, pos)
|
||||
pf.close()
|
||||
@@ -1735,7 +1735,7 @@ def ReplExecFragment(mb: memhub.MemBuddy*, src: str) -> int:
|
||||
|
||||
# 4) Write the wrapped source to disk (used only for error echo: fatal_error reads this file).
|
||||
viperlib.snprintf(ReplSrcPath, _REPL_PATH_CAP, "%s/%s.vp", ReplTmpDir, ReplNameBuf)
|
||||
sf: fileio.File* = fileio.File(ReplSrcPath, fileio.MODE.W)
|
||||
sf: io.File* = io.File(ReplSrcPath, io.MODE.W)
|
||||
if not sf.closed:
|
||||
sf.write(ReplSrcBuf, string.strlen(ReplSrcBuf))
|
||||
sf.close()
|
||||
|
||||
Reference in new issue
Block a user