Random minor fixes (#757)

* Fix incorrect/questionable assert() usage

Originally reported by https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2159000700,
but also includes a bunch of other fixes.

* Fix some `printf` warnings

Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2160310550

* Remove useless check

It is never passed thanks to `if (num_in < 1) {...; return}` before
Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840804

* Add missing header guard, rename other to avoid conflicts

Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2163210746

* Make DSi_SDDevice destructor virtual

Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2158670642

* Use thread-safe localtime_r, assign `time` result directly

Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840805

* Fix MinGW build

It needs _POSIX_THREAD_SAFE_FUNCTIONS to export `localtime_r`
This commit is contained in:
Valeri
2020-10-01 14:44:09 +03:00
committed by GitHub
parent 9d5791f8e5
commit 0d845c9e69
12 changed files with 44 additions and 37 deletions

View File

@ -1,5 +1,5 @@
#ifndef ARMJIT_COMPILER_H #ifndef ARMJIT_A64_COMPILER_H
#define ARMJIT_COMPILER_H #define ARMJIT_A64_COMPILER_H
#include "../ARM.h" #include "../ARM.h"
#include "../ARMJIT.h" #include "../ARMJIT.h"

View File

@ -42,7 +42,7 @@ s64 Compiler::RewriteMemAccess(u64 pc)
return patch.PatchOffset; return patch.PatchOffset;
} }
printf("this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc)); printf("this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc));
assert(false); abort();
} }
bool Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr) bool Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr)

View File

@ -1,3 +1,6 @@
#ifndef ARMJIT_COMPILER_H
#define ARMJIT_COMPILER_H
#if defined(__x86_64__) #if defined(__x86_64__)
#include "ARMJIT_x64/ARMJIT_Compiler.h" #include "ARMJIT_x64/ARMJIT_Compiler.h"
#elif defined(__aarch64__) #elif defined(__aarch64__)
@ -10,3 +13,5 @@ namespace ARMJIT
{ {
extern Compiler* JITCompiler; extern Compiler* JITCompiler;
} }
#endif

View File

@ -61,7 +61,8 @@ public:
} }
} }
assert("Welp!"); printf("this is a JIT bug! LoadRegister failed\n");
abort();
} }
void PutLiteral(int reg, u32 val) void PutLiteral(int reg, u32 val)

View File

@ -209,7 +209,8 @@ void Compiler::A_Comp_Arith()
Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2);
break; break;
default: default:
assert("unimplemented"); printf("this is a JIT bug! %04x\n", op);
abort();
} }
if (CurInstr.A_Reg(12) == 15) if (CurInstr.A_Reg(12) == 15)
@ -566,7 +567,7 @@ OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& car
return R(RSCRATCH); return R(RSCRATCH);
} }
assert(false); abort();
} }
void Compiler::T_Comp_ShiftImm() void Compiler::T_Comp_ShiftImm()

View File

@ -1,5 +1,5 @@
#ifndef ARMJIT_COMPILER_H #ifndef ARMJIT_X64_COMPILER_H
#define ARMJIT_COMPILER_H #define ARMJIT_X64_COMPILER_H
#include "../dolphin/x64Emitter.h" #include "../dolphin/x64Emitter.h"

View File

@ -39,7 +39,7 @@ s32 Compiler::RewriteMemAccess(u64 pc)
return patch.Offset; return patch.Offset;
} }
printf("this is a JIT bug %x\n", pc); printf("this is a JIT bug %llx\n", pc);
abort(); abort();
} }

View File

@ -169,7 +169,7 @@ void Save()
if (entry->Type == 0) if (entry->Type == 0)
fprintf(f, "%s=%d\n", entry->Name, *(int*)entry->Value); fprintf(f, "%s=%d\n", entry->Name, *(int*)entry->Value);
else else
fprintf(f, "%s=%s\n", entry->Name, entry->Value); fprintf(f, "%s=%s\n", entry->Name, (char*)entry->Value);
entry++; entry++;
} }

View File

@ -103,7 +103,7 @@ class DSi_SDDevice
{ {
public: public:
DSi_SDDevice(DSi_SDHost* host) { Host = host; IRQ = false; } DSi_SDDevice(DSi_SDHost* host) { Host = host; IRQ = false; }
~DSi_SDDevice() {} virtual ~DSi_SDDevice() {}
virtual void Reset() = 0; virtual void Reset() = 0;

View File

@ -16,6 +16,9 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
// Required by MinGW to enable localtime_r in time.h
#define _POSIX_THREAD_SAFE_FUNCTIONS
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -125,31 +128,29 @@ void ByteIn(u8 val)
case 0x20: case 0x20:
{ {
time_t timestamp; time_t timestamp = time(NULL);
struct tm* timedata; struct tm timedata;
time(&timestamp); localtime_r(&timestamp, &timedata);
timedata = localtime(&timestamp);
Output[0] = BCD(timedata->tm_year - 100); Output[0] = BCD(timedata.tm_year - 100);
Output[1] = BCD(timedata->tm_mon + 1); Output[1] = BCD(timedata.tm_mon + 1);
Output[2] = BCD(timedata->tm_mday); Output[2] = BCD(timedata.tm_mday);
Output[3] = BCD(timedata->tm_wday); Output[3] = BCD(timedata.tm_wday);
Output[4] = BCD(timedata->tm_hour); Output[4] = BCD(timedata.tm_hour);
Output[5] = BCD(timedata->tm_min); Output[5] = BCD(timedata.tm_min);
Output[6] = BCD(timedata->tm_sec); Output[6] = BCD(timedata.tm_sec);
} }
break; break;
case 0x60: case 0x60:
{ {
time_t timestamp; time_t timestamp = time(NULL);
struct tm* timedata; struct tm timedata;
time(&timestamp); localtime_r(&timestamp, &timedata);
timedata = localtime(&timestamp);
Output[0] = BCD(timedata->tm_hour); Output[0] = BCD(timedata.tm_hour);
Output[1] = BCD(timedata->tm_min); Output[1] = BCD(timedata.tm_min);
Output[2] = BCD(timedata->tm_sec); Output[2] = BCD(timedata.tm_sec);
} }
break; break;

View File

@ -228,7 +228,7 @@ void KeyMapButton::keyPressEvent(QKeyEvent* event)
{ {
if (!isChecked()) return QPushButton::keyPressEvent(event); if (!isChecked()) return QPushButton::keyPressEvent(event);
printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode()); printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), (int)event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode());
int key = event->key(); int key = event->key();
int mod = event->modifiers(); int mod = event->modifiers();

View File

@ -115,7 +115,6 @@ void audioCallback(void* data, Uint8* stream, int len)
if (num_in < len_in-margin) if (num_in < len_in-margin)
{ {
int last = num_in-1; int last = num_in-1;
if (last < 0) last = 0;
for (int i = num_in; i < len_in-margin; i++) for (int i = num_in; i < len_in-margin; i++)
((u32*)buf_in)[i] = ((u32*)buf_in)[last]; ((u32*)buf_in)[i] = ((u32*)buf_in)[last];