• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_BASE_PLATFORM_WRAPPERS_H_
6 #define V8_BASE_PLATFORM_WRAPPERS_H_
7 
8 #include <stddef.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "src/base/base-export.h"
14 
15 #if defined(V8_OS_STARBOARD)
16 #include "starboard/memory.h"
17 #include "starboard/string.h"
18 #endif
19 
20 namespace v8 {
21 namespace base {
22 
23 #if !defined(V8_OS_STARBOARD)
24 
25 // Common libstd implementations.
26 // inline implementations are preferred here due to performance concerns.
Malloc(size_t size)27 inline void* Malloc(size_t size) { return malloc(size); }
28 
Realloc(void * memory,size_t size)29 inline void* Realloc(void* memory, size_t size) {
30   return realloc(memory, size);
31 }
32 
Free(void * memory)33 inline void Free(void* memory) { return free(memory); }
34 
Calloc(size_t count,size_t size)35 inline void* Calloc(size_t count, size_t size) { return calloc(count, size); }
36 
Strdup(const char * source)37 inline char* Strdup(const char* source) { return strdup(source); }
38 
Fopen(const char * filename,const char * mode)39 inline FILE* Fopen(const char* filename, const char* mode) {
40   return fopen(filename, mode);
41 }
42 
Fclose(FILE * stream)43 inline int Fclose(FILE* stream) { return fclose(stream); }
44 
45 #else  // V8_OS_STARBOARD
46 
47 inline void* Malloc(size_t size) { return SbMemoryAllocate(size); }
48 
49 inline void* Realloc(void* memory, size_t size) {
50   return SbMemoryReallocate(memory, size);
51 }
52 
53 inline void Free(void* memory) { return SbMemoryDeallocate(memory); }
54 
55 inline void* Calloc(size_t count, size_t size) {
56   return SbMemoryCalloc(count, size);
57 }
58 
59 inline char* Strdup(const char* source) { return SbStringDuplicate(source); }
60 
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 }  // namespace base
68 }  // namespace v8
69 
70 #endif  // V8_BASE_PLATFORM_WRAPPERS_H_
71