the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 125 lines 3.4 kB view raw
1/* SCE CONFIDENTIAL 2 PlayStation(R)4 Programmer Tool Runtime Library Release 01.600.051 3 * Copyright (C) 2013 Sony Computer Entertainment Inc. 4 * All Rights Reserved. 5 */ 6 7#include <new> 8#include <cstdlib> 9#include <cstdio> 10 11void *user_new(std::size_t size) throw(std::bad_alloc); 12void *user_new(std::size_t size, const std::nothrow_t& x) throw(); 13void *user_new_array(std::size_t size) throw(std::bad_alloc); 14void *user_new_array(std::size_t size, const std::nothrow_t& x) throw(); 15void user_delete(void *ptr) throw(); 16void user_delete(void *ptr, const std::nothrow_t& x) throw(); 17void user_delete_array(void *ptr) throw(); 18void user_delete_array(void *ptr, const std::nothrow_t& x) throw(); 19 20//E Replace operator new. 21//J operator new と置き換わる 22void *user_new(std::size_t size) throw(std::bad_alloc) 23{ 24 void *ptr; 25 26 if (size == 0) 27 size = 1; 28 29 while ((ptr = (void *)std::malloc(size)) == NULL) { 30 //E Obtain new_handler 31 //J new_handler を取得する 32 std::new_handler handler = std::get_new_handler(); 33 34 //E When new_handler is a NULL pointer, bad_alloc is send. If not, new_handler is called. 35 //J new_handler が NULL ポインタの場合、bad_alloc を送出する、そうでない場合、new_handler を呼び出す 36 if (!handler) 37 { 38 assert(0);//throw std::bad_alloc(); 39 } 40 else 41 (*handler)(); 42 } 43 return ptr; 44} 45 46//E Replace operator new(std::nothrow). 47//J operator(std::nothrow) と置き換わる 48void *user_new(std::size_t size, const std::nothrow_t& x) throw() 49{ 50// void *ptr; 51// 52// (void)x; 53// 54// if (size == 0) 55// size = 1; 56// 57// while ((ptr = (void *)std::malloc(size)) == NULL) { 58// //E Obtain new_handler 59// //J new_handler を取得する 60// std::new_handler handler = std::get_new_handler(); 61// 62// //E When new_handler is a NULL pointer, NULL is returned. 63// //J new_handler が NULL ポインタの場合、NULL を返す 64// if (!handler) 65// return NULL; 66// 67// //E Call new_handler. If new_handler sends bad_alloc, NULL is returned. 68// //J new_handler を呼び出す、new_handler が bad_alloc を送出した場合、NULL を返す 69// try { 70// (*handler)(); 71// } catch (std::bad_alloc) { 72// return NULL; 73// } 74// } 75// return ptr; 76 assert(0); 77 return NULL; 78} 79 80//E Replace operator new[]. 81//J operator new[] と置き換わる 82void *user_new_array(std::size_t size) throw(std::bad_alloc) 83{ 84 return user_new(size); 85} 86 87//E Replace operator new[](std::nothrow). 88//J operator new[](std::nothrow) と置き換わる 89void *user_new_array(std::size_t size, const std::nothrow_t& x) throw() 90{ 91 return user_new(size, x); 92} 93 94//E Replace operator delete. 95//J operator delete と置き換わる 96void user_delete(void *ptr) throw() 97{ 98 //E In the case of the NULL pointer, no action will be taken. 99 //J NULL ポインタの場合、何も行わない 100 if (ptr != NULL) 101 std::free(ptr); 102} 103 104//E Replace operator delete(std::nothrow). 105//J operator delete(std::nothrow) と置き換わる 106void user_delete(void *ptr, const std::nothrow_t& x) throw() 107{ 108 (void)x; 109 110 user_delete(ptr); 111} 112 113//E Replace operator delete[]. 114//J operator delete[] と置き換わる 115void user_delete_array(void *ptr) throw() 116{ 117 user_delete(ptr); 118} 119 120//E Replace operator delete[](std::nothrow). 121//J operator delete[](std::nothrow) と置き換わる 122void user_delete_array(void *ptr, const std::nothrow_t& x) throw() 123{ 124 user_delete(ptr, x); 125}