@@ -61,18 +61,12 @@ public static string ProgramName
6161 get
6262 {
6363 IntPtr p = Runtime . Py_GetProgramName ( ) ;
64- string result = Runtime . IsPython3
65- ? UcsMarshaler . PtrToStringUni ( p )
66- : Marshal . PtrToStringAnsi ( p ) ;
67-
68- return result ?? "" ;
64+ return UcsMarshaler . PtrToPy3UnicodePy2String ( p ) ?? "" ;
6965 }
7066 set
7167 {
7268 Marshal . FreeHGlobal ( _programName ) ;
73- _programName = Runtime . IsPython3
74- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
75- : Marshal . StringToHGlobalAnsi ( value ) ;
69+ _programName = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
7670 Runtime . Py_SetProgramName ( _programName ) ;
7771 }
7872 }
@@ -82,18 +76,12 @@ public static string PythonHome
8276 get
8377 {
8478 IntPtr p = Runtime . Py_GetPythonHome ( ) ;
85- string result = Runtime . IsPython3
86- ? UcsMarshaler . PtrToStringUni ( p )
87- : Marshal . PtrToStringAnsi ( p ) ;
88-
89- return result ?? "" ;
79+ return UcsMarshaler . PtrToPy3UnicodePy2String ( p ) ?? "" ;
9080 }
9181 set
9282 {
9383 Marshal . FreeHGlobal ( _pythonHome ) ;
94- _pythonHome = Runtime . IsPython3
95- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
96- : Marshal . StringToHGlobalAnsi ( value ) ;
84+ _pythonHome = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
9785 Runtime . Py_SetPythonHome ( _pythonHome ) ;
9886 }
9987 }
@@ -103,18 +91,12 @@ public static string PythonPath
10391 get
10492 {
10593 IntPtr p = Runtime . Py_GetPath ( ) ;
106- string result = Runtime . IsPython3
107- ? UcsMarshaler . PtrToStringUni ( p )
108- : Marshal . PtrToStringAnsi ( p ) ;
109-
110- return result ?? "" ;
94+ return UcsMarshaler . PtrToPy3UnicodePy2String ( p ) ?? "" ;
11195 }
11296 set
11397 {
11498 Marshal . FreeHGlobal ( _pythonPath ) ;
115- _pythonPath = Runtime . IsPython3
116- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
117- : Marshal . StringToHGlobalAnsi ( value ) ;
99+ _pythonPath = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
118100 Runtime . Py_SetPath ( _pythonPath ) ;
119101 }
120102 }
0 commit comments