Skip to content

Make the VQA seek command's origin explicit - #114

Open
mischa85 wants to merge 3 commits into
OpenTS-Developers:mainfrom
mischa85:seek-origin
Open

Make the VQA seek command's origin explicit#114
mischa85 wants to merge 3 commits into
OpenTS-Developers:mainfrom
mischa85:seek-origin

Conversation

@mischa85

@mischa85 mischa85 commented Sep 2, 2026

Copy link
Copy Markdown

VQACMD_SEEK carries lseek's origin in its buffer argument, but the comment in both stream handlers said "Buffer has no meaning here", and the origin was spelled five ways across 15 call sites: SEEK_CUR, SEEK_SET, NULL, 0 and (void *)1. All of them now name the constant. The origin is also taken back through intptr_t rather than int, which truncated on a 64-bit target.

Behaviour preserved: SEEK_SET is 0 and SEEK_CUR is 1, so every rename keeps the value it had.

mischa85 added a commit to mischa85/OpenTS that referenced this pull request Sep 3, 2026

@Krisztiaan Krisztiaan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, just an extra step suggested

Comment thread code/vqalib/dstream.cpp Outdated
Comment thread code/vqalib/dstream.cpp Outdated
Comment thread code/vqalib/vqaplay.h
*/
inline int VQA_DecodeSeekOrigin(void *buffer)
{
return (int)(std::intptr_t)buffer;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this cascade cast if you can make a specific reinterpret_cast<int>(buffer);?

@mischa85 mischa85 Sep 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't compile on a 64-bit target. It only compiles on win32 because a pointer there is 32 bits.

So it would become static_cast<int>(reinterpret_cast<std::intptr_t>(buffer)) if we want to avoid C-style casts...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it would become static_cast<int>(reinterpret_cast<std::intptr_t>(buffer)) if we want to avoid C-style casts...

Em, no, 1 specific c++ cast static_cast<int>(buffer) is enough.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread code/vqalib/vqaplay.h
Comment on lines +369 to +373
/* VQACMD_SEEK and VQACMD_SEEKPEEK carry the seek origin in Buffer rather
* than a pointer. It comes back at pointer width before narrowing to the
* int origin that lseek and FileClass::Seek take.
*/
inline int VQA_DecodeSeekOrigin(void *buffer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this function if its code just return the void pointer as int (even not int32_t)

@mischa85 mischa85 Sep 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns int because that's the origin parameter of lseek and FileClass::Seek. int32_t is a typedef for int on both MSVC and clang, so that would change the spelling and nothing else, while no longer matching the API it feeds.

The smell is real though: the protocol hands you an integer in a pointer parameter, and a decoder is the best we can do without changing the protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants