develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
July 30, 2001 03:32
Subject:
Re: [PATCH for discussion] clamp, round #2
Message ID:
20010730103230.11518.1@bactrian.ni-s.u-net.com
Jeffrey Friedl <jfriedl@yahoo.com> writes:

The completeness of your patches is a joy, but IMHO:

while it is now using SvREADONLY it is _still_ adding 
the SVh_CLAMP_ACCESS flag which was what the SvREADONLY proposal 
was supposed to avoid.

Re-using SVp_SCREAM (has been studied) flag seems safe enough in theory,
but  we need to check that someplace else isn't already (ab)using it. 

It isn't clear why you rule out readonly/clamping tied hashes.

The \$HASH{KEY} issue "should" be solved by the READONLY-ness
being associated with the SV stored.

That is 
    \$Clamped{KEY}  # okay if KEY exists or is permitted, else winge 
    \$ReadOnly{KEY} # Complaint occurs iff code assigns via ref
                      due to readonlyness of the _value_.


The feature is useful, the implementation though is still not 
what I would like.

The implementation should IMHO:
 - Avoid new keywords.
 - Avoid using up additional flag bits.
 - Avoid slowing down hashes that are not so tagged
     - even the/my SvREADONLY possibly slows things a little,
       so it was suggested mg.c type "magic" be used for the marker.
 - Be mostly in a module.

I am also a little concerned about inventing another special "address".
Would not NULL suffice for "place holder"?

+#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no || (sv)==&PL_sv_placehold)

That could add "expensive" extra test to hot-ish code.


With the proposed \? prototype it should be possible to do 
all this with C-level magic - possibly by using a new magic type.


>--- bleedperl.orig/hv.h	Sun Jun 17 19:01:05 2001
>+++ bleedperl/hv.h	Sat Jul 28 21:14:52 2001
>@@ -31,7 +31,7 @@
>     char *	xhv_array;	/* pointer to malloced string */
>     STRLEN	xhv_fill;	/* how full xhv_array currently is */
>     STRLEN	xhv_max;	/* subscript of last element of xhv_array */
>-    IV		xhv_keys;	/* how many elements in the array */
>+    IV		xhv_realkeys;	/* elements in the array (excl placeholders) */
>     NV		xnv_nv;		/* numeric value, if any */
>     MAGIC*	xmg_magic;	/* magic for scalar array */
>     HV*		xmg_stash;	/* class package */
>@@ -40,6 +40,7 @@
>     HE		*xhv_eiter;	/* current entry of iterator */
>     PMOP	*xhv_pmroot;	/* list of pm's for this package */
>     char	*xhv_name;	/* name, if a symbol table */
>+    IV		xhv_keys;	/* elements in the array (incl placeholders) */
> };
> 
> /* hash a key */
>@@ -127,10 +128,15 @@
> #define HvFILL(hv)	((XPVHV*)  SvANY(hv))->xhv_fill
> #define HvMAX(hv)	((XPVHV*)  SvANY(hv))->xhv_max
> #define HvKEYS(hv)	((XPVHV*)  SvANY(hv))->xhv_keys
>+#define HvREALKEYS(hv)	((XPVHV*)  SvANY(hv))->xhv_realkeys
> #define HvRITER(hv)	((XPVHV*)  SvANY(hv))->xhv_riter
> #define HvEITER(hv)	((XPVHV*)  SvANY(hv))->xhv_eiter
> #define HvPMROOT(hv)	((XPVHV*)  SvANY(hv))->xhv_pmroot
> #define HvNAME(hv)	((XPVHV*)  SvANY(hv))->xhv_name
>+
>+#define HvCLAMPEDACCESS(hv)	(SvFLAGS(hv) &   SVh_CLAMP_ACCESS)
>+#define HvCLAMPEDACCESS_on(hv)	(SvFLAGS(hv) |=  SVh_CLAMP_ACCESS)
>+#define HvCLAMPEDACCESS_off(hv)	(SvFLAGS(hv) &= ~SVh_CLAMP_ACCESS)
> 
> #define HvSHAREKEYS(hv)		(SvFLAGS(hv) & SVphv_SHAREKEYS)
> #define HvSHAREKEYS_on(hv)	(SvFLAGS(hv) |= SVphv_SHAREKEYS)
>--- bleedperl.orig/intrpvar.h	Wed Jul 11 21:51:46 2001
>+++ bleedperl/intrpvar.h	Sat Jul 28 19:05:06 2001
>@@ -283,6 +283,9 @@
> PERLVAR(Isv_no,		SV)
> PERLVAR(Isv_yes,	SV)
> 
>+/* "approved" (but not exists()) keys in access-clamped hashes */
>+PERLVAR(Isv_placehold,	SV)
>+
> #ifdef CSH
> PERLVARI(Icshname,	char *,	CSH)
> PERLVAR(Icshlen,	I32)
>--- bleedperl.orig/sv.h	Sun Jul  8 17:03:52 2001
>+++ bleedperl/sv.h	Thu Jul 26 11:10:06 2001
>@@ -234,6 +234,8 @@
> 
> #define SVprv_WEAKREF   0x80000000      /* Weak reference */
> 
>+#define SVh_CLAMP_ACCESS 0x08000000	/* hash access has been clamped */
>+
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/


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