Skip to content

Commit

Permalink
PR #13202 from Eran: fix #13185 & #13192: move inline bool operator t…
Browse files Browse the repository at this point in the history
…o json.h
  • Loading branch information
maloel authored Jul 29, 2024
2 parents 19ffb87 + 0f309d1 commit b0d4926
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
8 changes: 1 addition & 7 deletions third-party/rsutils/include/rsutils/json-fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ class json_base

public:
inline bool exists() const;
// WARNING: this "overrides" the implicit operator<T> that the *derived* class defines that does implicit casting!
// I.e., if
// bool b = j;
// used the implicit conversion ('bool b = j.get< bool >();') before, now it will do:
// bool b = j.exists();
// In general, it is preferable to NEVER use implicit value conversions and instead stick to the .get<T>() syntax.
operator bool() const { return exists(); }
inline operator bool() const;

template< class T > inline T default_value( T const & default_value ) const;

Expand Down
13 changes: 13 additions & 0 deletions third-party/rsutils/include/rsutils/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ inline bool json_base::exists() const
return _ref().exists();
}


// WARNING: this "overrides" the implicit operator<T> that the *derived* class defines that does implicit casting!
// I.e., if
// bool b = j;
// used the implicit conversion ('bool b = j.get< bool >();') before, now it will do:
// bool b = j.exists();
// In general, it is preferable to NEVER use implicit value conversions and instead stick to the .get<T>() syntax.
inline json_base::operator bool() const
{
return exists();
}


// Get the JSON as a value, or a default if not there (throws if wrong type)
template< class T >
inline T json_base::default_value( T const & default_value ) const
Expand Down
4 changes: 2 additions & 2 deletions unit-tests/py/rspy/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def find_pyrs():
return None
from rspy import file
if platform.system() == 'Linux':
for so in file.find( build, '(^|/)pyrealsense2.*\.so$' ):
for so in file.find( build, r'(^|/)pyrealsense2.*\.so$' ):
return os.path.join( build, so )
else:
for pyd in file.find( build, '(^|/)pyrealsense2.*\.pyd$' ):
for pyd in file.find( build, r'(^|/)pyrealsense2.*\.pyd$' ):
return os.path.join( build, pyd )


Expand Down
18 changes: 9 additions & 9 deletions unit-tests/unit-test-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def add_slash_before_spaces(links):
Because spaces in links can't been read properly from cmake files.
"""
if links and type(links) is str:
return links.replace(' ', '\ ')
return links.replace( ' ', r'\ ' )
if links and type(links) is list:
# Build list comprehension of strings with backslash before spaces in case the link.
# We can get a ${var} so, when we get this we return as is
return [link.replace(' ', '\ ') if link[0] != '$' else link for link in links]
return [link.replace( ' ', r'\ ' ) if link[0] != '$' else link for link in links]
else:
raise TypeError

Expand Down Expand Up @@ -209,7 +209,7 @@ def process_cpp( dir, builddir ):
if regex:
pattern = re.compile( regex )
log.d( 'looking for C++ files in:', dir )
for f in file.find( dir, '(^|/)test-.*\.cpp$' ):
for f in file.find( dir, r'(^|/)test-.*\.cpp$' ):
testdir = os.path.splitext( f )[0] # "log/internal/test-all" <- "log/internal/test-all.cpp"
testparent = os.path.dirname(testdir) # "log/internal"
# We need the project name unique: keep the path but make it nicer:
Expand Down Expand Up @@ -257,7 +257,7 @@ def process_cpp( dir, builddir ):
static = False
custom_main = False
dependencies = 'realsense2'
for cmake_directive in file.grep( '^//#cmake:\s*', dir + '/' + f ):
for cmake_directive in file.grep( r'^//#cmake:\s*', dir + '/' + f ):
m = cmake_directive['match']
index = cmake_directive['index']
cmd, *rest = cmake_directive['line'][m.end():].split()
Expand All @@ -281,17 +281,17 @@ def process_cpp( dir, builddir ):
includes = find_includes( abs_file, includes, dependencies )
elif cmd == 'static!':
if len(rest):
log.e( f + '+' + str(index) + ': unexpected arguments past \'' + cmd + '\'' )
log.e( f"{f}+{index}: unexpected arguments past '{cmd}'" )
elif shared:
log.e( f + '+' + str(index) + ': \'' + cmd + '\' mutually exclusive with \'shared!\'' )
log.e( f"{f}+{index}: '{cmd}' mutually exclusive with 'shared!'" )
else:
log.d( 'static!' )
static = True
elif cmd == 'shared!':
if len(rest):
log.e( f + '+' + str(index) + ': unexpected arguments past \'' + cmd + '\'' )
log.e( f"{f}+{index}: unexpected arguments past '{cmd}'" )
elif static:
log.e( f + '+' + str(index) + ': \'' + cmd + '\' mutually exclusive with \'static!\'' )
log.e( f"{f}+{index}: '{cmd}' mutually exclusive with 'static!'" )
else:
log.d( 'shared!' )
shared = True
Expand All @@ -300,7 +300,7 @@ def process_cpp( dir, builddir ):
elif cmd == 'dependencies':
dependencies = ' '.join( rest )
else:
log.e( f + '+' + str(index) + ': unknown cmd \'' + cmd + '\' (should be \'add-file\', \'static!\', or \'shared!\')' )
log.e( f"{f}+{index}: unknown cmd '{cmd}' (should be 'add-file', 'static!', or 'shared!')" )

# Add any includes specified in the .cpp that we can find
includes = find_includes( dir + '/' + f, includes, dependencies )
Expand Down

0 comments on commit b0d4926

Please sign in to comment.