2424_host_interface = None
2525
2626
27- def init_host_interface ():
27+ def _init_host_interface ():
2828 global _host_interface
2929
3030 if _host_interface is None :
@@ -48,6 +48,7 @@ def set_local_input_output(value):
4848
4949
5050def read_input ():
51+ _init_host_interface ()
5152 return _host_interface .__faasm_read_input ()
5253
5354
@@ -56,6 +57,7 @@ def write_output(output):
5657 global output_data
5758 output_data = output
5859 else :
60+ _init_host_interface ()
5961 _host_interface .__faasm_write_output (output )
6062
6163
@@ -70,10 +72,12 @@ def get_output():
7072
7173
7274def read_state_size (key ):
75+ _init_host_interface ()
7376 return _host_interface .__faasm_read_state (bytes (key , "utf-8" ), None , 0 )
7477
7578
7679def read_state (key , state_len ):
80+ _init_host_interface ()
7781 state_len = int (state_len )
7882 buff = ctypes .create_string_buffer (state_len )
7983 _host_interface .__faasm_read_state (bytes (key , "utf-8" ), buff , state_len )
@@ -82,6 +86,7 @@ def read_state(key, state_len):
8286
8387
8488def read_state_offset (key , total_len , offset , offset_len ):
89+ _init_host_interface ()
8590 total_len = int (total_len )
8691 offset_len = int (offset_len )
8792 buff = ctypes .create_string_buffer (offset_len )
@@ -93,10 +98,12 @@ def read_state_offset(key, total_len, offset, offset_len):
9398
9499
95100def write_state (key , value ):
101+ _init_host_interface ()
96102 _host_interface .__faasm_write_state (bytes (key , "utf-8" ), value , len (value ))
97103
98104
99105def write_state_offset (key , total_len , offset , value ):
106+ _init_host_interface ()
100107 offset = int (offset )
101108 total_len = int (total_len )
102109
@@ -106,14 +113,17 @@ def write_state_offset(key, total_len, offset, value):
106113
107114
108115def push_state (key ):
116+ _init_host_interface ()
109117 _host_interface .__faasm_push_state (bytes (key , "utf-8" ))
110118
111119
112120def push_state_partial (key ):
121+ _init_host_interface ()
113122 _host_interface .__faasm_push_state_partial (bytes (key , "utf-8" ))
114123
115124
116125def pull_state (key , state_len ):
126+ _init_host_interface ()
117127 state_len = int (state_len )
118128 _host_interface .__faasm_pull_state (bytes (key , "utf-8" ), state_len )
119129
@@ -124,7 +134,9 @@ def chain(func, input_data):
124134 func (input_data )
125135 return 0
126136 else :
127- # Call native
137+ # Call into host interface
138+ _init_host_interface ()
139+
128140 func_name = func .__name__
129141 return _host_interface .__faasm_chain_py (
130142 bytes (func_name , "utf-8" ), input_data , len (input_data )
@@ -133,14 +145,16 @@ def chain(func, input_data):
133145
134146def await_call (call_id ):
135147 if PYTHON_LOCAL_CHAINING :
136- # Calls are run immediately
148+ # Calls are run immediately in local chaining
137149 return 0
138150 else :
139- # Call native
151+ _init_host_interface ()
140152 return _host_interface .__faasm_await_call (call_id )
141153
142154
143155def set_emulator_message (message_json ):
156+ _init_host_interface ()
157+
144158 message_bytes = bytes (message_json , "utf-8" )
145159 if PYTHON_LOCAL_OUTPUT :
146160 global output_data
@@ -150,8 +164,10 @@ def set_emulator_message(message_json):
150164
151165
152166def set_emulator_status (success ):
167+ _init_host_interface ()
153168 _host_interface .__set_emulator_status (success )
154169
155170
156171def get_emulator_async_response ():
172+ _init_host_interface ()
157173 return _host_interface .__get_emulator_async_response ()
0 commit comments