Skip to content

Commit

Permalink
starboard/types.h: Replace kSbInt32Max with std::numeric_limits equiv…
Browse files Browse the repository at this point in the history
…alents (#4187)

As said this CL replaces kSbInt16Max with its std::numeric_limits<>
equivalent, removes kSbInt32Min and kSbUInt32Max because they're unused,
and uses the stdint.h INT32_MIN where appropriate (for kSbInvalidInt and
in a C header file).

Verified via local x64x11 build.

[1]
https://source.corp.google.com/search?q=kSb.%3FInt(32)&sq=&ss=h%2Flbshell-internal%2Fcobalt_src%2F%2B%2Frefs%2Fheads%2FCOBALT

b/366064934
  • Loading branch information
yell0wd0g authored and borongc committed Nov 27, 2024
1 parent a3e8660 commit 6b3768f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions starboard/shared/posix/storage_write_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fcntl.h>

#include <algorithm>
#include <limits>
#include <vector>

#include "starboard/common/file.h"
Expand Down Expand Up @@ -57,8 +58,8 @@ bool SbStorageWriteRecord(SbStorageRecord record,
const char* source = data;
int64_t to_write = data_size;
while (to_write > 0) {
int to_write_max =
static_cast<int>(std::min(to_write, static_cast<int64_t>(kSbInt32Max)));
int to_write_max = static_cast<int>(std::min(
to_write, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
int bytes_written = write(temp_file, source, to_write_max);
if (bytes_written < 0) {
close(temp_file);
Expand Down
5 changes: 3 additions & 2 deletions starboard/shared/starboard/file_atomic_replace_write_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <unistd.h>

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand All @@ -42,8 +43,8 @@ bool SbFileAtomicReplaceWriteFile(const char* path,
int64_t to_write = data_size;

while (to_write > 0) {
const int to_write_max =
static_cast<int>(std::min(to_write, static_cast<int64_t>(kSbInt32Max)));
const int to_write_max = static_cast<int>(std::min(
to_write, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
const int bytes_written = write(temp_file, source, to_write_max);
RecordFileWriteStat(bytes_written);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <unistd.h>

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand Down Expand Up @@ -47,8 +48,8 @@ int64_t SbStorageReadRecord(SbStorageRecord record,
char* destination = out_data;
int64_t to_read = total;
while (to_read > 0) {
int to_read_max =
static_cast<int>(std::min(to_read, static_cast<int64_t>(kSbInt32Max)));
int to_read_max = static_cast<int>(std::min(
to_read, static_cast<int64_t>(std::numeric_limits<int32_t>::max())));
int bytes_read = read(record->file, destination, to_read_max);
if (bytes_read < 0) {
return -1;
Expand Down
4 changes: 3 additions & 1 deletion starboard/shared/starboard/localized_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "starboard/shared/starboard/localized_strings.h"

#include <algorithm>
#include <limits>

#include "starboard/common/file.h"
#include "starboard/common/log.h"
Expand Down Expand Up @@ -71,7 +72,8 @@ bool ReadFile(const std::string& filename, std::string* out_result) {
char* buffer_pos = buffer;
while (bytes_to_read > 0) {
int max_bytes_to_read = static_cast<int>(
std::min(static_cast<int64_t>(kSbInt32Max), bytes_to_read));
std::min(static_cast<int64_t>(std::numeric_limits<int32_t>::max()),
bytes_to_read));
int bytes_read = file.Read(buffer_pos, max_bytes_to_read);
if (bytes_read < 0) {
SB_DLOG(ERROR) << "Read from i18n file failed.";
Expand Down
6 changes: 1 addition & 5 deletions starboard/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ typedef int64_t ssize_t;

// Simulate needed portions of limits.h for platforms that don't provide it.

#define kSbInt32Min ((int32_t)0x80000000)
static const int32_t kSbInt32Max = ((int32_t)0x7FFFFFFF);
static const uint32_t kSbUInt32Max = ((uint32_t)0xFFFFFFFF);

static const int64_t kSbInt64Min = ((int64_t)SB_INT64_C(0x8000000000000000));
static const int64_t kSbInt64Max = ((int64_t)SB_INT64_C(0x7FFFFFFFFFFFFFFF));
static const uint64_t kSbUInt64Max = ((uint64_t)SB_INT64_C(0xFFFFFFFFFFFFFFFF));

// A value that represents an int that is probably invalid.
#define kSbInvalidInt kSbInt32Min
#define kSbInvalidInt INT32_MIN

// --- Standard Include Emulation Audits ---------------------------------------

Expand Down

0 comments on commit 6b3768f

Please sign in to comment.