Improvements to SWIG typemaps for Python interface#3190
Merged
oskooi merged 8 commits intoNanoComp:masterfrom Apr 4, 2026
Merged
Improvements to SWIG typemaps for Python interface#3190oskooi merged 8 commits intoNanoComp:masterfrom
oskooi merged 8 commits intoNanoComp:masterfrom
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3190 +/- ##
==========================================
+ Coverage 73.81% 73.87% +0.05%
==========================================
Files 18 18
Lines 5423 5458 +35
==========================================
+ Hits 4003 4032 +29
- Misses 1420 1426 +6 🚀 New features to boost your workflow:
|
stevengj
reviewed
Apr 3, 2026
stevengj
reviewed
Apr 3, 2026
stevengj
reviewed
Apr 3, 2026
stevengj
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Various improvements to the SWIG typemaps for the Python interface, organized by priority.
Critical — Crash/Segfault Bugs
1. Missing NULL checks in callback wrappers (
meep.i)py_callback_wrap(line 142),py_amp_func_wrap(line 152), andcustom_py_src_time::dipole(meep-python.hpp:32) do not check the return value ofPyObject_CallFunctionObjArgs. If the Python callback raises an exception, these dereference NULL →segfault. Same issue inmpb.icallback wrappers.2. Use-after-free in
_get_dft_array(meep.i:456)The
rank == 0zero-data path passes a stack-allocatedd[1]toPyArray_SimpleNewFromData, which creates a NumPy array pointing to stack memory that goes out of scope. The singleton path also leaksdft_arr.High Priority — Correctness
3.
meep::abort()instead of Python exceptions (typemap_utils.cpp)Many conversion functions (e.g.,
pyabsorber_to_absorber,pymaterial_grid_to_material_grid,py_list_to_gobj_list) callabort_with_stack_trace()on invalid input. This kills the process instead of raising a catchable Python exception. These should setPyErr_SetStringand return an error code.4.
PyFunction_CheckvsPyCallable_Check(meep.i:1408)The
kpoint_functypemap rejects lambdas, bound methods,functools.portal, and any callable that isn't a plain function. Should usePyCallable_Check.Medium Priority — Maintenance & Compatibility
5. Dupilcate typemaps
xtics/ytics/zticstypemaps appear twice (lines 1001-1018 and 1083-1105), first block is dead code.freeargfor amplitude function appears twice (lines 748 and 1069).double*array input typemaps repeat the sameis_array+array_datapattern ~8 times - could use%apply.Low Priority — Cleanup
6. Duplicate
%ignoredirectives (meep.i:1525-1529)is_variable,is_file,is_mediumeach ignored twice.