[pypy-commit] pypy py3.5-time: removed leak, simplified (removed invisfields, not needed)

plan_rich pypy.commits at gmail.com
Tue Jan 3 09:57:56 EST 2017


Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-time
Changeset: r89336:6498ac1ab56d
Date: 2017-01-03 15:57 +0100
http://bitbucket.org/pypy/pypy/changeset/6498ac1ab56d/

Log:	removed leak, simplified (removed invisfields, not needed)

diff --git a/lib_pypy/_structseq.py b/lib_pypy/_structseq.py
--- a/lib_pypy/_structseq.py
+++ b/lib_pypy/_structseq.py
@@ -50,14 +50,6 @@
         if 'n_sequence_fields' in dict:
             n_sequence_fields = dict['n_sequence_fields']
             extra_fields = extra_fields[n_sequence_fields:]
-            seq = n_sequence_fields
-            # pop all fields that are still in sequence!
-            while extra_fields and extra_fields[0][0] == seq:
-                field = extra_fields[0][1]
-                field.index = None
-                invis_fields.append(field)
-                extra_fields.pop(0)
-                seq += 1
         else:
             while extra_fields and extra_fields[0][0] == n_sequence_fields:
                 extra_fields.pop(0)
@@ -72,7 +64,6 @@
 
         assert '__new__' not in dict
         dict['_extra_fields'] = tuple(extra_fields)
-        dict['_invis_fields'] = tuple(invis_fields)
         dict['__new__'] = structseq_new
         dict['__reduce__'] = structseq_reduce
         dict['__setattr__'] = structseq_setattr
@@ -106,12 +97,7 @@
                 msg = "exactly"
             raise TypeError("expected a sequence with %s %d items. has %d" \
                             % (msg, real_count, length))
-        for field, value in zip(cls._invis_fields, sequence[visible_count:real_count]):
-            name = field.__name__
-            if name in dict:
-                raise TypeError("duplicate value for %r" % (name,))
-            dict[name] = value
-        for field, value in zip(cls._extra_fields, sequence[real_count:]):
+        for field, value in zip(cls._extra_fields, sequence[visible_count:]):
             name = field.__name__
             if name in dict:
                 raise TypeError("duplicate value for %r" % (name,))
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -237,6 +237,7 @@
                  (HAS_CLOCK_GETTIME and (HAS_CLOCK_HIGHRES or HAS_CLOCK_MONOTONIC)))
 tm = cConfig.tm
 glob_buf = lltype.malloc(tm, flavor='raw', zero=True, immortal=True)
+glob_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
 
 if _WIN:
     _GetSystemTimeAsFileTime = rwin32.winexternal('GetSystemTimeAsFileTime',
@@ -602,9 +603,15 @@
     rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
     if HAS_TM_ZONE :
         if len(tup_w) >= 10:
-            # XXX str2charp leaks the object
+            # NOTE this is not cleanly solved, the global variable glob_tm_zone
+            # saves the string that is later deleted when this function is called again
+            # an refactoring of this module could remove this
             tm_zone = encode_utf8(space, space.unicode_w(tup_w[9]), allow_surrogates=True)
-            glob_buf.c_tm_zone = rffi.str2charp(tm_zone, track_allocation=False)
+            malloced_str = rffi.str2charp(tm_zone, track_allocation=False)
+            if glob_tm_zone != lltype.nullptr(rffi.CCHARP.TO):
+                rffi.freecharp(glob_tm_zone, track_allocation=False)
+            glob_tm_zone = malloced_str
+            glob_buf.c_tm_zone = malloced_str
         if len(tup_w) >= 11:
             rffi.setintfield(glob_buf, 'c_tm_gmtoff', space.c_int_w(tup_w[10]))
 


More information about the pypy-commit mailing list