mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-03 05:57:40 -05:00
fix: Random build errors with GCC 12.1.0
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
@@ -26,7 +27,7 @@ namespace hex {
|
||||
[[nodiscard]] bool valid() const { return this->m_valid; }
|
||||
|
||||
private:
|
||||
void parseThingyFile(std::ifstream &content);
|
||||
void parseThingyFile(fs::File &file);
|
||||
|
||||
bool m_valid = false;
|
||||
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace hex {
|
||||
|
||||
EncodingFile::EncodingFile(Type type, const std::fs::path &path) {
|
||||
std::ifstream encodingFile(path.c_str());
|
||||
|
||||
auto file = fs::File(path, fs::File::Mode::Read);
|
||||
switch (type) {
|
||||
case Type::Thingy:
|
||||
parseThingyFile(encodingFile);
|
||||
parseThingyFile(file);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -34,22 +31,23 @@ namespace hex {
|
||||
return { ".", 1 };
|
||||
}
|
||||
|
||||
void EncodingFile::parseThingyFile(std::ifstream &content) {
|
||||
for (std::string line; std::getline(content, line);) {
|
||||
void EncodingFile::parseThingyFile(fs::File &file) {
|
||||
for (const auto &line : splitString(file.readString(), "\n")) {
|
||||
|
||||
std::string from, to;
|
||||
{
|
||||
auto delimiterPos = line.find('=', 0);
|
||||
auto delimiterPos = line.find('=');
|
||||
|
||||
if (delimiterPos == std::string::npos)
|
||||
continue;
|
||||
if (delimiterPos >= from.length())
|
||||
continue;
|
||||
if (delimiterPos >= to.length())
|
||||
continue;
|
||||
|
||||
from = line.substr(0, delimiterPos);
|
||||
to = line.substr(delimiterPos + 1);
|
||||
|
||||
hex::trim(from);
|
||||
hex::trim(to);
|
||||
|
||||
if (from.empty()) continue;
|
||||
if (to.empty()) to = " ";
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace hex {
|
||||
}
|
||||
|
||||
static PyObject *createStructureType(const std::string &keyword, PyObject *args) {
|
||||
if (args == nullptr) {
|
||||
PyErr_BadArgument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto type = PyTuple_GetItem(args, 0);
|
||||
if (type == nullptr) {
|
||||
PyErr_BadArgument();
|
||||
@@ -119,10 +124,19 @@ namespace hex {
|
||||
|
||||
for (Py_ssize_t i = 0; i < PyList_Size(list); i++) {
|
||||
auto item = PyList_GetItem(list, i);
|
||||
if (item == nullptr) {
|
||||
PyErr_SetString(PyExc_TypeError, "failed to get item from list");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto memberName = PyUnicode_AsUTF8(PyTuple_GetItem(item, 0));
|
||||
if (memberName == nullptr) {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid member name");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto memberType = PyTuple_GetItem(item, 1);
|
||||
if (memberType == nullptr) {
|
||||
if (!PyTuple_Check(memberType) || memberType == nullptr) {
|
||||
PyErr_SetString(PyExc_TypeError, "member needs to have a annotation extending from ImHexType");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -148,12 +162,6 @@ namespace hex {
|
||||
code += "["s + PyUnicode_AsUTF8(arraySize) + "];\n";
|
||||
else if (PyLong_Check(arraySize))
|
||||
code += "["s + std::to_string(PyLong_AsLong(arraySize)) + "];\n";
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "invalid array size type. Expected string or int");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
auto memberTypeInstance = PyObject_CallObject(memberType, nullptr);
|
||||
if (memberTypeInstance == nullptr || memberTypeInstance->ob_type->tp_base == nullptr || memberTypeInstance->ob_type->tp_base->tp_name != "ImHexType"s) {
|
||||
|
||||
Reference in New Issue
Block a user