Skip to content

Commit c630f77

Browse files
committed
make codes in /base comply with Google style except for namespace kaldi
1 parent cb6635d commit c630f77

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

src/base/io-funcs-test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ void UnitTestIo(bool binary) {
128128
} // end namespace kaldi.
129129

130130
int main() {
131+
using namespace kaldi;
131132
for (size_t i = 0; i < 10; i++) {
132-
kaldi::UnitTestIo(false);
133-
kaldi::UnitTestIo(true);
133+
UnitTestIo(false);
134+
UnitTestIo(true);
134135
}
135136
KALDI_ASSERT(1); // just to check that KALDI_ASSERT does not fail for 1.
136137
return 0;

src/base/kaldi-error.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const char *GetShortFileName(const char *filename) {
6161

6262
#if defined(HAVE_CXXABI_H) && defined(HAVE_EXECINFO_H)
6363
// The function name looks like a macro: it's a macro if we don't have ccxxabi.h
64-
inline void KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(std::string &ans,
65-
const char *to_append) {
64+
inline void KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(const char *to_append,
65+
std::string *ans) {
6666
// at input the string "to_append" looks like:
6767
// ./kaldi-error-test(_ZN5kaldi13UnitTestErrorEv+0xb) [0x804965d]
6868
// We want to extract the name e.g. '_ZN5kaldi13UnitTestErrorEv",
@@ -72,7 +72,7 @@ inline void KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(std::string &ans,
7272
const char *plus = (paren ? strchr(paren, '+') : NULL);
7373
if (!plus) { // did not find the '(' or did not find the '+'
7474
// This is a soft failure in case we did not get what we expected.
75-
ans += to_append;
75+
ans->append(to_append);
7676
return;
7777
}
7878
std::string stripped(paren+1, plus-(paren+1)); // the bit between ( and +.
@@ -83,14 +83,14 @@ inline void KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(std::string &ans,
8383
// to demangle, so we don't check it.
8484

8585
if (demangled_name != NULL) {
86-
ans += demangled_name;
86+
ans->append(demangled_name);
8787
free(demangled_name);
8888
} else {
89-
ans += to_append; // add the original string.
89+
ans->append(to_append); // add the original string.
9090
}
9191
}
9292
#else // defined(HAVE_CXXABI_H) && defined(HAVE_EXECINFO_H)
93-
#define KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(ans, to_append) ans += to_append
93+
#define KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(to_append, ans) ans += to_append
9494
#endif // defined(HAVE_CXXABI_H) && defined(HAVE_EXECINFO_H)
9595

9696
#ifdef HAVE_EXECINFO_H
@@ -103,17 +103,17 @@ std::string KaldiGetStackTrace() {
103103
char **strings = backtrace_symbols(array, size);
104104
if (size <= KALDI_MAX_TRACE_PRINT) {
105105
for (size_t i = 0; i < size; i++) {
106-
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(ans, strings[i]);
106+
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(strings[i], &ans);
107107
ans += "\n";
108108
}
109109
} else { // print out first+last (e.g.) 5.
110110
for (size_t i = 0; i < KALDI_MAX_TRACE_PRINT/2; i++) {
111-
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(ans, strings[i]);
111+
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(strings[i], &ans);
112112
ans += "\n";
113113
}
114114
ans += ".\n.\n.\n";
115115
for (size_t i = size - KALDI_MAX_TRACE_PRINT/2; i < size; i++) {
116-
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(ans, strings[i]);
116+
KALDI_APPEND_POSSIBLY_DEMANGLED_STRING(strings[i], &ans);
117117
ans += "\n";
118118
}
119119
if (size == KALDI_MAX_TRACE_SIZE)

src/base/kaldi-math-test.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,18 @@ void UnitTestLogSpeed() {
305305
} // end namespace kaldi.
306306

307307
int main() {
308-
kaldi::UnitTestApproxEqual();
309-
kaldi::UnitTestGcdLcm();
310-
kaldi::UnitTestFactorize();
311-
kaldi::UnitTestDefines();
312-
kaldi::UnitTestLogAddSub();
313-
kaldi::UnitTestRand();
314-
kaldi::UnitTestAssertFunc();
315-
kaldi::UnitTestRoundUpToNearestPowerOfTwo();
316-
kaldi::UnitTestExpSpeed<float>();
317-
kaldi::UnitTestExpSpeed<double>();
318-
kaldi::UnitTestLogSpeed<float>();
319-
kaldi::UnitTestLogSpeed<double>();
308+
using namespace kaldi;
309+
UnitTestApproxEqual();
310+
UnitTestGcdLcm();
311+
UnitTestFactorize();
312+
UnitTestDefines();
313+
UnitTestLogAddSub();
314+
UnitTestRand();
315+
UnitTestAssertFunc();
316+
UnitTestRoundUpToNearestPowerOfTwo();
317+
UnitTestExpSpeed<float>();
318+
UnitTestExpSpeed<double>();
319+
UnitTestLogSpeed<float>();
320+
UnitTestLogSpeed<double>();
320321
}
321322

src/base/kaldi-utils.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace kaldi {
3333
std::string CharToString(const char &c) {
3434
char buf[20];
3535
if (std::isprint(c))
36-
sprintf(buf, "\'%c\'", c);
36+
snprintf(buf, sizeof(buf), "\'%c\'", c);
3737
else
38-
sprintf(buf, "[character %d]", static_cast<int>(c));
38+
snprintf(buf, sizeof(buf), "[character %d]", static_cast<int>(c));
3939
return (std::string) buf;
4040
}
4141

src/doc/cpplint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,8 +2567,8 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, include_state,
25672567
error(filename, linenum, 'runtime/memset', 4,
25682568
'Did you mean "memset(%s, 0, %s)"?'
25692569
% (match.group(1), match.group(2)))
2570-
2571-
if Search(r'\busing namespace\b', line):
2570+
match = Search(r'\busing namespace kaldi\b',line)
2571+
if not match and Search(r'\busing namespace\b', line):
25722572
error(filename, linenum, 'build/namespaces', 5,
25732573
'Do not use namespace using-directives. '
25742574
'Use using-declarations instead.')

0 commit comments

Comments
 (0)