File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed
Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -500,7 +500,7 @@ public class KeywordArguments : PyDict
500500 public static KeywordArguments kw ( params object [ ] kv )
501501 {
502502 var dict = new KeywordArguments ( ) ;
503- if ( kv . Length % 2 != 0 )
503+ if ( kv . Length % 2 != 0 )
504504 throw new ArgumentException ( "Must have an equal number of keys and values" ) ;
505505 for ( int i = 0 ; i < kv . Length ; i += 2 )
506506 {
@@ -521,5 +521,33 @@ public static PyObject Import(string name)
521521 {
522522 return PythonEngine . ImportModule ( name ) ;
523523 }
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+ }
524552 }
525553}
Original file line number Diff line number Diff line change @@ -2027,11 +2027,26 @@ internal unsafe static extern IntPtr
20272027 internal unsafe static extern IntPtr
20282028 PyImport_GetModuleDict( ) ;
20292029
2030-
2030+ #if PYTHON3
20312031 [ DllImport ( Runtime . dll , CallingConvention = CallingConvention . Cdecl ,
20322032 ExactSpelling = true , CharSet = CharSet . Ansi ) ]
20332033 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
20352050
20362051 [ DllImport ( Runtime . dll , CallingConvention = CallingConvention . Cdecl,
20372052 ExactSpelling = true, CharSet = CharSet . Ansi ) ]
You can’t perform that action at this time.
0 commit comments