mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Update LLVM to latest upstream. (#1080)
Also change header guards to WPI header guards. Remove StringRef::c_str() customization, replacing the handful of uses with Twine or SmallString. TCPStream: Include errno.h and make Windows includes lowercase for consistency. Upstream LLVM version: eb4186cca7924fb1706357545311a2fa3de40c59
This commit is contained in:
43
wpiutil/src/main/native/cpp/memory.cpp
Normal file
43
wpiutil/src/main/native/cpp/memory.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "wpi/memory.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include "wpi/raw_ostream.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
void* CheckedCalloc(size_t num, size_t size) {
|
||||
void* p = std::calloc(num, size);
|
||||
if (!p) {
|
||||
errs() << "FATAL: failed to allocate " << (num * size) << " bytes\n";
|
||||
std::terminate();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void* CheckedMalloc(size_t size) {
|
||||
void* p = std::malloc(size == 0 ? 1 : size);
|
||||
if (!p) {
|
||||
errs() << "FATAL: failed to allocate " << size << " bytes\n";
|
||||
std::terminate();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void* CheckedRealloc(void* ptr, size_t size) {
|
||||
void* p = std::realloc(ptr, size == 0 ? 1 : size);
|
||||
if (!p) {
|
||||
errs() << "FATAL: failed to allocate " << size << " bytes\n";
|
||||
std::terminate();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user