Oct 30, 1995, 3:02 PM
Post #7 of 11
(1265 views)
Permalink
> From: Malcolm Beattie <mbeattie@sable.ox.ac.uk>
>
> Tim Bunce writes:
> >
> > > From: Malcolm Beattie <mbeattie@sable.ox.ac.uk>
> > >
> > > Kenneth Albanowski writes:
> > > >
> > > > Well, Tim, I not sure enough to comment on your description of how a tie()
> > > > works in SFIO.
> >
> > Well, I wasn't really pushing tie as a mechanism related to sfio. I was
> > simply pointing out that sfio and its stackable disciplines should be
> > included in our discussions.
> >
> > > > Let's try reversing things. Here is the immediate use I
> > > > see (and would like to have available) for tying a handle:
> > > >
> > > > $term = new Term::Control; #Use curses, terminfo, termcap, whatever
> > > > ioctl $term, T_ATTRON, "blink";
> >
> > Umm, personally I think ioctl's aren't the right model for termcap etc.
>
> Perhaps ioctl has the wrong connotations. I was thinking of ioctl
> in this context of meaning a fairly free-form out-of-band hook for
> disciplines to implement non-standard methods in disciplines. Users
> just need to know a name (e.g. "attron") and the sort of data it
> wants and the internals would pass the message along to the right
> discipline in the stack.
An out-of-band hook is a tempting idea but not part of sfio. If you're
thinking of changing sfio then you're into a whole new set of issues.
Basically it sounds like you're looking to merge sfio with a STREAMS-like
messaging system. I suspect we're trying to run with sfio before we can walk.
> > > > Now, how would you see this tying (sorry) in with the SFIO discipline
> > > > paradigm?
> >
> > Well, basically, I don't. Sfio disciplines only encompass read, write, seek
> > and 'exceptions'. It doesn't include ioctl's.
>
> But, since perl has a fairly dynamic class API (just define a
> sub attron { } and suddenly it's available as a method call for
> anyone that wants it) there's nothing to stop discipline classes
> from making out-of-band methods available. It's in this sense that
> I was thinking of the name ioctl, and perhaps Kenneth was too.
> Anything that isn't a read/write/seek gets implemented in its own
> (shared) namespace and lumped under the name "ioctl". STREAMS turns
> the user call ioctl(fd, I_FOO, somedata) into a standard format
> message and passes it down the stack of modules until it finds one
> which understands it. Analogously, perl could take a method call
> $stream->attron($something) (or $stream->ioctl($something)) and
> walk down the stack of disciplines (either explicitly or via some
> previously set-up inheritance) until it comes across a discipline
> class that understands it.
It would have to be explicitly since a stream stack would have no
relationship with an inheritance hierarchy (and faking one would incur
the heavy cost of invalidating all the ISA caches).
> > > Curses could be a stackable discipline on top of ordinary filehandles.
> > > Those ioctls would be passed along the stack of discipline modules
> > > until it reached one that understood it (like STREAMS).
> >
> > Remember that sfio is a replacement for stdio and stdio doesn't include ioctl's.
>
> I realise that (I've been playing with sfio this afternoon) but the
> API that sfio exposes looks as though it could be perlified quite
> nicely and beefed up to be more general-purpose, as with the Curses
> example above.
I tend to take the view that sfio disciplines are best suited to what
you might use a | series | of | pipes for in unix, only this way they're
all in the same process. Curses don't seem to fit that model well.
I think it's a case of "just because you could doesn't make it a good idea".
> I don't see why SFIO shouldn't be used as a basis for a powerful
> streams(lowercase)/discipline API for perl. I also think such a
> thing would graft in quite nicely to the current perl internals,
> which is your next point.
I have to agree that it's an appealing idea in general.
> > SFIO would work behind the scenes, especially
> > given Larry's point that tie for filehandles might actually just be a
> > bless (and hence that method calls should act as the 'user interface'
> > to file handles).
> >
> > I suspect we'll just have a core SFIO functionality transparently
> > replacing the STDIO functionality perl currently uses and then have a
> > separate SFIO module as an interface to the more whizz-bang features.
>
> This last paragraph is sort of what I've been talking about.
> If sfio disciplines (plus a little bit more) can be implemented
> easily as classes written in perl, then there should be less pressure
> for those who want to add more and more fields to SVs/XPVIOs and so
> on to store state. The state can be offloaded to the discipline
> object and pushed onto the stream.
Interesting point.
> To begin with, the Sfio module could be solely an ordinary XSUB module
> with its own methods for I/O following the C names: $stream->sfprintf
> and so on. The two places where changes to the perl internals would be
> necessary to integrate it seamlessly would be (1) native perl I/O
> operators (print, printf and so on) which would have to map to the
> Sfio versions and (2) the XPVIO would have to be able to distinguish
> between stdio and sfio streams unless stdio was either dropped all
> in one go from the internals or else the compatibility-mode of sfio
> was used for the stdio in perl. I suspect that they would have to run
> in parallel for a while in order to be able to get good benchmarks of
> sfio performance compared to the perl built-in stdio speedups.
A key aim of the original sfio module work by Paul was to prove the
portability of sfio itself.
I'm glad you're thinking about binary compatibility since that likely
to prove to be a sticky issue. Many extensions link to system and
third-party libraries which have been linked against stdio. Even
dynamic libraries may have dependencies on the size of the FILE struct.
Since I've not seen Paul post recently I'll append a couple of his
last messages on the Sfio module (Feb 95). They're a handy reminder
that the path ahead may not be all that smooth.
Tim.
----- Begin Included Message -----
Date: Tue, 21 Feb 95 13:10:55 GMT
From: Paul Marquess <pmarquess@bfsec.bt.co.uk>
To: mbeattie@sable.ox.ac.uk
Subject: Re: Sfio: opinions wanted.
Cc: perl5-porters@africa.nicoh.com, pmarquess@bfsec.bt.co.uk
From: Malcolm Beattie <mbeattie@sable.ox.ac.uk>
>
> Sfio sounds like another good reason to implement SVs whose strings
> aren't allocated with malloc. The first good reason that I came across
> was mmap. It was nice to be able to do
> $foo = mmap(HUGEFILE, 0, $hugefilesize); # or some such syntax
> while ($foo =~ /some interesting pattern/g) { do_something() }
> The idea was to have a flag SVf_NOTMALLOC so that when the SV went away,
> the pointer wasn't freed. I didn't address the problem of reallocating
> the string (sv_grow) since that was called from all over the place and
> I seem to remember one or two other gotchas. If the patches aren't
> archived in perl5-porters, I'll try to dig them out: they weren't large.
> It might be as easy to do from scratch. I think that with such a flag and
> some extra magic types (for a generalised reallocate and free), both sfio
> and mmap can be done elegantly. There may well be other uses too.
I had forgotten that discussion till you mentioned it Malcolm.
ok, I've found your original posting on mmap. From the quick look at
what you have done it looks like you have only implemented a read only
buffer. Where there any later patches?
It certainly would make life simpler for Sfio to have an SV which
corresponded to a buffer not under the control of Perl. I *do* think
that this would be a useful feature for module writers in general, so I
think it needs to be given a bit of thought and done properly. Comments?
Things that Sfio (at least) needs
1. Given a pointer & a size, the ability to have an SV 'adopt' it.
2. As Malcolm says, internal support to prevent and any calls to
sv_grow or calling free. I did a quick grep on the Perl source and
there are over 30 places where SvGROW gets called - not too bad.
3. Internal support to make sure that a user cannot write off the end
of the buffer. I'm not sure if this would be caught by any changes
needed for sv_grow.
4. Optionally set the SV read-only. This should be straightforward.
My recollection is that although there is no support for read only
variables in the language (yet), the internal support is all there.
5. The ability to make an 'ordinary' SV have the same behaviour as
above. sfio allows you to specify the buffer to be used for i/o, so
it would be nice to have this type of SV exibit the same behaviour
as one created by 1.
Looking at your reply, Malcolm, I guess 2 & 3 could be dealt with in a
more general way by having magic support for realloc & free. Must have
another look at the magic section in perlguts :)
Can anyone think of any other features that would be required?
Paul
----- End Included Message -----
----- Begin Included Message -----
From: Paul Marquess <pmarquess@bfsec.bt.co.uk>
Subject: Sfio: opinions wanted.
To: perl5-porters@africa.nicoh.com
Date: Sun, 19 Feb 1995 15:00:22 +0000 (GMT)
Cc: Paul Marquess <pmarquess@bfsec.bt.co.uk>
Reply-To: pmarquess@bfsec.bt.co.uk
I didn't get much time to have a look at Sfio (i.e. the Perl module, as
opposed to sfio the package it interfaces to) this week, but things have
settled down enough for me to have another look at it.
I'm playing with disciplines just now & I'm trying to decide the best way
to represent the memory buffers that sfio uses all over the place.
Basically there are a lot of occasions where sfio expects or presents the
user with a pointer to an area of memory along with an associated size.
These areas of memory correspond to the buffers used by the package for
i/o. The user of the Sfio package will have to be able to
1. Create an area of memory which sfio can use for a buffer.
2. Access an area of memory that sfio has allocated itself.
3. Read from either types of buffer
4. Write to either types of buffer
First I just used the good old 'copy the complete buffer into a Perl scalar'
approach. Whilst this does work, it means a *lot* of copying goes on.
Next I thought about presenting the user with the pointer & size as is. They
can use unpack to get to the buffer, *but* as far as I can see pack cannot
write back to the same place. Is this correct? I might very well have been
looking too hard at the code, so if I have completely missed the obvious
perhaps one of you could point it out to me.
I promise not to scream too loud :)
My third idea was to implement a Memory class. This would allow the creation
of areas of memory in Perl via a constructor and would also allow the
pointer/size pairs which sfio presents the user with to be dealt with.
The things I like most about this approach are that
1. The memory can be presented to the user as the pointer/size pair and
either as a Perl scalar or as an array - given the appropriate ties.
2. The memory will only be copied if the user actually needs to.
3. The class can prevent writing off the end of the memory area. Given the
nature of the memory, it is very important not too stray out of bounds.
Possible downsides
1. Am I using a sledehammer to crack a nut?
2. The tie mechanism is a bit slow at the moment. This may or may not be
addressed in the future when Perl gets optimiseded. Currently then, it
remains to be seen if the Memory class is any faster than simply copying
buffers around.
Opinions?
Paul
----- End Included Message -----