-
Notifications
You must be signed in to change notification settings - Fork 748
When I try to use the Chinese namespace in C# #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@charSLee013 this is likely not going to be supported, but let's check with @yagweb if this makes any sense. |
This bug is very big, which is also a hindrance to the globalization of Pythonnet. We need to solve this problem urgently and hope to get your help :) |
Contributions are welcome! |
I tried to troubleshoot the problem, when running to moduleName = "中文";
IntPtr pyname = Runtime.PyString_FromString(moduleName);
out:>>>pyname == 0x0000000000000
IntPtr pyfilename = Runtime.PyString_FromString(filename); //error I tried to find the problem, and found it in internal static IntPtr PyString_FromString(string value)
{
byte[] len = Encoding.UTF8.GetBytes(value);
IntPtr a = PyString_FromStringAndSize(value, value.Length);
foreach (char t in value)
{
if (t >= 0x4e00 && t <= 0x9fbb)
{
a = PyString_FromStringAndSize(value, len.Length);
return a;
}
}
return a;
} The exciting thing is that it does. But in try
{
IntPtr module = Runtime.PyImport_AddModule("clr._extras");
out:>>>module == 0x00000000000000
IntPtr module_globals = Runtime.PyModule_GetDict(module); //error
IntPtr builtins = Runtime.PyEval_GetBuiltins();
Runtime.PyDict_SetItemString(module_globals, "__builtins__", builtins);
|
@charSLee013 It seems the exist of method PyString_FromString is to be compatible with python2. So for users it should not be used with unicode strings. A recommended fix is call PyUnicode_FromString instead of the faked PyString_FromStringAndSize method of Python3.
Even with this modification, Chinese namespace is not working now. The problem here is that pythonnet needs to support Python2 and Python3 at the same time. Python3 supports modules with chinese name but Python2 does not. So nobody tests this before. Since both .net and Python3 support Chinese namespace, pythonnet with Python3 should work with Chinese namespace in theory. It seems one problem is located in the import hooks (maybe not the only one), heavily debugging work is needed. |
Looking forward to your good news, this test result is very important @yagweb |
Pinvokestackimbalance is fixed in master branch @daixinwei2018 |
The fix was this has been merged to master, so I'll close this. Feel free to reopen if the version in the master branch doesn't solve the issue. |
Environment
Details
Hi,
THANK YOU SO MUCH!
The text was updated successfully, but these errors were encountered: