Commit 35e9b47c authored by Lei Wang's avatar Lei Wang Committed by LeiWang1999
Browse files

[Typo] Remove unused comments generated by copilot (#379)

* Remove debug print statement from OptimizeForTarget function and enhance library loading mechanism in Cython adapter. Implemented file locking during cache access and added checks for library size before loading. Introduced temporary file handling for safer compilation of Cython JIT adapter.

* Update comments in Cython adapter for clarity and consistency. Changed Chinese comments to English for better readability and understanding of the code's functionality, specifically regarding file handling and compilation processes.

* Refactor comments in Cython adapter for improved clarity. Updated comment on cache file deletion for consistency and removed unnecessary whitespace in file handling section.
parent 0181d721
...@@ -70,7 +70,7 @@ def get_cached_lib(source_code: str) -> Tuple[Optional[ctypes.CDLL], Path]: ...@@ -70,7 +70,7 @@ def get_cached_lib(source_code: str) -> Tuple[Optional[ctypes.CDLL], Path]:
if cache_path.stat().st_size > 1024: if cache_path.stat().st_size > 1024:
return ctypes.CDLL(str(cache_path)), cache_path return ctypes.CDLL(str(cache_path)), cache_path
else: else:
cache_path.unlink() # 删除不完整文件 cache_path.unlink() # remove the incomplete file
except Exception as e: except Exception as e:
logger.error(f"Failed to load cached library: {e}") logger.error(f"Failed to load cached library: {e}")
return None, cache_path return None, cache_path
...@@ -111,7 +111,7 @@ with open(cython_wrapper_path, "r") as f: ...@@ -111,7 +111,7 @@ with open(cython_wrapper_path, "r") as f:
with open(md5_path, "w") as f: with open(md5_path, "w") as f:
f.write(code_hash) f.write(code_hash)
# 使用临时文件进行编译 # compile the cython_wrapper.pyx file into .cpp
cython = get_cython_compiler() cython = get_cython_compiler()
if cython is None: if cython is None:
raise Exception("Cython is not installed, please install it first.") raise Exception("Cython is not installed, please install it first.")
...@@ -121,7 +121,7 @@ with open(cython_wrapper_path, "r") as f: ...@@ -121,7 +121,7 @@ with open(cython_wrapper_path, "r") as f:
command = f"{cc} -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I{python_include_path} {source_path} -o {temp_path}" command = f"{cc} -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I{python_include_path} {source_path} -o {temp_path}"
os.system(command) os.system(command)
# 原子替换操作 # rename the temp file to the library file
temp_path.rename(library_path) temp_path.rename(library_path)
except Exception as e: except Exception as e:
if temp_path.exists(): if temp_path.exists():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment