Ticket #778 (closed RFC: duplicate)

Opened 13 years ago

Last modified 13 years ago

Make FileHandle Subclassable

Reported by: whiteknight Owned by:
Priority: normal Milestone:
Component: none Version: 1.3.0
Severity: medium Keywords: io oo pmc
Cc: Language:
Patch status: Platform:


There were some other related tickets (I can't find them now) about this, so sorry if I am duplicating anything.

FileHandles are not current subclassable in PIR because they have ATTRs that are not usable from PIR (char*, PIOOFF_T, etc). In order for a PMC like FileHandle to be properly subclassable, every one of it's ATTRs must be an INTVAL, FLOATVAL, STRING* or PMC*. Otherwise, the subclass will throw an exception if we try to access an ATTR that is not one of these from the parent type.

I want to make two changes to FileHandle (in addition to the cleanups I am working on in the io_cleanups branch right now) to make this possible:

1) Create a new IOBuffer PMC type to take care of buffering. FileHandle will then delegate it's buffering needs to a PMC of this type. The benefit here is that we can use this same buffering functionality from other IO PMC types (sockets, pipes, etc). 2) Convert the ATTRs file_pos and last_pos from type PIOOFF_T into type INTVAL. This may be a lossy transition but it's worth noting that almost every use of these two ATTRs, outside the IO API, are converted to INTVAL already.

#2 of course is a little sketchy, so I would be happy to hear about alternate ideas to fix this issue. Shortly after getting these ATTRs fixed (if not immediately thereafter) we should be able to properly subclass FileHandles.

Change History

Changed 13 years ago by allison

  • status changed from new to closed
  • resolution set to duplicate

We can't use the same buffering for the different I/O sources anyway, so no advantage to the IOBuffer PMC.

PIOOFF_T can't be cast to an INTVAL. It's a long in STDIO, and a HUGEINTVAL on Windows I/O.

Talked with Whiteknight about FileHandle subclassing in IRC a few days ago. The better solution is to make it generally possible to subclass PMCs with ATTRs other than the four canonical types, which he's working on now in TT #789. This ticket rejected, in favor of that one.

Note: See TracTickets for help on using tickets.