Skip to content

Commit 4d5eb20

Browse files
knuth-bendix: fix helper to_latin1 again
1 parent 38a9843 commit 4d5eb20

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/knuth-bendix.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ namespace libsemigroups {
5454
namespace {
5555
std::string to_latin1(std::string const& u) {
5656
static py::object bytes;
57-
try {
58-
bytes = py::getattr(py::globals()["__builtins__"], "bytes");
59-
} catch (py::error_already_set& e) {
60-
bytes = py::globals()["__builtins__"]["bytes"];
57+
static bool first_call = true;
58+
if (first_call) {
59+
first_call = false;
60+
try {
61+
bytes = py::getattr(py::globals()["__builtins__"], "bytes");
62+
} catch (py::error_already_set& e) {
63+
bytes = py::globals()["__builtins__"]["bytes"];
64+
}
6165
}
6266
return PyBytes_AS_STRING(bytes(py::str(u), "latin1").ptr());
6367
}

0 commit comments

Comments
 (0)