wrappers.h 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASE_PLATFORM_WRAPPERS_H_
#define V8_BASE_PLATFORM_WRAPPERS_H_

#include <stddef.h>
#include <stdio.h>
10 11 12 13 14 15 16
#include <stdlib.h>
#include <string.h>

#include "src/base/base-export.h"

#if defined(V8_OS_STARBOARD)
#include "starboard/memory.h"
17
#include "starboard/string.h"
18
#endif
19 20 21 22

namespace v8 {
namespace base {

23 24 25 26 27 28 29 30 31 32 33 34 35 36
#if !defined(V8_OS_STARBOARD)

// Common libstd implementations.
// inline implementations are preferred here due to performance concerns.
inline void* Malloc(size_t size) { return malloc(size); }

inline void* Realloc(void* memory, size_t size) {
  return realloc(memory, size);
}

inline void Free(void* memory) { return free(memory); }

inline void* Calloc(size_t count, size_t size) { return calloc(count, size); }

37 38
inline char* Strdup(const char* source) { return strdup(source); }

39 40 41 42 43 44 45 46
inline FILE* Fopen(const char* filename, const char* mode) {
  return fopen(filename, mode);
}

inline int Fclose(FILE* stream) { return fclose(stream); }

#else  // V8_OS_STARBOARD

47
inline void* Malloc(size_t size) { return SbMemoryAllocate(size); }
48 49 50 51

inline void* Realloc(void* memory, size_t size) {
  return SbMemoryReallocate(memory, size);
}
52

53
inline void Free(void* memory) { return SbMemoryDeallocate(memory); }
54

55 56 57
inline void* Calloc(size_t count, size_t size) {
  return SbMemoryCalloc(count, size);
}
58

59 60
inline char* Strdup(const char* source) { return SbStringDuplicate(source); }

61
inline FILE* Fopen(const char* filename, const char* mode) { return NULL; }
62

63
inline int Fclose(FILE* stream) { return -1; }
64

65
#endif  // V8_OS_STARBOARD
66 67 68 69 70

}  // namespace base
}  // namespace v8

#endif  // V8_BASE_PLATFORM_WRAPPERS_H_