mirror of https://github.com/Jittor/Jittor
fix windows encoding error, thanks liduan for reporting this bug
This commit is contained in:
parent
61ea95b76f
commit
53b377ee7d
|
@ -9,7 +9,7 @@
|
|||
# file 'LICENSE.txt', which is part of this source code package.
|
||||
# ***************************************************************
|
||||
|
||||
__version__ = '1.3.1.43'
|
||||
__version__ = '1.3.1.44'
|
||||
from jittor_utils import lock
|
||||
with lock.lock_scope():
|
||||
ori_int = int
|
||||
|
|
|
@ -45,7 +45,13 @@ DEF_IS(string, PyObject*) to_py_object(const string& a) {
|
|||
|
||||
DEF_IS(string, string) from_py_object(PyObject* obj) {
|
||||
Py_ssize_t size;
|
||||
#ifdef _WIN32
|
||||
PyObjHolder a(PyUnicode_AsEncodedString(obj, win_encode.c_str(), "strict"));
|
||||
char* s;
|
||||
auto ret = PyBytes_AsStringAndSize(a.obj, &s, &size);
|
||||
#else
|
||||
const char* s = PyUnicode_AsUTF8AndSize(obj, &size);
|
||||
#endif
|
||||
CHECK(s);
|
||||
return string(s, size);
|
||||
}
|
||||
|
|
|
@ -316,9 +316,19 @@ int register_sigaction() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
string win_encode;
|
||||
#endif
|
||||
|
||||
static int log_init() {
|
||||
register_sigaction();
|
||||
std::atexit(log_exiting);
|
||||
#ifdef _WIN32
|
||||
if (getenv("JITTOR_ENCODE"))
|
||||
win_encode = getenv("JITTOR_ENCODE");
|
||||
else
|
||||
win_encode = "gbk";
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,4 +277,8 @@ bool check_vlog(const char* fileline, int verbose);
|
|||
|
||||
void system_with_check(const char* cmd, const char* cwd=nullptr);
|
||||
|
||||
#ifdef _WIN32
|
||||
extern string win_encode;
|
||||
#endif
|
||||
|
||||
} // jittor
|
Loading…
Reference in New Issue