Fix cross-platform path handling
completed by: Nagato Yuki
mentors: Andrew Whitworth
Task Description
Parrot Ticket #1282 describes a problem with the OS PMC type. The OS PMC implements a variety of routines for interacting with the operating system and file system. The problem is that the path separator slashes ('/' on linux, '\\' on windows) get mixed and matched. We need to fix this.
In src/library.c there is a function cnv_to_win32_filesep to convert to windows slashes when we're on Windows systems. This function is a little messy, poorly named and not used consistently.
Rename the function cnv_to_win32_filesep to Parrot_lib_fix_path_slashes. Make it a public function (not "static"). Fix the function so that it converts to the current platform (Convert '\\' to '/' on linux, convert '/' to '\\' on windows). Right now it only converts to windows-style slashes, you need to fix it to do both. Use your new function in src/dynpmc/os.pmc in the cwd method to fix Ticket # 1282. Make sure the new function is used consistently in src/library.c, wherever it might be needed.
Notice that the STRING* type in Parrot is more complicated than the "char*" from normal C. A Parrot STRING contains information about encodings and charsets, buffer allocation and management, and other details. See the existing code in src/library.c for code examples. If you need additional functionality, look at src/string/api.c for more functions.
Steps To Complete This Task
- Create a fork of parrot.git on github.com
- Rename your function in src/library.c. Make it not static.
- Run "make headerizer" to update header files
- Use your new function in src/dynpmc/os.pmc
- Scan through src/library.c and make sure your new function is used everywhere it should be used.
- Build parrot and run it's test suite (make fulltest) to verify that things still work
- Create a Github pull request (button on the upper right of your fork) to have your changes incorporated into the master repository
Benefits
- Proper native path handling is important for consistent, correct behavior on all systems.
- Being able to write code once and have it "just work" on all platforms is important. Parrot can handle the messy details of path separators.
Requirements
- C Programming Language