Use absolute namespace names in generator to avoid collisions
PiperOrigin-RevId: 256349023
Change-Id: Ic6e178a158fd9af0343c747b0525e703aad7ef99
diff --git a/sandboxed_api/tools/generator2/code.py b/sandboxed_api/tools/generator2/code.py
index 2724c10..9d539ce 100644
--- a/sandboxed_api/tools/generator2/code.py
+++ b/sandboxed_api/tools/generator2/code.py
@@ -457,8 +457,8 @@
"""Class representing function return type.
Attributes:
- return_type: sapi::StatusOr<T> where T is original return type, or
- sapi::Status for functions returning void
+ return_type: ::sapi::StatusOr<T> where T is original return type, or
+ ::sapi::Status for functions returning void
"""
def __init__(self, function, arg_type):
@@ -470,8 +470,8 @@
"""Returns function return type prepared from the type."""
# TODO(szwl): const ptrs do not play well with SAPI C++ API...
spelling = self._clang_type.spelling.replace('const', '')
- return_type = 'sapi::StatusOr<{}>'.format(spelling)
- return_type = 'sapi::Status' if self.is_void() else return_type
+ return_type = '::sapi::StatusOr<{}>'.format(spelling)
+ return_type = '::sapi::Status' if self.is_void() else return_type
return return_type
@@ -832,7 +832,7 @@
result.append(' SAPI_RETURN_IF_ERROR(sandbox_->Call("{}", &ret{}));'
''.format(f.name, ', '.join(call_arguments)))
- return_status = 'return sapi::OkStatus();'
+ return_status = 'return ::sapi::OkStatus();'
if f.result and not f.result.is_void():
if f.result and f.result.is_enum():
return_status = ('return static_cast<{}>'
diff --git a/sandboxed_api/tools/generator2/code_test_util.py b/sandboxed_api/tools/generator2/code_test_util.py
index a96bc30..3315cb8 100644
--- a/sandboxed_api/tools/generator2/code_test_util.py
+++ b/sandboxed_api/tools/generator2/code_test_util.py
@@ -36,7 +36,7 @@
// int function_a(int, int)
- sapi::StatusOr<int> function_a(int x, int y) {
+ ::sapi::StatusOr<int> function_a(int x, int y) {
::sapi::v::Int ret;
::sapi::v::Int x_((x));
::sapi::v::Int y_((y));
@@ -46,7 +46,7 @@
}
// int types_1(bool, unsigned char, char, unsigned short, short)
- sapi::StatusOr<int> types_1(bool a0, unsigned char a1, char a2, unsigned short a3, short a4) {
+ ::sapi::StatusOr<int> types_1(bool a0, unsigned char a1, char a2, unsigned short a3, short a4) {
::sapi::v::Int ret;
::sapi::v::Bool a0_((a0));
::sapi::v::UChar a1_((a1));
@@ -59,7 +59,7 @@
}
// int types_2(int, unsigned int, long, unsigned long)
- sapi::StatusOr<int> types_2(int a0, unsigned int a1, long a2, unsigned long a3) {
+ ::sapi::StatusOr<int> types_2(int a0, unsigned int a1, long a2, unsigned long a3) {
::sapi::v::Int ret;
::sapi::v::Int a0_((a0));
::sapi::v::UInt a1_((a1));
@@ -71,7 +71,7 @@
}
// int types_3(long long, unsigned long long, float, double)
- sapi::StatusOr<int> types_3(long long a0, unsigned long long a1, float a2, double a3) {
+ ::sapi::StatusOr<int> types_3(long long a0, unsigned long long a1, float a2, double a3) {
::sapi::v::Int ret;
::sapi::v::LLong a0_((a0));
::sapi::v::ULLong a1_((a1));
@@ -83,7 +83,7 @@
}
// int types_4(signed char, short, int, long)
- sapi::StatusOr<int> types_4(signed char a0, short a1, int a2, long a3) {
+ ::sapi::StatusOr<int> types_4(signed char a0, short a1, int a2, long a3) {
::sapi::v::Int ret;
::sapi::v::SChar a0_((a0));
::sapi::v::Short a1_((a1));
@@ -95,7 +95,7 @@
}
// int types_5(long long, long double)
- sapi::StatusOr<int> types_5(long long a0, long double a1) {
+ ::sapi::StatusOr<int> types_5(long long a0, long double a1) {
::sapi::v::Int ret;
::sapi::v::LLong a0_((a0));
::sapi::v::Reg<long double> a1_((a1));
@@ -105,11 +105,11 @@
}
// void types_6(char *)
- sapi::Status types_6(::sapi::v::Ptr* a0) {
+ ::sapi::Status types_6(::sapi::v::Ptr* a0) {
::sapi::v::Void ret;
SAPI_RETURN_IF_ERROR(sandbox_->Call("types_6", &ret, a0));
- return sapi::OkStatus();
+ return ::sapi::OkStatus();
}
@@ -146,7 +146,7 @@
// uint function(uintp)
- sapi::StatusOr<uint> function(::sapi::v::Ptr* a) {
+ ::sapi::StatusOr<uint> function(::sapi::v::Ptr* a) {
::sapi::v::UInt ret;
SAPI_RETURN_IF_ERROR(sandbox_->Call("function", &ret, a));
@@ -189,7 +189,7 @@
// ProcessStatus ProcessDatapoint(ProcessStatus)
- sapi::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
+ ::sapi::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
::sapi::v::IntBase<ProcessStatus> ret;
::sapi::v::IntBase<ProcessStatus> status_((status));