11import sys
22from collections .abc import Generator
33from pathlib import Path
4+ from typing import Any
45
56from .ffi import ffi , load_hostfxr
67from .types import Runtime , RuntimeInfo , StrOrPath
@@ -144,7 +145,7 @@ def info(self):
144145def _get_handle_for_runtime_config (
145146 dll , dotnet_root : StrOrPath , runtime_config : StrOrPath
146147):
147- params = ffi .new ("hostfxr_initialize_parameters*" )
148+ params : Any = ffi .new ("hostfxr_initialize_parameters*" )
148149 params .size = ffi .sizeof ("hostfxr_initialize_parameters" )
149150 # params.host_path = ffi.new("char_t[]", encode(sys.executable))
150151 params .host_path = ffi .NULL
@@ -164,7 +165,7 @@ def _get_handle_for_runtime_config(
164165def _get_handle_for_dotnet_command_line (
165166 dll , dotnet_root : StrOrPath , entry_dll : StrOrPath
166167):
167- params = ffi .new ("hostfxr_initialize_parameters*" )
168+ params : Any = ffi .new ("hostfxr_initialize_parameters*" )
168169 params .size = ffi .sizeof ("hostfxr_initialize_parameters" )
169170 params .host_path = ffi .NULL
170171 dotnet_root_p = ffi .new ("char_t[]" , encode (str (Path (dotnet_root ))))
@@ -209,4 +210,7 @@ def encode(string: str):
209210 return string .encode ("utf8" )
210211
211212 def decode (char_ptr ) -> str :
212- return ffi .string (char_ptr ).decode ("utf8" )
213+ res = ffi .string (char_ptr )
214+ if isinstance (res , bytes ):
215+ return res .decode ("utf8" )
216+ return str (res )
0 commit comments