mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Replaced C-style casts found by GCC in HAL, wpilibc, and JNI (#211)
This commit is contained in:
committed by
Peter Johnson
parent
2ec6132fcb
commit
93b486b6ba
@@ -71,7 +71,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
m_structures[index] = std::make_shared<TStruct>();
|
||||
return (THandle)hal::createHandle(index, enumValue);
|
||||
return static_cast<THandle>(hal::createHandle(index, enumValue));
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size>
|
||||
|
||||
@@ -51,7 +51,7 @@ static inline int16_t getHandleIndex(HAL_Handle handle) {
|
||||
}
|
||||
static inline HAL_HandleEnum getHandleType(HAL_Handle handle) {
|
||||
// mask first 8 bits and cast to enum
|
||||
return (HAL_HandleEnum)((handle >> 24) & 0xff);
|
||||
return static_cast<HAL_HandleEnum>((handle >> 24) & 0xff);
|
||||
}
|
||||
static inline bool isHandleType(HAL_Handle handle, HAL_HandleEnum handleType) {
|
||||
return handleType == getHandleType(handle);
|
||||
|
||||
@@ -75,7 +75,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
m_structures[index] = std::make_shared<TStruct>();
|
||||
return (THandle)hal::createHandle(index, enumValue);
|
||||
return static_cast<THandle>(hal::createHandle(index, enumValue));
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
|
||||
@@ -73,7 +73,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
// and allocate it.
|
||||
std::lock_guard<priority_mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i] = toSet;
|
||||
return (THandle)createHandle(i, enumValue);
|
||||
return static_cast<THandle>(createHandle(i, enumValue));
|
||||
}
|
||||
}
|
||||
return HAL_kInvalidHandle;
|
||||
|
||||
@@ -69,7 +69,7 @@ THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
|
||||
// and allocate it.
|
||||
std::lock_guard<priority_mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i] = std::make_shared<TStruct>();
|
||||
return (THandle)createHandle(i, enumValue);
|
||||
return static_cast<THandle>(createHandle(i, enumValue));
|
||||
}
|
||||
}
|
||||
return HAL_kInvalidHandle;
|
||||
|
||||
@@ -57,13 +57,13 @@ THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
m_structures[i] = structure;
|
||||
return (THandle)createHandle(i, enumValue);
|
||||
return static_cast<THandle>(createHandle(i, enumValue));
|
||||
}
|
||||
}
|
||||
if (i >= INT16_MAX) return HAL_kInvalidHandle;
|
||||
|
||||
m_structures.push_back(structure);
|
||||
return (THandle)createHandle(static_cast<int16_t>(i), enumValue);
|
||||
return static_cast<THandle>(createHandle(static_cast<int16_t>(i), enumValue));
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
|
||||
@@ -45,7 +45,8 @@ AnalogTriggerOutput::~AnalogTriggerOutput() {
|
||||
bool AnalogTriggerOutput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerOutput(
|
||||
m_trigger.m_trigger, (HAL_AnalogTriggerType)m_outputType, &status);
|
||||
m_trigger.m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
&status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ void CameraServer::Serve() {
|
||||
address.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
address.sin_port = htons(kPort);
|
||||
|
||||
if (bind(sock, (struct sockaddr*)&address, sizeof(address)) == -1)
|
||||
if (bind(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
wpi_setErrnoError();
|
||||
|
||||
if (listen(sock, 10) == -1) wpi_setErrnoError();
|
||||
@@ -183,8 +183,8 @@ void CameraServer::Serve() {
|
||||
while (true) {
|
||||
socklen_t clientAddressLen = sizeof(clientAddress);
|
||||
|
||||
int conn =
|
||||
accept(sock, (struct sockaddr*)&clientAddress, &clientAddressLen);
|
||||
int conn = accept(sock, reinterpret_cast<sockaddr*>(&clientAddress),
|
||||
&clientAddressLen);
|
||||
if (conn == -1) {
|
||||
wpi_setErrnoError();
|
||||
continue;
|
||||
|
||||
@@ -30,9 +30,10 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(m_interrupt, GetPortHandleForRouting(),
|
||||
(HAL_AnalogTriggerType)GetAnalogTriggerTypeForRouting(),
|
||||
&status);
|
||||
HAL_RequestInterrupts(
|
||||
m_interrupt, GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
SetUpSourceEdge(true, false);
|
||||
HAL_AttachInterruptHandler(m_interrupt, handler, param, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
@@ -53,9 +54,10 @@ void InterruptableSensorBase::RequestInterrupts() {
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_RequestInterrupts(m_interrupt, GetPortHandleForRouting(),
|
||||
(HAL_AnalogTriggerType)GetAnalogTriggerTypeForRouting(),
|
||||
&status);
|
||||
HAL_RequestInterrupts(
|
||||
m_interrupt, GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
SetUpSourceEdge(true, false);
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ std::thread::native_handle_type Task::native_handle() {
|
||||
* @return true on success.
|
||||
*/
|
||||
bool Task::Verify() {
|
||||
TASK id = (TASK)m_thread.native_handle();
|
||||
return HAL_VerifyTaskID(id) == OK;
|
||||
auto id = m_thread.native_handle();
|
||||
return HAL_VerifyTaskID(&id) == OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,8 @@ Java_edu_wpi_first_wpilibj_hal_DigitalGlitchFilterJNI_setFilterSelect(
|
||||
JNIEnv* env, jclass, jint id, jint filter_index) {
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_SetFilterSelect((HAL_DigitalHandle)id, filter_index, &status);
|
||||
HAL_SetFilterSelect(static_cast<HAL_DigitalHandle>(id), filter_index,
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
@@ -33,7 +34,8 @@ Java_edu_wpi_first_wpilibj_hal_DigitalGlitchFilterJNI_getFilterSelect(
|
||||
JNIEnv* env, jclass, jint id) {
|
||||
int32_t status = 0;
|
||||
|
||||
jint result = HAL_GetFilterSelect((HAL_DigitalHandle)id, &status);
|
||||
jint result =
|
||||
HAL_GetFilterSelect(static_cast<HAL_DigitalHandle>(id), &status);
|
||||
CheckStatus(env, status);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ static void GetStackTrace(JNIEnv *env, std::string &res, std::string &func) {
|
||||
|
||||
// call getStackTrace
|
||||
jobjectArray stackTrace =
|
||||
(jobjectArray)env->CallObjectMethod(throwable, getStackTraceId);
|
||||
static_cast<jobjectArray>(env->CallObjectMethod(throwable,
|
||||
getStackTraceId));
|
||||
|
||||
if (!stackTrace) return;
|
||||
|
||||
@@ -87,7 +88,8 @@ static void GetStackTrace(JNIEnv *env, std::string &res, std::string &func) {
|
||||
|
||||
// call to string on the object
|
||||
jstring stackElementString =
|
||||
(jstring)env->CallObjectMethod(curStackTraceElement, toStringId);
|
||||
static_cast<jstring>(env->CallObjectMethod(curStackTraceElement,
|
||||
toStringId));
|
||||
|
||||
if (!stackElementString) {
|
||||
env->DeleteLocalRef(stackTrace);
|
||||
@@ -236,8 +238,10 @@ void ThrowBoundaryException(JNIEnv *env, double value, double lower,
|
||||
env->GetMethodID(boundaryExCls, "<init>", "(Ljava/lang/String;)V");
|
||||
|
||||
jobject msg =
|
||||
env->CallStaticObjectMethod(boundaryExCls, getMessage, (jdouble)value,
|
||||
(jdouble)lower, (jdouble)upper);
|
||||
env->CallStaticObjectMethod(boundaryExCls, getMessage,
|
||||
static_cast<jdouble>(value),
|
||||
static_cast<jdouble>(lower),
|
||||
static_cast<jdouble>(upper));
|
||||
jobject ex = env->NewObject(boundaryExCls, constructor, msg);
|
||||
env->Throw(static_cast<jthrowable>(ex));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ void InterruptThreadJNI::Main() {
|
||||
args.version = JNI_VERSION_1_2;
|
||||
args.name = const_cast<char*>("Interrupt");
|
||||
args.group = nullptr;
|
||||
jint rs = jvm->AttachCurrentThreadAsDaemon((void**)&env, &args);
|
||||
jint rs = jvm->AttachCurrentThreadAsDaemon(reinterpret_cast<void**>(&env),
|
||||
&args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
@@ -95,7 +96,7 @@ void InterruptThreadJNI::Main() {
|
||||
uint32_t mask = m_mask;
|
||||
jobject param = m_param;
|
||||
lock.unlock(); // don't hold mutex during callback execution
|
||||
env->CallVoidMethod(func, mid, (jint)mask, param);
|
||||
env->CallVoidMethod(func, mid, static_cast<jint>(mask), param);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
@@ -111,7 +112,7 @@ void InterruptThreadJNI::Main() {
|
||||
}
|
||||
|
||||
void interruptHandler(uint32_t mask, void* param) {
|
||||
((InterruptJNI*)param)->Notify(mask);
|
||||
static_cast<InterruptJNI*>(param)->Notify(mask);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -17,7 +17,7 @@ static void throwJavaException(JNIEnv *env) {
|
||||
jclass je = env->FindClass("com/ni/vision/VisionException");
|
||||
int err = imaqGetLastError();
|
||||
const char* err_text = getErrorText(err);
|
||||
char* full_err_msg = (char*)malloc(30+strlen(err_text));
|
||||
char* full_err_msg = static_cast<char*>(malloc(30+strlen(err_text)));
|
||||
sprintf(full_err_msg, "imaqError: %d: %s", err, err_text);
|
||||
env->ThrowNew(je, full_err_msg);
|
||||
free(full_err_msg);
|
||||
@@ -27,7 +27,7 @@ static void throwJavaException(JNIEnv *env) {
|
||||
static void dxthrowJavaException(JNIEnv *env, IMAQdxError err) {
|
||||
jclass je = env->FindClass("com/ni/vision/VisionException");
|
||||
const char* err_text = getErrorText(err);
|
||||
char* full_err_msg = (char*)malloc(30+strlen(err_text));
|
||||
char* full_err_msg = static_cast<char*>(malloc(30+strlen(err_text)));
|
||||
sprintf(full_err_msg, "IMAQdxError: %d: %s", err, err_text);
|
||||
env->ThrowNew(je, full_err_msg);
|
||||
free(full_err_msg);
|
||||
|
||||
@@ -79,7 +79,8 @@ void NotifierThreadJNI::Main() {
|
||||
args.version = JNI_VERSION_1_2;
|
||||
args.name = const_cast<char *>("Notifier");
|
||||
args.group = nullptr;
|
||||
jint rs = jvm->AttachCurrentThreadAsDaemon((void **)&env, &args);
|
||||
jint rs =
|
||||
jvm->AttachCurrentThreadAsDaemon(reinterpret_cast<void **>(&env), &args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
@@ -92,7 +93,7 @@ void NotifierThreadJNI::Main() {
|
||||
jmethodID mid = m_mid;
|
||||
uint64_t currentTime = m_currentTime;
|
||||
lock.unlock(); // don't hold mutex during callback execution
|
||||
env->CallVoidMethod(func, mid, (jlong)currentTime);
|
||||
env->CallVoidMethod(func, mid, static_cast<jlong>(currentTime));
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
|
||||
@@ -1169,7 +1169,7 @@ static void throwJavaException(JNIEnv *env) {{
|
||||
jclass je = env->FindClass("{packagepath}/VisionException");
|
||||
int err = imaqGetLastError();
|
||||
const char* err_text = getErrorText(err);
|
||||
char* full_err_msg = (char*)malloc(30+strlen(err_text));
|
||||
char* full_err_msg = static_cast<char*>(malloc(30+strlen(err_text)));
|
||||
sprintf(full_err_msg, "imaqError: %d: %s", err, err_text);
|
||||
env->ThrowNew(je, full_err_msg);
|
||||
free(full_err_msg);
|
||||
@@ -1179,7 +1179,7 @@ static void throwJavaException(JNIEnv *env) {{
|
||||
static void dxthrowJavaException(JNIEnv *env, IMAQdxError err) {{
|
||||
jclass je = env->FindClass("{packagepath}/VisionException");
|
||||
const char* err_text = getErrorText(err);
|
||||
char* full_err_msg = (char*)malloc(30+strlen(err_text));
|
||||
char* full_err_msg = static_cast<char*>(malloc(30+strlen(err_text)));
|
||||
sprintf(full_err_msg, "IMAQdxError: %d: %s", err, err_text);
|
||||
env->ThrowNew(je, full_err_msg);
|
||||
free(full_err_msg);
|
||||
|
||||
Reference in New Issue
Block a user