Skip to content
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

How to access files from the binary #79

Open
coolcoder613eb opened this issue Oct 10, 2023 · 5 comments
Open

How to access files from the binary #79

coolcoder613eb opened this issue Oct 10, 2023 · 5 comments
Labels
question Further information is requested

Comments

@coolcoder613eb
Copy link

I have built RustPython for DOS, https://github.com/coolcoder613eb/RustPython
And I want to know how make the binary accept files from the command line.
right now it says:
Screenshot 2023-10-10 at 4 47 15 pm
[ERROR rustpython_vm::vm::compile] Failed reading file 'PYBASIC.PY': No such file or directory (os error 44)

@turbolent
Copy link
Owner

turbolent commented Oct 14, 2023

Are you sure you are providing the WASI environment with a file descriptor (capability) to the directory? See e.g.

w2c2/examples/python/main.c

Lines 211 to 214 in 2e9c86f

if (!wasiFileDescriptorAdd(-1, "/", NULL)) {
fprintf(stderr, "failed to add preopen\n");
return 1;
}

Note that paths are assumed to be WASI paths, which are Unix/POSIX paths (e.g /foo/bar).

w2c2's WASI implementation automatically translates Unix paths to the native format (

w2c2/wasi/wasi.c

Lines 313 to 333 in 2e9c86f

#elif defined(__MSDOS__)
bool isAbsolute = path[0] == '/';
char *pos = path;
while ((pos = strchr(pos, '/'))) {
*pos = PATH_SEPARATOR;
}
/* Prefix with volume name */
if (isAbsolute) {
size_t pathLength = strlen(path);
unsigned int drive;
_dos_getdrive(&drive);
memmove(path + 2, path, pathLength);
path[0] = 'A' + drive - 1;
path[1] = ':';
pathLength += 2;
path[pathLength] = '\0';
}
#else
), and back

What compiler are you using, DJGPP?

@turbolent turbolent added the question Further information is requested label Oct 14, 2023
@coolcoder613eb
Copy link
Author

Yes, DJGPP, and i think i have fixed it, my solution also means you do not need to write out the full path.
my code in main.c:

#ifdef __MSDOS__
    if (!wasiFileDescriptorAdd(-1, "C:\\", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }
#endif
    if (!wasiFileDescriptorAdd(-2, ".", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }

    if (!wasiFileDescriptorAdd(-3, "/", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }

@coolcoder613eb
Copy link
Author

Not really related, but how would I compile for windows 2000?
CPython3.11, and RustPython without freeze-stdlib, don't work on DOS through w2c2 because of 8.3, is there any solution?

@SamuraiCrow
Copy link
Contributor

How do you run on drive D or later with your fix?

@coolcoder613eb
Copy link
Author

coolcoder613eb commented Oct 15, 2023

I dont know, haven't tried.
I could try doing:

if (!wasiFileDescriptorAdd(-1, "A:\\", NULL)) {
        fprintf(stderr, "failed to add A: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "B:\\", NULL)) {
        fprintf(stderr, "failed to add B: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "C:\\", NULL)) {
        fprintf(stderr, "failed to add C: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "D:\\", NULL)) {
        fprintf(stderr, "failed to add D: preopen\n");
    }

etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants