Skip to content

Commit

Permalink
Use shared ForkClientContext for generated sandboxees by default
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 643247505
Change-Id: I079e43394bc7a9c86159f4512138440966a00b50
  • Loading branch information
happyCoder92 authored and copybara-github committed Jun 14, 2024
1 parent bc350a9 commit 9d92acb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion sandboxed_api/tools/clang_generator/emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ constexpr absl::string_view kEmbedClassTemplate = R"(
// Sandbox with embedded sandboxee and default policy
class %1$s : public ::sapi::Sandbox {
public:
%1$s() : ::sapi::Sandbox(%2$s_embed_create()) {}
%1$s()
: ::sapi::Sandbox([]() {
static auto* fork_client_context =
new ::sapi::ForkClientContext(%2$s_embed_create());
return fork_client_context;
}()) {}
};
)";
Expand Down
14 changes: 10 additions & 4 deletions sandboxed_api/tools/python_generator/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,16 @@ class Generator(object):
GUARD_START = ('#ifndef {0}\n' '#define {0}')
GUARD_END = '#endif // {}'
EMBED_INCLUDE = '#include "{}"'
EMBED_CLASS = ('class {0}Sandbox : public ::sapi::Sandbox {{\n'
' public:\n'
' {0}Sandbox() : ::sapi::Sandbox({1}_embed_create()) {{}}\n'
'}};')
EMBED_CLASS = '''
class {0}Sandbox : public ::sapi::Sandbox {{
public:
{0}Sandbox()
: ::sapi::Sandbox([]() {{
static auto* fork_client_context =
new ::sapi::ForkClientContext({1}_embed_create());
return fork_client_context;
}}()) {{}}
}};'''

def __init__(self, translation_units):
# type: (List[cindex.TranslationUnit]) -> None
Expand Down

0 comments on commit 9d92acb

Please sign in to comment.