@@ -61,15 +61,22 @@ do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0)
61
61
#define JOIN_SET (p , flag ) ((void*) ((uintptr_t) (JOIN_OBJ(p)) | (flag)))
62
62
#define JOIN_OBJ (p ) ((PyObject*) ((uintptr_t) (p) & ~(uintptr_t)1))
63
63
64
+ /* Py_SETREF for a PyObject* that uses a join flag. */
65
+ Py_LOCAL_INLINE (void )
66
+ _set_joined_ptr (PyObject * * p , PyObject * new_joined_ptr )
67
+ {
68
+ PyObject * tmp = JOIN_OBJ (* p );
69
+ * p = new_joined_ptr ;
70
+ Py_DECREF (tmp );
71
+ }
72
+
64
73
/* Py_CLEAR for a PyObject* that uses a join flag. Pass the pointer by
65
74
* reference since this function sets it to NULL.
66
75
*/
67
76
static void _clear_joined_ptr (PyObject * * p )
68
77
{
69
78
if (* p ) {
70
- PyObject * tmp = JOIN_OBJ (* p );
71
- * p = NULL ;
72
- Py_DECREF (tmp );
79
+ _set_joined_ptr (p , NULL );
73
80
}
74
81
}
75
82
@@ -356,7 +363,6 @@ static int
356
363
element_init (PyObject * self , PyObject * args , PyObject * kwds )
357
364
{
358
365
PyObject * tag ;
359
- PyObject * tmp ;
360
366
PyObject * attrib = NULL ;
361
367
ElementObject * self_elem ;
362
368
@@ -397,15 +403,11 @@ element_init(PyObject *self, PyObject *args, PyObject *kwds)
397
403
Py_INCREF (tag );
398
404
Py_XSETREF (self_elem -> tag , tag );
399
405
400
- tmp = self_elem -> text ;
401
406
Py_INCREF (Py_None );
402
- self_elem -> text = Py_None ;
403
- Py_DECREF (JOIN_OBJ (tmp ));
407
+ _set_joined_ptr (& self_elem -> text , Py_None );
404
408
405
- tmp = self_elem -> tail ;
406
409
Py_INCREF (Py_None );
407
- self_elem -> tail = Py_None ;
408
- Py_DECREF (JOIN_OBJ (tmp ));
410
+ _set_joined_ptr (& self_elem -> tail , Py_None );
409
411
410
412
return 0 ;
411
413
}
@@ -675,12 +677,10 @@ _elementtree_Element_clear_impl(ElementObject *self)
675
677
dealloc_extra (self );
676
678
677
679
Py_INCREF (Py_None );
678
- Py_DECREF (JOIN_OBJ (self - > text ));
679
- self - > text = Py_None ;
680
+ _set_joined_ptr (& self - > text , Py_None );
680
681
681
682
Py_INCREF (Py_None );
682
- Py_DECREF (JOIN_OBJ (self - > tail ));
683
- self - > tail = Py_None ;
683
+ _set_joined_ptr (& self - > tail , Py_None );
684
684
685
685
Py_RETURN_NONE ;
686
686
}
@@ -702,13 +702,11 @@ _elementtree_Element___copy___impl(ElementObject *self)
702
702
if (!element )
703
703
return NULL;
704
704
705
- Py_DECREF (JOIN_OBJ (element - > text ));
706
- element - > text = self - > text ;
707
- Py_INCREF (JOIN_OBJ (element - > text ));
705
+ Py_INCREF (JOIN_OBJ (self - > text ));
706
+ _set_joined_ptr (& element - > text , self - > text );
708
707
709
- Py_DECREF (JOIN_OBJ (element - > tail ));
710
- element - > tail = self - > tail ;
711
- Py_INCREF (JOIN_OBJ (element - > tail ));
708
+ Py_INCREF (JOIN_OBJ (self -> tail ));
709
+ _set_joined_ptr (& element -> tail , self -> tail );
712
710
713
711
if (self -> extra ) {
714
712
if (element_resize (element , self -> extra -> length ) < 0 ) {
@@ -776,14 +774,12 @@ _elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo)
776
774
text = deepcopy (JOIN_OBJ (self -> text ), memo );
777
775
if (!text )
778
776
goto error ;
779
- Py_DECREF (element -> text );
780
- element -> text = JOIN_SET (text , JOIN_GET (self -> text ));
777
+ _set_joined_ptr (& element -> text , JOIN_SET (text , JOIN_GET (self -> text )));
781
778
782
779
tail = deepcopy (JOIN_OBJ (self -> tail ), memo );
783
780
if (!tail )
784
781
goto error ;
785
- Py_DECREF (element -> tail );
786
- element -> tail = JOIN_SET (tail , JOIN_GET (self -> tail ));
782
+ _set_joined_ptr (& element -> tail , JOIN_SET (tail , JOIN_GET (self -> tail )));
787
783
788
784
if (self -> extra ) {
789
785
if (element_resize (element , self -> extra -> length ) < 0 )
@@ -968,13 +964,13 @@ element_setstate_from_attributes(ElementObject *self,
968
964
Py_INCREF (tag );
969
965
Py_XSETREF (self -> tag , tag );
970
966
971
- _clear_joined_ptr ( & self -> text ) ;
972
- self -> text = text ? JOIN_SET ( text , PyList_CheckExact (text )) : Py_None ;
973
- Py_INCREF ( JOIN_OBJ ( self -> text ) );
967
+ text = text ? JOIN_SET ( text , PyList_CheckExact ( text )) : Py_None ;
968
+ Py_INCREF ( JOIN_OBJ (text ));
969
+ _set_joined_ptr ( & self -> text , text );
974
970
975
- _clear_joined_ptr ( & self -> tail ) ;
976
- self -> tail = tail ? JOIN_SET ( tail , PyList_CheckExact (tail )) : Py_None ;
977
- Py_INCREF ( JOIN_OBJ ( self -> tail ) );
971
+ tail = tail ? JOIN_SET ( tail , PyList_CheckExact ( tail )) : Py_None ;
972
+ Py_INCREF ( JOIN_OBJ (tail ));
973
+ _set_joined_ptr ( & self -> tail , tail );
978
974
979
975
/* Handle ATTRIB and CHILDREN. */
980
976
if (!children && !attrib )
@@ -2009,8 +2005,7 @@ element_text_setter(ElementObject *self, PyObject *value, void *closure)
2009
2005
{
2010
2006
_VALIDATE_ATTR_VALUE (value );
2011
2007
Py_INCREF (value );
2012
- Py_DECREF (JOIN_OBJ (self -> text ));
2013
- self -> text = value ;
2008
+ _set_joined_ptr (& self -> text , value );
2014
2009
return 0 ;
2015
2010
}
2016
2011
@@ -2019,8 +2014,7 @@ element_tail_setter(ElementObject *self, PyObject *value, void *closure)
2019
2014
{
2020
2015
_VALIDATE_ATTR_VALUE (value );
2021
2016
Py_INCREF (value );
2022
- Py_DECREF (JOIN_OBJ (self -> tail ));
2023
- self -> tail = value ;
2017
+ _set_joined_ptr (& self -> tail , value );
2024
2018
return 0 ;
2025
2019
}
2026
2020
0 commit comments