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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 37 deletions

View File

@ -1,5 +1,5 @@
#ifndef ARMJIT_COMPILER_H
#define ARMJIT_COMPILER_H
#ifndef ARMJIT_A64_COMPILER_H
#define ARMJIT_A64_COMPILER_H
#include "../ARM.h"
#include "../ARMJIT.h"
@ -266,4 +266,4 @@ public:
}
#endif
#endif

View File

@ -42,7 +42,7 @@ s64 Compiler::RewriteMemAccess(u64 pc)
return patch.PatchOffset;
}
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)
@ -807,4 +807,4 @@ void Compiler::T_Comp_LDMIA_STMIA()
}
}
}
}

View File

@ -1,3 +1,6 @@
#ifndef ARMJIT_COMPILER_H
#define ARMJIT_COMPILER_H
#if defined(__x86_64__)
#include "ARMJIT_x64/ARMJIT_Compiler.h"
#elif defined(__aarch64__)
@ -9,4 +12,6 @@
namespace ARMJIT
{
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)

View File

@ -209,7 +209,8 @@ void Compiler::A_Comp_Arith()
Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2);
break;
default:
assert("unimplemented");
printf("this is a JIT bug! %04x\n", op);
abort();
}
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);
}
assert(false);
abort();
}
void Compiler::T_Comp_ShiftImm()
@ -779,4 +780,4 @@ void Compiler::T_Comp_RelAddr()
MOV(32, rd, Imm32((R15 & ~2) + offset));
}
}
}

View File

@ -1,5 +1,5 @@
#ifndef ARMJIT_COMPILER_H
#define ARMJIT_COMPILER_H
#ifndef ARMJIT_X64_COMPILER_H
#define ARMJIT_X64_COMPILER_H
#include "../dolphin/x64Emitter.h"
@ -252,4 +252,4 @@ public:
}
#endif
#endif

View File

@ -39,7 +39,7 @@ s32 Compiler::RewriteMemAccess(u64 pc)
return patch.Offset;
}
printf("this is a JIT bug %x\n", pc);
printf("this is a JIT bug %llx\n", pc);
abort();
}
@ -819,4 +819,4 @@ void Compiler::T_Comp_LDMIA_STMIA()
ADD(32, rb, Imm8(offset));
}
}
}

View File

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

View File

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

View File

@ -16,6 +16,9 @@
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 <string.h>
#include <time.h>
@ -125,31 +128,29 @@ void ByteIn(u8 val)
case 0x20:
{
time_t timestamp;
struct tm* timedata;
time(&timestamp);
timedata = localtime(&timestamp);
time_t timestamp = time(NULL);
struct tm timedata;
localtime_r(&timestamp, &timedata);
Output[0] = BCD(timedata->tm_year - 100);
Output[1] = BCD(timedata->tm_mon + 1);
Output[2] = BCD(timedata->tm_mday);
Output[3] = BCD(timedata->tm_wday);
Output[4] = BCD(timedata->tm_hour);
Output[5] = BCD(timedata->tm_min);
Output[6] = BCD(timedata->tm_sec);
Output[0] = BCD(timedata.tm_year - 100);
Output[1] = BCD(timedata.tm_mon + 1);
Output[2] = BCD(timedata.tm_mday);
Output[3] = BCD(timedata.tm_wday);
Output[4] = BCD(timedata.tm_hour);
Output[5] = BCD(timedata.tm_min);
Output[6] = BCD(timedata.tm_sec);
}
break;
case 0x60:
{
time_t timestamp;
struct tm* timedata;
time(&timestamp);
timedata = localtime(&timestamp);
time_t timestamp = time(NULL);
struct tm timedata;
localtime_r(&timestamp, &timedata);
Output[0] = BCD(timedata->tm_hour);
Output[1] = BCD(timedata->tm_min);
Output[2] = BCD(timedata->tm_sec);
Output[0] = BCD(timedata.tm_hour);
Output[1] = BCD(timedata.tm_min);
Output[2] = BCD(timedata.tm_sec);
}
break;

View File

@ -228,7 +228,7 @@ void KeyMapButton::keyPressEvent(QKeyEvent* 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 mod = event->modifiers();

View File

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