@@ -61,18 +61,12 @@ public static string ProgramName
61
61
get
62
62
{
63
63
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 ) ?? "" ;
69
65
}
70
66
set
71
67
{
72
68
Marshal . FreeHGlobal ( _programName ) ;
73
- _programName = Runtime . IsPython3
74
- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
75
- : Marshal . StringToHGlobalAnsi ( value ) ;
69
+ _programName = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
76
70
Runtime . Py_SetProgramName ( _programName ) ;
77
71
}
78
72
}
@@ -82,18 +76,12 @@ public static string PythonHome
82
76
get
83
77
{
84
78
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 ) ?? "" ;
90
80
}
91
81
set
92
82
{
93
83
Marshal . FreeHGlobal ( _pythonHome ) ;
94
- _pythonHome = Runtime . IsPython3
95
- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
96
- : Marshal . StringToHGlobalAnsi ( value ) ;
84
+ _pythonHome = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
97
85
Runtime . Py_SetPythonHome ( _pythonHome ) ;
98
86
}
99
87
}
@@ -103,18 +91,12 @@ public static string PythonPath
103
91
get
104
92
{
105
93
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 ) ?? "" ;
111
95
}
112
96
set
113
97
{
114
98
Marshal . FreeHGlobal ( _pythonPath ) ;
115
- _pythonPath = Runtime . IsPython3
116
- ? UcsMarshaler . GetInstance ( "" ) . MarshalManagedToNative ( value )
117
- : Marshal . StringToHGlobalAnsi ( value ) ;
99
+ _pythonPath = UcsMarshaler . Py3UnicodePy2StringtoPtr ( value ) ;
118
100
Runtime . Py_SetPath ( _pythonPath ) ;
119
101
}
120
102
}
0 commit comments