develooper Front page | perl.perl5.porters | Postings from August 2011

Re: IN SEARCH OF: The definitive treatise on the "private" OK flags (SVp*OK)

Thread Previous | Thread Next
From:
Chip Salzenberg
Date:
August 12, 2011 21:51
Subject:
Re: IN SEARCH OF: The definitive treatise on the "private" OK flags (SVp*OK)
Message ID:
CANSL5VEKePRiQFpugujJs_nYhMO7OhRto8bpd=fRvWZ81JPifw@mail.gmail.com
On Fri, Aug 12, 2011 at 9:20 PM, Chip Salzenberg <rev.chip@gmail.com> wrote:
> /me lights the Tim Toady Signal
> (I don't think this bug goes back that far, but I want to understand the design principles involved)

Turns out it does go back that far.  But in this diving, I confess
I've gained a measure of empathy for Larry's plaintive cry: "What have
you done to my program?!"

First, the earliest ancestor of mg_get() did not play with the OK flags.
This is 5.0 alpha 2, and oh how simple it all started:

79072805 (Larry Wall 1993-10-07 23:00:00 +0000  14) int
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  15) mg_get(sv)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  16) SV* sv;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  17) {
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  18)     MAGIC* mg;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  19)     for (mg =
SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  20)     MGVTBL* vtbl =
mg->mg_virtual;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  21)     if (vtbl &&
vtbl->svt_get)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  22)
(*vtbl->svt_get)(sv, mg);
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  23)     }
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  24)     return 0;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000  25) }

A subsequent revision introduced the first public/private flag games.
Here is 5.0 alpha 4 (463ee0b2):

79072805 (Larry Wall 1993-10-07 23:00:00 +0000   14) int
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   15) mg_get(sv)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   16) SV* sv;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   17) {
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   18)     MAGIC* mg;
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   19)
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   20)     SvMAGICAL_off(sv);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   21)     SvFLAGS(sv)
&= ~(SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   22)     SvFLAGS(sv)
|= SvPRIVATE(sv) & (SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   23)     SvPRIVATE(sv)
&= ~(SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   24)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   25)     for (mg =
SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   26)    MGVTBL* vtbl =
mg->mg_virtual;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   27)    if (vtbl &&
vtbl->svt_get)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   28)
(*vtbl->svt_get)(sv, mg);
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   29)     }
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   30)
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   31)     SvMAGICAL_on(sv);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   32)     SvPRIVATE(sv)
&= ~(SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   33)     SvPRIVATE(sv)
|= SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   34)     SvFLAGS(sv)
&= ~(SVf_IOK|SVf_NOK|SVf_POK);
463ee0b2 (Larry Wall 1993-11-10 00:00:00 +0000   35)
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   36)     return 0;
79072805 (Larry Wall 1993-10-07 23:00:00 +0000   37) }

So even at this very early date, after mg_get() one could not depend
on having any meaningful OK flags.  And from this time the details may
have changed (a lot!), this aspect of the flags has remained constant.
 Which leaves the question still unanswered: How has this ever worked?

Thread Previous | Thread Next


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