fix android compilation (#372)

* fix android compilation

* checking __GLIBCXX__ and __GLIBCPP__ macro in addition to __ANDROID__

* using vsnprintf instead of std::vsnprintf to compile on Android

* removed __GLIBCPP__ check on Android

* StringPrintF instead of std::to_string for Android
This commit is contained in:
Dmitry Trifonov 2017-04-18 08:48:07 -07:00 committed by Eric
parent 46afd8e693
commit 09b93ccc6a
3 changed files with 8 additions and 7 deletions

View File

@ -31,6 +31,7 @@
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <thread>
#include "check.h"
@ -163,8 +164,8 @@ bool BenchmarkFamilies::FindBenchmarks(
StringPrintF("%s:", family->arg_names_[arg_i].c_str());
}
}
instance.name += std::to_string(arg);
instance.name += StringPrintF("%d", arg);
++arg_i;
}

View File

@ -89,7 +89,7 @@ std::string FormatString(const char* msg, va_list args) {
std::size_t size = 256;
char local_buff[256];
auto ret = std::vsnprintf(local_buff, size, msg, args_cp);
auto ret = vsnprintf(local_buff, size, msg, args_cp);
va_end(args_cp);
@ -104,7 +104,7 @@ std::string FormatString(const char* msg, va_list args) {
// we did not provide a long enough buffer on our first attempt.
size = (size_t)ret + 1; // + 1 for the null byte
std::unique_ptr<char[]> buff(new char[size]);
ret = std::vsnprintf(buff.get(), size, msg, args);
ret = vsnprintf(buff.get(), size, msg, args);
CHECK(ret > 0 && ((size_t)ret) < size);
return buff.get();
}

View File

@ -114,14 +114,14 @@ void TestRegistrationAtRuntime() {
#endif
#ifndef BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK
{
int x = 42;
const char* x = "42";
auto capturing_lam = [=](benchmark::State& st) {
while (st.KeepRunning()) {
}
st.SetLabel(std::to_string(x));
st.SetLabel(x);
};
benchmark::RegisterBenchmark("lambda_benchmark", capturing_lam);
AddCases({{"lambda_benchmark", "42"}});
AddCases({{"lambda_benchmark", x}});
}
#endif
}