Skip to content

Commit

Permalink
Add back +1 element with explicit NULL
Browse files Browse the repository at this point in the history
Fun fact: this is required by ANSII C:
- https://stackoverflow.com/a/39096006/2719194
- https://code.activestate.com/lists/python-list/704158

and we did not yet initialize it properly.
  • Loading branch information
ax3l committed Jan 16, 2022
1 parent c0ed665 commit ba3cf5c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Python/pywarpx/_libwarpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,20 @@ def get_nattr_species(self, species_name):
def amrex_init(self, argv, mpi_comm=None):
# --- Construct the ctype list of strings to pass in
argc = len(argv)
self.argvC = (_LP_c_char * argc)()
# note: +1 since there is an extra char-string array element,
# that ANSII C requires to be a simple NULL entry
# https://stackoverflow.com/a/39096006/2719194
# https://code.activestate.com/lists/python-list/704158
self.argvC = (_LP_c_char * (argc + 1))()
print("amrex_init argv=", argv)
print("amrex_init len(argv)=", len(argv))
for i, arg in enumerate(argv):
enc_arg = arg.encode('utf-8')
print(enc_arg, len(enc_arg), repr(enc_arg), type(enc_arg))
#self.argvC[i] = ctypes.create_string_buffer(enc_arg)
self.argvC[i] = ctypes.c_char_p(enc_arg)
self.argvC[argc] = ctypes.c_char_p(b"\0")

print("len(argvC)=", len(self.argvC))
self.argvC = ctypes.cast(self.argvC, _LP_LP_c_char)
print("argc=", argc)
Expand Down

0 comments on commit ba3cf5c

Please sign in to comment.