Repository navigation
Conversation
|
I can squash all the commits at the end. I'm not super sure about how to handle the mono-typed arrays. Currently, I'm not enforcing strict typing except when reading/writing. I suppose you could have a wrapper around |
|
yeah, I agree there's probably no point in enforcing strict typing other than at read/write time |
leoetlino
left a comment
There was a problem hiding this comment.
@leoetlino reviewed 10 files and all commit messages, and made 11 comments.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on dt-12345).
py/py_byml.cpp line 77 at r1 (raw file):
return std::invoke(callable, obj, std::forward<Ts>(args)...); }; if (py::isinstance<Byml::Array>(handle)) {
let's not copy and paste the same block too many times. can we try something like
template <typename T, Byml::Type type>
struct Borrowable {};
template <typename... Ts, typename Callable>
static auto BorrowByml(Callable&& callable) {
return [&, callable](py::handle handle, Ts&&... args) {
Byml obj;
const auto invoke = [&] { return std::invoke(callable, obj, std::forward<Ts>(args)...); };
const auto borrow_and_invoke = [&]<typename T, Byml::Type type, typename... Rest>(
const auto& self, Borrowable<T, type>, Rest... rest) {
if (!py::isinstance<T>(handle)) {
if constexpr (sizeof...(Rest) == 0) {
obj = handle.cast<Byml>();
return invoke();
} else {
return self(self, rest...);
}
}
auto& ref = handle.cast<T&>();
obj = std::move(ref);
util::ScopeGuard guard{[&] { ref = std::move(obj.Get<type>()); }};
return invoke();
};
return borrow_and_invoke(borrow_and_invoke,
Borrowable<Byml::Array, Byml::Type::Array>{},
Borrowable<Byml::MonoTypedArray, Byml::Type::MonoTypedArray>{},
Borrowable<Byml::Dictionary, Byml::Type::Dictionary>{},
Borrowable<Byml::OrderedDictionary, Byml::Type::OrderedDictionary>{},
Borrowable<Byml::Hash32, Byml::Type::Hash32>{},
Borrowable<Byml::Hash64, Byml::Type::Hash64>{},
Borrowable<Byml::OrderedHash32, Byml::Type::OrderedHash32>{},
Borrowable<Byml::OrderedHash64, Byml::Type::OrderedHash64>{});
};
}src/byml.cpp line 60 at r1 (raw file):
Hash32 = 0x20, Hash64 = 0x21, OrderedHash32 = 0x30, // Unsupported
these are no longer unsupported are they?
src/byml.cpp line 343 at r1 (raw file):
const std::vector<u32> indices = ParseIndexOrder(index_offset, size); result.reserve(size); for (u32 i = 0; i < size; ++i) {
for (auto index : indices)? doesn't look like we're using i other than to get the i-th index
src/byml.cpp line 397 at r1 (raw file):
const std::vector<u32> indices = ParseIndexOrder(index_offset, size); result.reserve(size); for (u32 i = 0; i < size; ++i) {
for (auto index : indices)?
src/byml.cpp line 593 at r1 (raw file):
switch (data.GetType()) { case Byml::Type::Hash32: { const auto& hash = data.GetHash32();
these are all looking very similar - can we refactor these new cases into a (likely templated) function to deduplicate them?
src/include/oead/byml.h line 56 at r1 (raw file):
Array, MonoTypedArray, Dictionary,
afaik Hash is the official name for this data type - or do you know if they've renamed it since?
src/include/oead/byml.h line 72 at r1 (raw file):
using OrderedHash32 = tsl::ordered_map<u32, Byml, absl::Hash<u32>, std::equal_to<u32>, std::allocator<std::pair<u32, Byml>>, std::vector<std::pair<u32, Byml>>>;
any reason we're specifying all these template arguments? do the defaults not work?
src/include/oead/byml.h line 85 at r1 (raw file):
struct MonoTypedArray { MonoTypedArray() : elements(), type(Type::Null) {}
Suggestion:
MonoTypedArray() = default;src/include/oead/byml.h line 87 at r1 (raw file):
MonoTypedArray() : elements(), type(Type::Null) {} explicit MonoTypedArray(Type type_) : elements(), type(type_) {}
Suggestion:
explicit MonoTypedArray(Type type_) : type(type_) {}src/include/oead/byml.h line 98 at r1 (raw file):
std::vector<Byml> elements; Type type;
Suggestion:
Type type = Type::Null;test/test_map_get.py line 64 at r1 (raw file):
2 : oead.U32(2), 3 : oead.U32(3), 4 : oead.U32(4),
can we try adding 10: oead.U32(10) somewhere in the middle to make sure that the items don't get reordered?
dt-12345
left a comment
There was a problem hiding this comment.
@dt-12345 made 11 comments.
Reviewable status: 2 of 11 files reviewed, 11 unresolved discussions (waiting on leoetlino).
py/py_byml.cpp line 77 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
let's not copy and paste the same block too many times. can we try something like
template <typename T, Byml::Type type> struct Borrowable {}; template <typename... Ts, typename Callable> static auto BorrowByml(Callable&& callable) { return [&, callable](py::handle handle, Ts&&... args) { Byml obj; const auto invoke = [&] { return std::invoke(callable, obj, std::forward<Ts>(args)...); }; const auto borrow_and_invoke = [&]<typename T, Byml::Type type, typename... Rest>( const auto& self, Borrowable<T, type>, Rest... rest) { if (!py::isinstance<T>(handle)) { if constexpr (sizeof...(Rest) == 0) { obj = handle.cast<Byml>(); return invoke(); } else { return self(self, rest...); } } auto& ref = handle.cast<T&>(); obj = std::move(ref); util::ScopeGuard guard{[&] { ref = std::move(obj.Get<type>()); }}; return invoke(); }; return borrow_and_invoke(borrow_and_invoke, Borrowable<Byml::Array, Byml::Type::Array>{}, Borrowable<Byml::MonoTypedArray, Byml::Type::MonoTypedArray>{}, Borrowable<Byml::Dictionary, Byml::Type::Dictionary>{}, Borrowable<Byml::OrderedDictionary, Byml::Type::OrderedDictionary>{}, Borrowable<Byml::Hash32, Byml::Type::Hash32>{}, Borrowable<Byml::Hash64, Byml::Type::Hash64>{}, Borrowable<Byml::OrderedHash32, Byml::Type::OrderedHash32>{}, Borrowable<Byml::OrderedHash64, Byml::Type::OrderedHash64>{}); }; }
Done.
src/byml.cpp line 60 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
these are no longer unsupported are they?
Done.
src/byml.cpp line 343 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
for (auto index : indices)? doesn't look like we're using i other than to get the i-th index
Done.
src/byml.cpp line 397 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
for (auto index : indices)?
Done.
src/byml.cpp line 593 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
these are all looking very similar - can we refactor these new cases into a (likely templated) function to deduplicate them?
Done.
src/include/oead/byml.h line 56 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
afaik Hash is the official name for this data type - or do you know if they've renamed it since?
I don't know if we have any official confirmation of them renaming it. I thought it might be a bit clearer to distinguish between the versions with integer keys and string keys, but I can revert it if we prefer to stick to the official naming as much as possible.
src/include/oead/byml.h line 72 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
any reason we're specifying all these template arguments? do the defaults not work?
They do, but I saw we were using std::vector as the underlying container in the aamp classes so I thought I should do the same here.
test/test_map_get.py line 64 at r1 (raw file):
Previously, leoetlino (Léo Lam) wrote…
can we try adding 10: oead.U32(10) somewhere in the middle to make sure that the items don't get reordered?
Done.
src/include/oead/byml.h line 87 at r1 (raw file):
MonoTypedArray() : elements(), type(Type::Null) {} explicit MonoTypedArray(Type type_) : elements(), type(type_) {}
Done.
src/include/oead/byml.h line 85 at r1 (raw file):
struct MonoTypedArray { MonoTypedArray() : elements(), type(Type::Null) {}
Done.
src/include/oead/byml.h line 98 at r1 (raw file):
std::vector<Byml> elements; Type type;
Done.
leoetlino
left a comment
There was a problem hiding this comment.
@leoetlino reviewed 9 files and all commit messages, made 1 comment, and resolved 11 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on dt-12345).
src/byml.cpp line 629 at r2 (raw file):
} writer.AlignUp(4); WriteIndices(indices);
I think I'm a bit confused - why do we need indices? in your old version, we're writing sorted but now we're writing indices? was that a bug?
|
I ran this through AI and it looks like a few bugs sneaked past my review :^)
a quick verification suggests these are real problems |
|
Thanks, I'll get to fixing these. I am realizing now that the
Like a crash? Doesn't the reader class check all the reads already? Though related to that, I did notice that the existing |
|
Previously, leoetlino (Léo Lam) wrote…
Yeah, it was wrong before. I think it's good now ( |
Adds support for:
TODO:
tsl::ordered_mapstd::vector<Byml>(though maybe without exposing references to the underlying elements to enforce the mono-typing?)Also as side note - the current abseil version fails to build on Windows with compilers that don't define
_MSC_VER(MinGW, Windows clang not in MSVC-compatibility mode) becauseO_NONBLOCKis not defined. This is fixed in upstream by abseil/abseil-cpp@ddbdebc.This change is