@@ -158,18 +158,19 @@ void define_generator(py::module &m) {
158158 });
159159
160160 m.def (" _generate_filter_main" , [](const std::vector<std::string> &argv) -> void {
161- std::vector<char *> mutable_argv;
162- mutable_argv.reserve (argv.size ());
163- for (auto &s : argv) {
164- mutable_argv.push_back (const_cast <char *>(s.c_str ()));
165- }
166- const int result = Halide::Internal::generate_filter_main ((int )mutable_argv.size (), mutable_argv.data (), PyGeneratorFactoryProvider ());
167- if (result != 0 ) {
168- // Some paths in generate_filter_main() will fail with user_error or similar (which throws an exception
169- // due to how libHalide is built for Python), but some paths just return an error code. For consistency,
170- // handle both by throwing a C++ exception, which PyBind11 turns into a Python exception.
171- throw std::runtime_error (" Generator failed: " + std::to_string (result));
172- } }, py::arg (" argv" ));
161+ std::vector<char *> mutable_argv;
162+ mutable_argv.reserve (argv.size () + 1 );
163+ for (auto &s : argv) {
164+ mutable_argv.push_back (const_cast <char *>(s.c_str ()));
165+ }
166+ mutable_argv.push_back (nullptr );
167+ const int result = Halide::Internal::generate_filter_main ((int )mutable_argv.size () - 1 , mutable_argv.data (), PyGeneratorFactoryProvider ());
168+ if (result != 0 ) {
169+ // Some paths in generate_filter_main() will fail with user_error or similar (which throws an exception
170+ // due to how libHalide is built for Python), but some paths just return an error code. For consistency,
171+ // handle both by throwing a C++ exception, which PyBind11 turns into a Python exception.
172+ throw std::runtime_error (" Generator failed: " + std::to_string (result));
173+ } }, py::arg (" argv" ));
173174
174175 m.def (" _unique_name" , []() -> std::string {
175176 return ::Halide::Internal::unique_name (' p' );
0 commit comments