Skip to content

Commit 86dbcb1

Browse files
committed
load-path: Move condition out of for-loop (bug #66477).
* libinterp/corefcn/load-path.cc (load_path::set): Move current directory to front of load path earlier. Move one of the conditions out of the for-loop that runs any PKG_ADD scripts.
1 parent 5e039bf commit 86dbcb1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

libinterp/corefcn/load-path.cc

+18-15
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,27 @@ load_path::set (const std::string& p, bool warn, bool is_init)
343343
for (const auto& elt : elts)
344344
append (elt, warn);
345345

346+
// Always prepend current directory.
347+
prepend (".", warn);
348+
346349
// Restore add hook and execute for all newly added directories.
347350
frame.run_first ();
348351

349-
// FIXME: Shouldn't the test for add_hook be outside the for loop?
350-
// Why not use const here? Does add_hook change dir_info_list?
351-
// FIXME: We should be able to assume that the current directory is always
352-
// the first element in the list. When we assume C++20 or later,
353-
// consider replacing the range-based loop with:
354-
// for (auto& di : m_dir_info_list | std::views::drop (1))
355-
// Then, the string comparison inside the loop could be dropped.
356-
for (auto& di : m_dir_info_list)
352+
if (m_add_hook)
357353
{
358-
// execute PKG_ADD script (but not in the current directory)
359-
if (m_add_hook && di.dir_name.compare ("."))
360-
m_add_hook (di.dir_name);
354+
// FIXME: Why not use const here? Does add_hook change dir_info_list?
355+
// FIXME: We should be able to assume that the current directory is
356+
// always the first element in the list. When we assume C++20 or
357+
// later, consider replacing the range-based loop with:
358+
// for (auto& di : m_dir_info_list | std::views::drop (1))
359+
// Then, the string comparison inside the loop could be dropped.
360+
for (auto& di : m_dir_info_list)
361+
{
362+
// execute PKG_ADD script (but not in the current directory)
363+
if (di.dir_name.compare ("."))
364+
m_add_hook (di.dir_name);
365+
}
361366
}
362-
363-
// Always prepend current directory.
364-
prepend (".", warn);
365367
}
366368

367369
void
@@ -1136,7 +1138,8 @@ load_path::add (const std::string& dir_arg, bool at_end, bool warn)
11361138
warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
11371139
}
11381140

1139-
// FIXME: is there a better way to do this?
1141+
// FIXME: Is there a better way to keep "." at the front of the various lists
1142+
// that are kept with information about the load path?
11401143

11411144
i = find_dir_info (".");
11421145

0 commit comments

Comments
 (0)