GSoC/GCI Archive
Google Code-in 2010 Parrot Foundation and The Perl Foundation

Refactor close() method behavior on IO handle types

completed by: Fernando Brito

mentors: whiteknight

Task Description: Parrot's IO system has several major improvements scheduled in the coming months. Before those can happen, the existing system needs to be cleaned up significantly. Code files in src/io/ directory implement much of the low-level IO logic, while special "Handle" object types in src/pmc/ directory provide specific implementations that the user will interact with. These include "FileHandle" (for interacting with files on disk), Socket (for communicating over a network) and StringHandle (for interacting with a string as if it were a file). All three of these inherit from the abstract type Handle and provide their own close() methods. This needs to be fixed.

Steps to complete:

  1. Create a fork of parrot/parrot on github
  2. Move the close() METHOD from src/pmc/filehandle.pmc to src/pmc/handle.pmc, including documentation.
  3. In the file src/io/api.c, the function Parrot_io_close() needs to be updated to support Socket and StringHandle types
    1. Copy most of the internal logic from the close method in src/pmc/socket.pmc into a new if-branch in Parrot_io_close. A PMC is a socket if it's base_type is enum_class_Socket (See the enum_class_FileHandle example above for inspiration. pmc->vtable->base_type == enum_class_Socket, etc)
    2. Remove the close method from src/pmc/socket.pmc
    3. Copy most of the internal logic from the close method in src/pmc/stringhandle.pmc into a new if-branch in Parrot_io_close. A PMC is a StringHandle if it's base_type is enum_class_StringHandle
    4. remove the close method from src/pmc/stringhandle.pmc
  4. Build parrot and run all tests (make fulltest), fixing any errors that pop up
  5. You may occasionally have to run "make headerizer" when header definitions are changed
  6. open a pull request on github to get your changes merged in.

Links: https://github.com/parrot/parrot, http://trac.parrot.org/parrot/wiki/IOTasklist