develooper Front page | perl.perl5.porters | Postings from February 2003

Re: New SV Flag

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
February 7, 2003 00:58
Subject:
Re: New SV Flag
Message ID:
20030207095258.6E05.H.M.BRAND@hccnet.nl
On Thu 06 Feb 2003 15:07, "H.Merijn Brand" <h.m.brand@hccnet.nl> wrote:
> On Thu 06 Feb 2003 13:15, Tim Bunce <Tim.Bunce@pobox.com> wrote:
> > > I wonder if there is a way to do this with magic but I think no matter 
> > > what is done in the magic destructor, perl will continue to go on. 
> > > Basically I want a flag that says, sv_free, don't free this SV, call 
> > > the magic destructor and then don't do anything more.
> > 
> > sv_free does:
> > 
> >     ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));
> 
> I did propose a patch to the magicians to weed out ATOMIC_INC and
> ATOMIC_DEC_AND_TEST as by Arthur and Nick's request. Where did it go?

Found it:

--- sv.c        2003-01-07 11:34:01.000000000 +0100
+++ sv.c.new    2003-01-10 15:16:45.000000000 +0100
@@ -5378,7 +5378,7 @@ SV *
 Perl_sv_newref(pTHX_ SV *sv)
 {
     if (sv)
-       ATOMIC_INC(SvREFCNT(sv));
+       (SvREFCNT(sv))++;
     return sv;
 }

@@ -5396,8 +5396,6 @@ Normally called via a wrapper macro C<Sv
 void
 Perl_sv_free(pTHX_ SV *sv)
 {
-    int refcount_is_zero;
-
     if (!sv)
        return;
     if (SvREFCNT(sv) == 0) {
@@ -5416,8 +5414,7 @@ Perl_sv_free(pTHX_ SV *sv)
            Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "Attempt to free unreferenced scalar");
        return;
     }
-    ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));
-    if (!refcount_is_zero)
+    if (--(SvREFCNT(sv)) > 0)
        return;
 #ifdef DEBUGGING
     if (SvTEMP(sv)) {
--- sv.h        2003-01-04 01:59:18.000000000 +0100
+++ sv.h.new    2003-01-10 15:14:05.000000000 +0100
@@ -125,20 +125,17 @@ perform the upgrade if necessary.  See C
 #define SvFLAGS(sv)    (sv)->sv_flags
 #define SvREFCNT(sv)   (sv)->sv_refcnt

-#define ATOMIC_INC(count) (++count)
-#define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
-
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
 #  define SvREFCNT_inc(sv)             \
     ({                                 \
        SV *nsv = (SV*)(sv);            \
        if (nsv)                        \
-            ATOMIC_INC(SvREFCNT(nsv)); \
+            (SvREFCNT(nsv))++; \
        nsv;                            \
     })
 #else
 #  define SvREFCNT_inc(sv)     \
-       ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
+       ((PL_Sv=(SV*)(sv)), (PL_Sv && ++(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
 #endif

 #define SvREFCNT_dec(sv)       sv_free((SV*)(sv))

-- 
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using perl-5.6.1, 5.8.0 & 633 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
  WinNT 4, Win2K pro & WinCE 2.11.  Smoking perl CORE: smokers@perl.org
http://archives.develooper.com/daily-build@perl.org/   perl-qa@perl.org
send smoke reports to: smokers-reports@perl.org, QA: http://qa.perl.org



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