@@ -66,7 +66,7 @@ function compile(solvers, mexdir, fortd, gateways, options)
6666% The following code is to circumvent a bug in MATLAB R2025a, which segfaults on Linux when the
6767% Fortran files contain internal procedures that are passed as actual arguments to other procedures.
6868% To avoid this bug, we replace gateways/*_mex.F90 with gateways/R2025a/*_mex.F90, and
69- % fortran/cobylb.f90 with gateways/R2025a/cobylb.f90, which uses module variables instead of
69+ % fortran/cobylb.f90 with gateways/R2025a/cobylb.f90, which use module variables instead of
7070% internal procedures. The price is that PRIMA becomes thread-unsafe and recursion-unsafe.
7171% See MathWorks Technical Support Case 07931486 and
7272% https://www.mathworks.com/matlabcentral/answers/2178414-bug-matlab-2025a-segfaults-on-ubuntu-when-handling-fortran-mex-files-with-internal-subroutines
@@ -80,12 +80,16 @@ function compile(solvers, mexdir, fortd, gateways, options)
8080 [' MATLAB R2025a has a bug that causes segmentation faults when handling Fortran MEX files with internal procedures.\n ' , ...
8181 ' PRIMA is adapted to circumvent this bug but it becomes thread-unsafe and recursion-unsafe.' ]);
8282 end
83- % Replace the files. N.B.: The .*f90 files have become .* files after the refactorization in setup.m.
83+ % Replace the files. N.B.: The .*90 files have become .* after the code refactoring in setup.m.
84+ replacement_dir = fullfile(gateways , ' R2025a' );
8485 for isol = 1 : length(solvers )
8586 solver = solvers{isol };
86- copyfile(fullfile(gateways , ' R2025a' , [solver , ' _mex.F' ]), fullfile(gateways , [solver , ' _mex.F' ]));
87+ copyfile(fullfile(replacement_dir , [solver , ' _mex.F' ]), fullfile(gateways , [solver , ' _mex.F' ]));
88+ if strcmp(solver , ' cobyla' )
89+ % For COBYLA, we also need to replace the Fortran source file cobylb.f.
90+ copyfile(fullfile(replacement_dir , ' cobylb.f' ), fullfile(fortd , ' cobyla' , ' cobylb.f' ));
91+ end
8792 end
88- copyfile(fullfile(gateways , ' R2025a' , ' cobylb.f' ), fullfile(fortd , ' cobyla' , ' cobylb.f' ));
8993end
9094% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9195
0 commit comments