一方代码在 /W4 下已零警告。剩余警告全部来自上游副本 (googlepinyinime-rev/、vendor/opencc/ 及其捆绑的 marisa), 按 AGENTS.md 保留上游原格式,有意不改。 - data_path.h、test_pinyin.cpp: _wgetenv 改 _wdupenv_s,返回值 用 optional 包一层,由 unique_ptr 负责 free - quanpin_dictionary.cpp: 去掉条件表达式内的赋值。外层查询原本 只用其真假,reset_cache_if_database_changed() 可能使其失效, 故保留重取 - build_sql_for_checking_word: 删掉从未使用的 jp 形参 - 未使用的 catch 形参、int/size_type 符号不匹配 - wav_writer.h: 形参 sample_rate 遮蔽同名命名空间常量,改名 requested_sample_rate;默认值改为直接引用该常量,去掉魔数 - pinyin_file_io.h: _wfopen/_wopen 改 _wfsopen/_wsopen_s 最后一项没有用微软推荐的 _wfopen_s: 它打开的文件不可共享,而这是 词库文件,Server、TSF DLL 和设置进程会并发读同一份。_SH_DENYNO 正是被弃用调用原本的共享语义,因此只消除警告,不改变行为。 _wsopen_s 的 pmode 传 0,唯一调用方 userdict.cpp 用的是 O_WRONLY, 不带 _O_CREAT。
33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
#pragma once
|
|
// Included only while compiling the pinned decoder's dicttrie/userdict translation units.
|
|
// Their unqualified calls resolve these namespace overloads; no CRT macros or vendor edits.
|
|
#ifdef _WIN32
|
|
#include <cstdio>
|
|
#include <filesystem>
|
|
#include <io.h>
|
|
#include <share.h>
|
|
#include <string>
|
|
namespace ime_pinyin
|
|
{
|
|
// _wfsopen / _wsopen_s instead of the deprecated _wfopen / _wopen: the secure
|
|
// _wfopen_s opens without sharing, while the decoder's dictionary files are read
|
|
// concurrently by the Server, the TSF DLL and the settings process. _SH_DENYNO is
|
|
// exactly the sharing mode the deprecated calls used, so this only silences C4996.
|
|
inline FILE *fopen(const char *path, const char *mode)
|
|
{
|
|
const std::wstring wide_mode(mode, mode + std::char_traits<char>::length(mode));
|
|
return _wfsopen(std::filesystem::u8path(path).c_str(), wide_mode.c_str(), _SH_DENYNO);
|
|
}
|
|
inline int open(const char *path, int flags)
|
|
{
|
|
int fd = -1;
|
|
// pmode is only consulted for _O_CREAT, which no caller passes.
|
|
if (_wsopen_s(&fd, std::filesystem::u8path(path).c_str(), flags, _SH_DENYNO, 0) != 0)
|
|
{
|
|
return -1;
|
|
}
|
|
return fd;
|
|
}
|
|
} // namespace ime_pinyin
|
|
#endif
|