Skip to content

Commit

Permalink
PyPy macOS: Fix Argv Encoding
Browse files Browse the repository at this point in the history
Trying to fix the macOS PyPy 3.7 error seen in #37
  • Loading branch information
ax3l committed Jan 7, 2022
1 parent 5da86ba commit bb76308
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 34 deletions.
34 changes: 0 additions & 34 deletions recipe/2626.patch

This file was deleted.

134 changes: 134 additions & 0 deletions recipe/2726.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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

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
the local encoding.

Alternatively, we can try encoding to `locale.getpreferredencoding()`
or setting the encoding forced to UTF-8.
---
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 9de8227397..925a276985 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('utf-8')))
+ ctypes.c_char_p(species_name.encode('ascii')))

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))()
for i, arg in enumerate(argv):
- enc_arg = arg.encode('utf-8')
+ enc_arg = arg.encode('ascii')
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('utf-8')), x.size,
+ ctypes.c_char_p(species_name.encode('ascii')), 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('utf-8'))
+ ctypes.c_char_p(species_name.encode('ascii'))
)

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('utf-8')), level,
+ ctypes.c_char_p(species_name.encode('ascii')), 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('utf-8')),
- ctypes.c_char_p(comp_name.encode('utf-8')),
+ ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(comp_name.encode('ascii')),
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('utf-8')),
- ctypes.c_char_p(pid_name.encode('utf-8'))
+ ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(pid_name.encode('ascii'))
)

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('utf-8')),
- ctypes.c_char_p(pid_name.encode('utf-8')), comm
+ ctypes.c_char_p(species_name.encode('ascii')),
+ ctypes.c_char_p(pid_name.encode('ascii')), 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('utf-8')),
+ ctypes.c_char_p(species_name.encode('ascii')),
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('utf-8')),
+ ctypes.c_char_p(species_name.encode('ascii')),
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('utf-8')),
+ ctypes.c_char_p(species_name.encode('ascii')),
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('utf-8')),
+ ctypes.c_char_p(species_name.encode('ascii')),
self.get_boundary_number(boundary), level,
ctypes.byref(num_tiles), ctypes.byref(particles_per_tile),
- ctypes.c_char_p(comp_name.encode('utf-8'))
+ ctypes.c_char_p(comp_name.encode('ascii'))
)

particle_data = []
4 changes: 4 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ package:
source:
url: https://github.com/ECP-WarpX/WarpX/archive/{{ version }}.tar.gz
sha256: {{ sha256 }}
patches:
# Fix encoding issues when passing inputs to AMReX
# https://github.com/ECP-WarpX/WarpX/pull/2726
- 2726.patch

build:
number: {{ build }}
Expand Down

0 comments on commit bb76308

Please sign in to comment.