@@ -222,12 +222,11 @@ cdef class FaceIterator_base(SageObject):
222222
223223 sage: TestSuite( sage. geometry. polyhedron. combinatorial_polyhedron. face_iterator. FaceIterator) . run( )
224224 """
225+ # Note that all values are set to zero at the time ``__cinit__`` is called:
226+ # https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#initialisation-methods
227+ # In particular, ``__dealloc__`` will not do harm in this case.
228+
225229 cdef CombinatorialPolyhedron C
226- self .structure.atom_rep = NULL
227- self .structure.coatom_rep = NULL
228- self .structure.first_time = NULL
229- self .structure.new_faces = NULL
230- self .structure.visited_all = NULL
231230
232231 # Working around that __cinit__ of base and derived class must be the same,
233232 # as extension classes do not yet have __new__ in Cython 0.29.
@@ -305,26 +304,20 @@ cdef class FaceIterator_base(SageObject):
305304 # We may assume ``dimension > 0`` and ``n_faces > 0``.
306305
307306 # Initialize ``new_faces``.
308- # We modify ``self.structure.dimension`` to keep track how far we got with allocating, in case of error.
309- self .structure.new_faces = < face_list_t* > check_allocarray((self .structure.dimension), sizeof(face_list_t))
310- self .structure.dimension = 0
311- for i in range (C.dimension()):
307+ self .structure.new_faces = < face_list_t* > check_calloc((self .structure.dimension), sizeof(face_list_t))
308+ for i in range (self .structure.dimension):
312309 face_list_init(self .structure.new_faces[i],
313310 self .coatoms.n_faces(), self .coatoms.n_atoms(),
314311 self .coatoms.n_coatoms())
315- self .structure.dimension = i + 1
316- # Note that ``self.structure.dimension == C.dimension()`` in case we got until this point.
317312
318313 face_list_copy(self .structure.new_faces[self .structure.dimension- 1 ], self .coatoms.data)
319314
320315 # Initialize ``visited_all``.
321- self .structure.face_status = - 1
322- self .structure.visited_all = < face_list_t* > check_allocarray((self .structure.dimension), sizeof(face_list_t))
316+ self .structure.visited_all = < face_list_t* > check_calloc((self .structure.dimension), sizeof(face_list_t))
323317 face_list_shallow_init(self .structure.visited_all[self .structure.dimension- 1 ],
324318 self .coatoms.n_faces(), self .coatoms.n_atoms(),
325319 self .coatoms.n_coatoms())
326320 self .structure.visited_all[self .structure.dimension- 1 ].n_faces = 0
327- self .structure.face_status = 0
328321
329322 if not C.is_bounded():
330323 # Treating the far face as if we had visited all its elements.
@@ -355,13 +348,21 @@ cdef class FaceIterator_base(SageObject):
355348 self .structure.new_faces[self .structure.dimension - 1 ].polyhedron_is_simple = False
356349
357350 def __dealloc__ (self ):
351+ """
352+ TESTS::
353+
354+ sage: from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator import FaceIterator_base
355+ sage: FaceIterator_base(2) # indirect doctest
356+ Traceback (most recent call last):
357+ ...
358+ AttributeError: 'sage.rings.integer.Integer' object has no attribute 'combinatorial_polyhedron'
359+ """
358360 cdef int i
359361 sig_free(self .structure.atom_rep)
360362 sig_free(self .structure.coatom_rep)
361363 sig_free(self .structure.first_time)
362364 if self .structure.visited_all:
363- if self .structure.face_status != - 1 :
364- face_list_shallow_free(self .structure.visited_all[self .structure.dimension - 1 ])
365+ face_list_shallow_free(self .structure.visited_all[self .structure.dimension - 1 ])
365366 sig_free(self .structure.visited_all)
366367 if self .structure.new_faces:
367368 for i in range (self .structure.dimension):
0 commit comments