Fix C89 compile error for cpu detect. Make mips detection assume DSP if cpuinfo file can not be opened, so that if run in a sandbox, DSP is assumed true, like the arm version.

BUG=303
TESTED=cl /c /TC /Iinclude source/cpu_id.cc
R=tpsiaki@google.com

Review URL: https://webrtc-codereview.appspot.com/10549004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@986 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
fbarchard@google.com 2014-03-24 18:24:22 +00:00
parent efc5d9b930
commit 91dc3eddeb
3 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,6 @@
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 985 Version: 986
License: BSD License: BSD
License File: LICENSE License File: LICENSE

View File

@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 985 #define LIBYUV_VERSION 986
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT

View File

@ -120,13 +120,13 @@ void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) {
// For Arm, but public to allow testing on any CPU // For Arm, but public to allow testing on any CPU
LIBYUV_API SAFEBUFFERS LIBYUV_API SAFEBUFFERS
int ArmCpuCaps(const char* cpuinfo_name) { int ArmCpuCaps(const char* cpuinfo_name) {
char cpuinfo_line[512];
FILE* f = fopen(cpuinfo_name, "r"); FILE* f = fopen(cpuinfo_name, "r");
if (!f) { if (!f) {
// Assume Neon if /proc/cpuinfo is unavailable. // Assume Neon if /proc/cpuinfo is unavailable.
// This will occur for Chrome sandbox for Pepper or Render process. // This will occur for Chrome sandbox for Pepper or Render process.
return kCpuHasNEON; return kCpuHasNEON;
} }
char cpuinfo_line[512];
while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) { while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) {
if (memcmp(cpuinfo_line, "Features", 8) == 0) { if (memcmp(cpuinfo_line, "Features", 8) == 0) {
char* p = strstr(cpuinfo_line, " neon"); char* p = strstr(cpuinfo_line, " neon");
@ -142,19 +142,21 @@ int ArmCpuCaps(const char* cpuinfo_name) {
#if defined(__mips__) && defined(__linux__) #if defined(__mips__) && defined(__linux__)
static int MipsCpuCaps(const char* search_string) { static int MipsCpuCaps(const char* search_string) {
char cpuinfo_line[512];
const char* file_name = "/proc/cpuinfo"; const char* file_name = "/proc/cpuinfo";
char cpuinfo_line[256]; FILE* f = fopen(file_name, "r");
FILE* f = NULL; if (!f) {
if ((f = fopen(file_name, "r")) != NULL) { // Assume DSP if /proc/cpuinfo is unavailable.
while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f) != NULL) { // This will occur for Chrome sandbox for Pepper or Render process.
if (strstr(cpuinfo_line, search_string) != NULL) { return kCpuHasMIPS_DSP;
fclose(f);
return kCpuHasMIPS_DSP;
}
}
fclose(f);
} }
/* Did not find string in the proc file, or not Linux ELF. */ while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f) != NULL) {
if (strstr(cpuinfo_line, search_string) != NULL) {
fclose(f);
return kCpuHasMIPS_DSP;
}
}
fclose(f);
return 0; return 0;
} }
#endif #endif