Move entirety of llvm namespace to wpi namespace.

During shared library loading, a different libLLVM can be pulled in, causing
llvm symbols from dependent libraries to resolve to that library instead of
this one. This has been seen in the wild with the Mesa OpenGL implementation
in JavaFX applications (see wpilibsuite/shuffleboard#361).

This is clearly a very breaking change. For some level of backwards
compatibility, a namespace alias from llvm to wpi is performed in the "llvm"
headers.  Unfortunately, forward declarations of llvm classes will still break,
but compilers seem to generate clear error messages in those cases
("namespace alias 'llvm' not allowed here, assuming 'wpi'").

This change also moves all the wpiutil headers to a single "wpi" subdirectory
from the previously split "llvm", "support", "tcpsockets", and "udpsockets".
Shim headers will be added for backwards compatibility in a later commit.
This commit is contained in:
Peter Johnson
2018-04-29 23:33:19 -07:00
parent 93859eb84f
commit f84018af5f
377 changed files with 2747 additions and 2742 deletions

View File

@@ -7,7 +7,7 @@
#include "HAL/cpp/fpga_clock.h"
#include <llvm/raw_ostream.h>
#include <wpi/raw_ostream.h>
#include "HAL/HAL.h"
@@ -20,10 +20,10 @@ fpga_clock::time_point fpga_clock::now() noexcept {
int32_t status = 0;
uint64_t currentTime = HAL_GetFPGATime(&status);
if (status != 0) {
llvm::errs()
wpi::errs()
<< "Call to HAL_GetFPGATime failed."
<< "Initialization might have failed. Time will not be correct\n";
llvm::errs().flush();
wpi::errs().flush();
return epoch();
}
return time_point(std::chrono::microseconds(currentTime));

View File

@@ -9,14 +9,14 @@
#include <algorithm>
#include <llvm/SmallVector.h>
#include <support/mutex.h>
#include <wpi/SmallVector.h>
#include <wpi/mutex.h>
namespace hal {
static llvm::SmallVector<HandleBase*, 32>* globalHandles = nullptr;
static wpi::SmallVector<HandleBase*, 32>* globalHandles = nullptr;
static wpi::mutex globalHandleMutex;
HandleBase::HandleBase() {
static llvm::SmallVector<HandleBase*, 32> gH;
static wpi::SmallVector<HandleBase*, 32> gH;
std::lock_guard<wpi::mutex> lock(globalHandleMutex);
if (!globalHandles) {
globalHandles = &gH;

View File

@@ -12,9 +12,9 @@
#include "HAL/CAN.h"
#include "HALUtil.h"
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
#include "llvm/SmallString.h"
#include "llvm/raw_ostream.h"
#include "support/jni_util.h"
#include "wpi/SmallString.h"
#include "wpi/jni_util.h"
#include "wpi/raw_ostream.h"
using namespace frc;
using namespace wpi::java;
@@ -53,8 +53,8 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxSendMessage(
if (logDEBUG <= canJNILogLevel) {
if (dataBuffer) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream str(buf);
wpi::SmallString<128> buf;
wpi::raw_svector_ostream str(buf);
for (int32_t i = 0; i < dataSize; i++) {
str.write_hex(dataBuffer[i]) << ' ';
}
@@ -102,8 +102,8 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
CANJNI_LOG(logDEBUG).write_hex(*messageIDPtr);
if (logDEBUG <= canJNILogLevel) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream str(buf);
wpi::SmallString<128> buf;
wpi::raw_svector_ostream str(buf);
for (int32_t i = 0; i < dataSize; i++) {
// Pad one-digit data with a zero
@@ -121,7 +121,7 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
CANJNI_LOG(logDEBUG) << "Status: " << status;
if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr;
return MakeJByteArray(env, llvm::StringRef{reinterpret_cast<const char*>(buffer),
return MakeJByteArray(env, wpi::StringRef{reinterpret_cast<const char*>(buffer),
static_cast<size_t>(dataSize)});
}

View File

@@ -15,7 +15,7 @@
#include "HAL/DriverStation.h"
#include "edu_wpi_first_wpilibj_hal_HAL.h"
#include "HALUtil.h"
#include "support/jni_util.h"
#include "wpi/jni_util.h"
using namespace frc;
using namespace wpi::java;

View File

@@ -21,9 +21,9 @@
#include "HAL/Errors.h"
#include "HAL/cpp/Log.h"
#include "edu_wpi_first_wpilibj_hal_HALUtil.h"
#include "llvm/SmallString.h"
#include "llvm/raw_ostream.h"
#include "support/jni_util.h"
#include "wpi/SmallString.h"
#include "wpi/jni_util.h"
#include "wpi/raw_ostream.h"
using namespace wpi::java;
@@ -64,8 +64,8 @@ namespace frc {
void ThrowAllocationException(JNIEnv *env, int32_t minRange, int32_t maxRange,
int32_t requestedValue, int32_t status) {
const char *message = HAL_GetErrorMessage(status);
llvm::SmallString<1024> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message << ", Minimum Value: "
<< minRange << ", Maximum Value: " << maxRange << ", Requested Value: "
<< requestedValue;
@@ -75,8 +75,8 @@ void ThrowAllocationException(JNIEnv *env, int32_t minRange, int32_t maxRange,
void ThrowHalHandleException(JNIEnv *env, int32_t status) {
const char *message = HAL_GetErrorMessage(status);
llvm::SmallString<1024> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message;
halHandleExCls.Throw(env, buf.c_str());
}
@@ -88,8 +88,8 @@ void ReportError(JNIEnv *env, int32_t status, bool doThrow) {
}
const char *message = HAL_GetErrorMessage(status);
if (doThrow && status < 0) {
llvm::SmallString<1024> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message;
runtimeExCls.Throw(env, buf.c_str());
} else {
@@ -111,8 +111,8 @@ void ThrowError(JNIEnv *env, int32_t status, int32_t minRange, int32_t maxRange,
ThrowHalHandleException(env, status);
}
const char *message = HAL_GetErrorMessage(status);
llvm::SmallString<1024> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message;
runtimeExCls.Throw(env, buf.c_str());
}
@@ -147,8 +147,8 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
}
case HAL_ERR_CANSessionMux_NotAllowed:
case kRIOStatusFeatureNotSupported: {
llvm::SmallString<100> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<100> buf;
wpi::raw_svector_ostream oss(buf);
oss << "MessageID = " << message_id;
canMessageNotAllowedExCls.Throw(env, buf.c_str());
break;
@@ -165,8 +165,8 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
break;
}
default: {
llvm::SmallString<100> buf;
llvm::raw_svector_ostream oss(buf);
wpi::SmallString<100> buf;
wpi::raw_svector_ostream oss(buf);
oss << "Fatal status code detected: " << status;
uncleanStatusExCls.Throw(env, buf.c_str());
break;

View File

@@ -13,7 +13,7 @@
#include "HAL/I2C.h"
#include "HALUtil.h"
#include "support/jni_util.h"
#include "wpi/jni_util.h"
using namespace frc;
using namespace wpi::java;
@@ -83,7 +83,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransactionB(
I2CJNI_LOG(logDEBUG) << "Port = " << port;
I2CJNI_LOG(logDEBUG) << "Address = " << (jint)address;
I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)sendSize;
llvm::SmallVector<uint8_t, 128> recvBuf;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(receiveSize);
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << (jint)receiveSize;
jint returnValue =
@@ -173,7 +173,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CReadB(
I2CJNI_LOG(logDEBUG) << "Port = " << port;
I2CJNI_LOG(logDEBUG) << "Address = " << address;
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << receiveSize;
llvm::SmallVector<uint8_t, 128> recvBuf;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(receiveSize);
jint returnValue = HAL_ReadI2C(static_cast<HAL_I2CPort>(port), address, recvBuf.data(), receiveSize);
env->SetByteArrayRegion(dataReceived, 0, receiveSize,

View File

@@ -10,14 +10,14 @@
#include <atomic>
#include <thread>
#include <support/mutex.h>
#include <wpi/SafeThread.h>
#include <wpi/mutex.h>
#include "HAL/cpp/Log.h"
#include "HAL/Interrupts.h"
#include "HALUtil.h"
#include "edu_wpi_first_wpilibj_hal_InterruptJNI.h"
#include "support/SafeThread.h"
using namespace frc;

View File

@@ -13,7 +13,7 @@
#include "HAL/OSSerialPort.h"
#include "HALUtil.h"
#include "support/jni_util.h"
#include "wpi/jni_util.h"
using namespace frc;
using namespace wpi::java;
@@ -244,7 +244,7 @@ Java_edu_wpi_first_wpilibj_hal_OSSerialPortJNI_serialGetBytesReceived(
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_OSSerialPortJNI_serialRead(
JNIEnv* env, jclass, jbyte port, jbyteArray dataReceived, jint size) {
SERIALJNI_LOG(logDEBUG) << "Serial Read";
llvm::SmallVector<char, 128> recvBuf;
wpi::SmallVector<char, 128> recvBuf;
recvBuf.resize(size);
int32_t status = 0;
jint retVal = HAL_ReadOSSerial(static_cast<HAL_SerialPort>(port), recvBuf.data(),

View File

@@ -13,7 +13,7 @@
#include "HAL/SPI.h"
#include "HALUtil.h"
#include "support/jni_util.h"
#include "wpi/jni_util.h"
using namespace frc;
using namespace wpi::java;
@@ -79,7 +79,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiTransactionB(
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiTransactionB";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint)port;
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
llvm::SmallVector<uint8_t, 128> recvBuf;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(size);
jint retVal =
HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
@@ -146,7 +146,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiRead(
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
jint retVal;
if (initiate) {
llvm::SmallVector<uint8_t, 128> sendBuf;
wpi::SmallVector<uint8_t, 128> sendBuf;
sendBuf.resize(size);
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(), dataReceivedPtr, size);
} else {
@@ -168,10 +168,10 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiReadB(
SPIJNI_LOG(logDEBUG) << "Initiate = " << (jboolean)initiate;
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
jint retVal;
llvm::SmallVector<uint8_t, 128> recvBuf;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(size);
if (initiate) {
llvm::SmallVector<uint8_t, 128> sendBuf;
wpi::SmallVector<uint8_t, 128> sendBuf;
sendBuf.resize(size);
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(), recvBuf.data(), size);
} else {
@@ -404,7 +404,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiReadAutoReceived
SPIJNI_LOG(logDEBUG) << "Port = " << port;
SPIJNI_LOG(logDEBUG) << "NumToRead = " << numToRead;
SPIJNI_LOG(logDEBUG) << "Timeout = " << timeout;
llvm::SmallVector<uint8_t, 128> recvBuf;
wpi::SmallVector<uint8_t, 128> recvBuf;
recvBuf.resize(numToRead);
int32_t status = 0;
jint retval = HAL_ReadSPIAutoReceivedData(static_cast<HAL_SPIPort>(port), recvBuf.data(), numToRead, timeout, &status);

View File

@@ -13,7 +13,7 @@
#include "HAL/SerialPort.h"
#include "HALUtil.h"
#include "support/jni_util.h"
#include "wpi/jni_util.h"
using namespace frc;
using namespace wpi::java;
@@ -263,7 +263,7 @@ Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialGetBytesReceived(
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialRead(
JNIEnv* env, jclass, jbyte port, jbyteArray dataReceived, jint size) {
SERIALJNI_LOG(logDEBUG) << "Serial Read";
llvm::SmallVector<char, 128> recvBuf;
wpi::SmallVector<char, 128> recvBuf;
recvBuf.resize(size);
int32_t status = 0;
jint retVal = HAL_ReadSerial(static_cast<HAL_SerialPort>(port), recvBuf.data(),