-
Notifications
You must be signed in to change notification settings - Fork 71
Bocfel: Add ZTERP_GLK_NO_STDIO version of zterp_os_aux_file #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
A couple comments: At least nominally the idea of "no stdio mode" is orthogonal to the OS. There's probably no reason to, but it's possible to build on Unix with no stdio, for example, assuming the Glk target implements // ╔══════════════════════════════════════════════════════════════════════════════╗
// ║ Parchment functions ║
// ╚══════════════════════════════════════════════════════════════════════════════╝
#elif defined(ZTERP_OS_PARCHMENT)
#if defined(ZTERP_GLK_NO_STDIO) && defined(GLKUNIX_FILEREF_GET_FILENAME)
// code goes here
#endifThen just add Since you're using This dovetails into the next point: this doesn't do any sort of filename sanitizing. I assume that under Parchment that's irrelevant because the browser provides sandboxing of some sort? If so, then having the OS type of Parchment is a good way to signal that: similar to the previous comment, if somebody was building with Glk on a non-supported OS (or no OS provided at all), but did enable no stdio mode, then all of a sudden this code is active, allowing games to escape their containing directory. But if you just mandate that if you're building for the "operating system" of Parchment, you're guaranteed to be sandboxed, or guaranteed that the concept of escaping a containing directory is nonsensical, we're fine. |
It's already required to be defined alongside ZTERP_GLK_UNIX: Lines 31 to 34 in 67d246f
Do you think it would be better to check both are defined here?
Oh yes, I'll add a check for that. But I noticed that io.cpp also requires that if you're using ZTERP_GLK_NO_STDIO then GLKUNIX_FILEREF_CREATE_UNCLEANED must be defined: Lines 40 to 44 in 67d246f
Should we put all of these checks together in one place? I don't know how a C++ project would typically be structured to do that. Does it matter which file the checks happen in - are they compiled in alphabetical order?
|
|
Man, this really is kind of getting to be a mess of macros, isn't it? I didn't think about For the macros, it's just not going to be pretty (par for the course with C/C++ macros). In C++, the macro checks really do need to be right around where they're being used. Build order isn't guaranteed at all, since you can tell So forget I said anything about sanitizing, but we'll still want the excessive macro checks. However... this got me thinking. Your code isn't really tied to no-stdio mode at all. It's basically generic Glk code to provide an auxiliary filename. I didn't realize it earlier, but it's clear now once you mentioned that sanitizing comes for free. I think, then, this should be in the generic function definition, if the right conditions (Glk with #ifndef have_zterp_os_aux_file
#ifdef ZTERP_GLK_UNIX
extern "C" {
#include <glkstart.h>
}
#endif
std::unique_ptr<std::string> zterp_os_aux_file(const std::string &filename)
{
#if defined(ZTERP_GLK_UNIX) && defined(GLKUNIX_FILEREF_GET_FILENAME)
frefid_t fref = glk_fileref_create_by_name(fileusage_Data | fileusage_BinaryMode, const_cast<char *>(filename.c_str()), 0);
if (fref != nullptr) {
auto result = std::make_unique<std::string>(glkunix_fileref_get_filename(fref));
glk_fileref_destroy(fref);
return result;
}
#endif
return nullptr;
}
#endifThis gets around the need for a new operating system type and also doesn't have to even worry about no-stdio mode outside of |
That is the purpose of the no-stdio mode as a whole, to use the glkunix functions rather than stdio functions ;) It's just not necessary anywhere other than Emglken, and sometimes it's a bit clumsy. Glulxe, Git, Hugo and Scare did that already, they never use the stdio filesystem functions, which made it very easy to use with Emglken's very weird FS-less environment. Bocfel only needed tiny changes, and TADS needed.. a lot haha. I don't think Bocfel should be aiming to switch to Glk only (which of course it can't do as it has non-Glk IO modes!) but it is nice when we can get it working in Emglken with minimal changes. Great idea to (if supported) make this the default implementation! I'll update the PR to do that. |
…o mode, add it as the default
|
OK, looks great! Thanks! |
This seems to be working with @EmptySpaceRun's game that uses the Z-Machine's
@save/@restoreno-prompt data file feature.My C++ is very rudimentary, but does it look okay to you?