aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar Axel Huebl <axel.huebl@plasma.ninja> 2021-11-20 17:14:45 -0800
committerGravatar GitHub <noreply@github.com> 2021-11-20 17:14:45 -0800
commitf87ee691277dedc1efca584b63b492ce1850d3fb (patch)
tree8e44a0daeaddd42cd4f0303762db311e85afc16d /Python/pywarpx
parent1ab82a3dd77863dba5ef14e06b019cfa8ae53e13 (diff)
downloadWarpX-f87ee691277dedc1efca584b63b492ce1850d3fb.tar.gz
WarpX-f87ee691277dedc1efca584b63b492ce1850d3fb.tar.zst
WarpX-f87ee691277dedc1efca584b63b492ce1850d3fb.zip
Python: More Nullptr Checks (#2574)
* Python: More Nullptr Checks I am debugging a couple of crashes while mitigating CI. One of them pointed to the locations here (`ValueError: NULL pointer access`), so I decided to add some checks. * Skip invalid tiles * Skip Empty Tiles But Check Pointer * Python: nullptr check in _array1d_from_pointer Make the methods `get_particle_structs` and `get_particle_boundary_buffer_structs` more robust.
Diffstat (limited to 'Python/pywarpx')
-rwxr-xr-xPython/pywarpx/_libwarpx.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 9ebbd262f..d80a1915f 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -136,6 +136,8 @@ _LP_LP_c_char = ctypes.POINTER(_LP_c_char)
# this is a function for converting a ctypes pointer to a numpy array
def _array1d_from_pointer(pointer, dtype, size):
+ if not pointer:
+ raise Exception(f'_array1d_from_pointer: pointer is a nullptr')
if sys.version_info.major >= 3:
# from where do I import these? this might only work for CPython...
#PyBuf_READ = 0x100
@@ -559,6 +561,8 @@ def get_particle_structs(species_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
arr = _array1d_from_pointer(data[i], _p_dtype, particles_per_tile[i])
particle_data.append(arr)
@@ -599,6 +603,10 @@ def get_particle_arrays(species_name, comp_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], (particles_per_tile[i],))
try:
# This fails on some versions of numpy
@@ -896,6 +904,8 @@ def get_particle_boundary_buffer_structs(species_name, boundary, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
arr = _array1d_from_pointer(data[i], _p_dtype, particles_per_tile[i])
particle_data.append(arr)
@@ -949,6 +959,10 @@ def get_particle_boundary_buffer(species_name, boundary, comp_name, level):
particle_data = []
for i in range(num_tiles.value):
+ if particles_per_tile[i] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], (particles_per_tile[i],))
try:
# This fails on some versions of numpy
@@ -989,6 +1003,10 @@ def _get_mesh_field_list(warpx_func, level, direction, include_ghosts):
for i in range(size.value):
shape = tuple([shapes[shapesize*i + d] for d in range(shapesize)])
# --- The data is stored in Fortran order, hence shape is reversed and a transpose is taken.
+ if shape[::-1] == 0:
+ continue
+ if not data[i]:
+ raise Exception(f'get_particle_arrays: data[i] for i={i} was not initialized')
arr = np.ctypeslib.as_array(data[i], shape[::-1]).T
try:
# This fails on some versions of numpy