develooper Front page | perl.perl5.porters | Postings from June 2017

TONYC TPF Grant 9 report 2

From:
Tony Cook
Date:
June 23, 2017 01:28
Subject:
TONYC TPF Grant 9 report 2
Message ID:
20170623012827.GB26455@mars.tony.develop-help.com
[Hours]         [Activity]
2017/05/29      Monday
 1.32           #131221 debugging, research, work on a fix
 1.58           #131221 debugging, threads support
=====
 2.90

2017/05/30      Tuesday
 2.13           #131221 more threads support, debugging
 0.57           . in @INC follow-up for File::Fetch #11
 1.83           #131221 debugging
=====
 4.53

2017/05/31      Wednesday
 1.65           #131221 threads debugging, trying for a fix
 2.38           #131221 stumble into a fix, leak testing
=====
 4.03

2017/06/01      Thursday
 2.25           #131221 testing, writing regression tests
 1.80           #131221 more tests, testing, comment with patch
=====
 4.05

Which I calculate is 15.51 hours.

Approximately 2 issues were reviewed or worked on.

I spent nearly all of this week working on handle duplication bugs in
PerlIO::via [perl #131221].

PerlIO handles can be duplicated in two ways:

1) explicit duplication, using

  open $fh, ">&", $old_handle

  which is what the ticket originally reported.

2) duplication on thread creation.

For the first case, PerlIO calls the layer's Getarg entry point, which
PerlIO::via translates into a call to the (undocumented) GETARG
method.

I first thought this could be used as a workaround, but it turned to
be buggy - the result of the call to GETARG is a temporary, but the
callers to Getarg expect to own the SV returned, and either store it
or SvREFCNT_dec() the SV, resulting in a free of an unreferenced SV
one the next (nested) FREETMPS.  So I bumped the reference count.

To fix the base issue, if there's no GETARG method the PerlIO::via
Getargs handler now returns the class of the stored object.

To fix the thread cloning issue I used a similar mechanism used in
other layers: Getarg on a thread clone sets layer specific magic on a
new SV allocated to be the argument, and the Pushed handler
(PerlIOVia_pushed) skips any processing if the magic is found.

All of the cloning is then done in the Dup handler (PerlIOVia_dup).

I originally duplicated the file handle that PerlIO::Via creates to
pass into methods, but this handle is special - it's IO slot refers to
the next lower layer of the same handle that the Via layer works with,
duplicating it results in some double frees (unless you do what
PerlIOVia_method() already does.)

Due to that and since it's possible none of the methods will be called
in the new thread, I skipped duplicating the handle at all, leaving it
to PerlIOVia_method() to create a new handle if needed.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About