Skip to content

Commit

Permalink
Update patch: only off-by-one error
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Jan 7, 2022
1 parent bb76308 commit bd24acd
Showing 1 changed file with 153 additions and 1 deletion.
154 changes: 153 additions & 1 deletion recipe/2726.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 74ce023ec98a3e2c01a91e8c23fa58cd8ac5e4e3 Mon Sep 17 00:00:00 2001
From: Axel Huebl <axel.huebl@plasma.ninja>
Date: Fri, 7 Jan 2022 06:28:12 -0800
Subject: [PATCH] Python: Argv Encoding ASCII
Subject: [PATCH 1/3] Python: Argv Encoding ASCII

Since we pass those arguments to argc/argv in C in the end, we might
want to stay with ASCII. Otherwise, the interpretation might not fit
Expand Down Expand Up @@ -132,3 +132,155 @@ index 9de8227397..925a276985 100755
)

particle_data = []

From e3ebfdaa5d54ac1be91d6a52adc8443d9cb918d1 Mon Sep 17 00:00:00 2001
From: Axel Huebl <axel.huebl@plasma.ninja>
Date: Fri, 7 Jan 2022 19:31:39 +0100
Subject: [PATCH 2/3] argvC: fix off-by-one error.

---
Python/pywarpx/_libwarpx.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 925a276985..8a23b64655 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -397,7 +397,7 @@ 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)
- argvC = (_LP_c_char * (argc+1))()
+ argvC = (_LP_c_char * argc)()
for i, arg in enumerate(argv):
enc_arg = arg.encode('ascii')
argvC[i] = ctypes.create_string_buffer(enc_arg)

From fa899eff4eedb857b66a76d6ea50af72a78c6c28 Mon Sep 17 00:00:00 2001
From: Axel Huebl <axel.huebl@plasma.ninja>
Date: Fri, 7 Jan 2022 10:32:45 -0800
Subject: [PATCH 3/3] Keep utf-8 encoding for now.

---
Python/pywarpx/_libwarpx.py | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 8a23b64655..75a34fc18b 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -392,14 +392,14 @@ def get_nattr_species(self, species_name):

'''
return self.libwarpx_so.warpx_nCompsSpecies(
- ctypes.c_char_p(species_name.encode('ascii')))
+ ctypes.c_char_p(species_name.encode('utf-8')))

def amrex_init(self, argv, mpi_comm=None):
# --- Construct the ctype list of strings to pass in
argc = len(argv)
argvC = (_LP_c_char * argc)()
for i, arg in enumerate(argv):
- enc_arg = arg.encode('ascii')
+ enc_arg = arg.encode('utf-8')
argvC[i] = ctypes.create_string_buffer(enc_arg)

if mpi_comm is None or MPI is None:
@@ -620,7 +620,7 @@ def add_particles(self, species_name, x=None, y=None, z=None, ux=None, uy=None,
attr[:,self.get_particle_comp_index(species_name, key)-3] = vals

self.libwarpx_so.warpx_addNParticles(
- ctypes.c_char_p(species_name.encode('ascii')), x.size,
+ ctypes.c_char_p(species_name.encode('utf-8')), x.size,
x, y, z, ux, uy, uz, nattr, attr, unique_particles
)

@@ -642,7 +642,7 @@ def get_particle_count(self, species_name):

'''
return self.libwarpx_so.warpx_getNumParticles(
- ctypes.c_char_p(species_name.encode('ascii'))
+ ctypes.c_char_p(species_name.encode('utf-8'))
)

def get_particle_structs(self, species_name, level):
@@ -670,7 +670,7 @@ def get_particle_structs(self, species_name, level):
particles_per_tile = _LP_c_int()
num_tiles = ctypes.c_int(0)
data = self.libwarpx_so.warpx_getParticleStructs(
- ctypes.c_char_p(species_name.encode('ascii')), level,
+ ctypes.c_char_p(species_name.encode('utf-8')), level,
ctypes.byref(num_tiles), ctypes.byref(particles_per_tile)
)

@@ -710,8 +710,8 @@ def get_particle_arrays(self, species_name, comp_name, level):
particles_per_tile = _LP_c_int()
num_tiles = ctypes.c_int(0)
data = self.libwarpx_so.warpx_getParticleArrays(
- ctypes.c_char_p(species_name.encode('ascii')),
- ctypes.c_char_p(comp_name.encode('ascii')),
+ ctypes.c_char_p(species_name.encode('utf-8')),
+ ctypes.c_char_p(comp_name.encode('utf-8')),
level, ctypes.byref(num_tiles), ctypes.byref(particles_per_tile)
)

@@ -883,8 +883,8 @@ def get_particle_comp_index(self, species_name, pid_name):

'''
return self.libwarpx_so.warpx_getParticleCompIndex(
- ctypes.c_char_p(species_name.encode('ascii')),
- ctypes.c_char_p(pid_name.encode('ascii'))
+ ctypes.c_char_p(species_name.encode('utf-8')),
+ ctypes.c_char_p(pid_name.encode('utf-8'))
)

def add_real_comp(self, species_name, pid_name, comm=True):
@@ -901,8 +901,8 @@ def add_real_comp(self, species_name, pid_name, comm=True):

'''
self.libwarpx_so.warpx_addRealComp(
- ctypes.c_char_p(species_name.encode('ascii')),
- ctypes.c_char_p(pid_name.encode('ascii')), comm
+ ctypes.c_char_p(species_name.encode('utf-8')),
+ ctypes.c_char_p(pid_name.encode('utf-8')), comm
)

def get_particle_boundary_buffer_size(self, species_name, boundary):
@@ -925,7 +925,7 @@ def get_particle_boundary_buffer_size(self, species_name, boundary):

'''
return self.libwarpx_so.warpx_getParticleBoundaryBufferSize(
- ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(species_name.encode('utf-8')),
self.get_boundary_number(boundary)
)

@@ -958,7 +958,7 @@ def get_particle_boundary_buffer_structs(self, species_name, boundary, level):
particles_per_tile = _LP_c_int()
num_tiles = ctypes.c_int(0)
data = self.libwarpx_so.warpx_getParticleBoundaryBufferStructs(
- ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(species_name.encode('utf-8')),
self.get_boundary_number(boundary), level,
ctypes.byref(num_tiles), ctypes.byref(particles_per_tile)
)
@@ -1005,16 +1005,16 @@ def get_particle_boundary_buffer(self, species_name, boundary, comp_name, level)
num_tiles = ctypes.c_int(0)
if comp_name == 'step_scraped':
data = self.libwarpx_so.warpx_getParticleBoundaryBufferScrapedSteps(
- ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(species_name.encode('utf-8')),
self.get_boundary_number(boundary), level,
ctypes.byref(num_tiles), ctypes.byref(particles_per_tile)
)
else:
data = self.libwarpx_so.warpx_getParticleBoundaryBuffer(
- ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(species_name.encode('utf-8')),
self.get_boundary_number(boundary), level,
ctypes.byref(num_tiles), ctypes.byref(particles_per_tile),
- ctypes.c_char_p(comp_name.encode('ascii'))
+ ctypes.c_char_p(comp_name.encode('utf-8'))
)

particle_data = []

0 comments on commit bd24acd

Please sign in to comment.