| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f7f2fc0 commit eca5ac9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -500,7 +500,7 @@ public class KeywordArguments : PyDict | |||
| 500 | 500 | public static KeywordArguments kw(params object[] kv) | |
| 501 | 501 | { | |
| 502 | 502 | var dict = new KeywordArguments(); | |
| 503 | - if (kv.Length%2 != 0) | ||
| 503 | + if (kv.Length % 2 != 0) | ||
| 504 | 504 | throw new ArgumentException("Must have an equal number of keys and values"); | |
| 505 | 505 | for (int i = 0; i < kv.Length; i += 2) | |
| 506 | 506 | { | |
@@ -521,5 +521,33 @@ public static PyObject Import(string name) | |||
| 521 | 521 | { | |
| 522 | 522 | return PythonEngine.ImportModule(name); | |
| 523 | 523 | } | |
| 524 | + | ||
| 525 | + public static void SetArgv() | ||
| 526 | + { | ||
| 527 | + IEnumerable<string> args; | ||
| 528 | + try | ||
| 529 | + { | ||
| 530 | + args = Environment.GetCommandLineArgs(); | ||
| 531 | + } | ||
| 532 | + catch (NotSupportedException) | ||
| 533 | + { | ||
| 534 | + args = Enumerable.Empty<string>(); | ||
| 535 | + } | ||
| 536 | + | ||
| 537 | + SetArgv( | ||
| 538 | + new[] { "" }.Concat( | ||
| 539 | + Environment.GetCommandLineArgs().Skip(1) | ||
| 540 | + ) | ||
| 541 | + ); | ||
| 542 | + } | ||
| 543 | + | ||
| 544 | + public static void SetArgv(IEnumerable<string> argv) | ||
| 545 | + { | ||
| 546 | + using (GIL()) | ||
| 547 | + { | ||
| 548 | + var arr = argv.ToArray(); | ||
| 549 | + Runtime.PySys_SetArgvEx(arr.Length, arr, 0); | ||
| 550 | + } | ||
| 551 | + } | ||
| 524 | 552 | } | |
| 525 | 553 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2027,11 +2027,26 @@ internal unsafe static extern IntPtr | |||
| 2027 | 2027 | internal unsafe static extern IntPtr | |
| 2028 | 2028 | PyImport_GetModuleDict(); | |
| 2029 | 2029 | ||
| 2030 | - | ||
| 2030 | + #if PYTHON3 | ||
| 2031 | 2031 | [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, | |
| 2032 | 2032 | ExactSpelling = true, CharSet = CharSet.Ansi)] | |
| 2033 | 2033 | internal unsafe static extern void | |
| 2034 | - PySys_SetArgv(int argc, IntPtr argv); | ||
| 2034 | + PySys_SetArgvEx( | ||
| 2035 | + int argc, | ||
| 2036 | + [MarshalAsAttribute(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr)] | ||
| 2037 | + string[] argv, | ||
| 2038 | + int updatepath | ||
| 2039 | + ); | ||
| 2040 | + #elif PYTHON2 | ||
| 2041 | + [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, | ||
| 2042 | + ExactSpelling = true, CharSet = CharSet.Ansi)] | ||
| 2043 | + internal unsafe static extern void | ||
| 2044 | + PySys_SetArgvEx( | ||
| 2045 | + int argc, | ||
| 2046 | + string[] argv, | ||
| 2047 | + int updatepath | ||
| 2048 | + ); | ||
| 2049 | + #endif | ||
| 2035 | 2050 | ||
| 2036 | 2051 | [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl, | |
| 2037 | 2052 | ExactSpelling = true, CharSet = CharSet.Ansi)] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments