Skip to content

Commit 93223a2

Browse files
src: add appropriate coverage ignore on C++ code for Python type creation and memory allocation
Those branches cannot be meaningfully tested.
1 parent 82de3de commit 93223a2

File tree

13 files changed

+134
-129
lines changed

13 files changed

+134
-129
lines changed

atom/src/atomdict.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ PyObject* AtomDict_new( PyTypeObject* type, PyObject* args, PyObject* kwargs )
8484
cppy::ptr self( PyDict_Type.tp_new( type, args, kwargs ) );
8585
if( !self )
8686
{
87-
return 0;
87+
return 0; // LCOV_EXCL_LINE (failed instance creation)
8888
}
8989
atomdict_cast( self.get() )->pointer = new CAtomPointer();
9090
return self.release();
@@ -437,7 +437,7 @@ PyObject* DefaultAtomDict::New( CAtom* atom, Member* key_validator, Member* valu
437437
cppy::ptr self( PyDict_Type.tp_new( DefaultAtomDict::TypeObject, 0, 0 ) );
438438
if( !self )
439439
{
440-
return 0;
440+
return 0; // LCOV_EXCL_LINE (failed instance creation)
441441
}
442442
cppy::xincref( pyobject_cast( key_validator ) );
443443
atomdict_cast( self.get() )->m_key_validator = key_validator;
@@ -462,7 +462,7 @@ bool DefaultAtomDict::Ready()
462462
);
463463
if( !TypeObject )
464464
{
465-
return false;
465+
return false; // LCOV_EXCL_LINE (failed type creation)
466466
}
467467
return true;
468468
}

atom/src/atomlist.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace ListMethods
4141
if( strcmp( method->ml_name, name ) == 0 )
4242
return method->ml_meth;
4343
}
44-
return 0;
44+
return 0; // LCOV_EXCL_LINE (failed method lookup)
4545
}
4646

4747
static bool
@@ -84,17 +84,17 @@ ListSubtype_New( PyTypeObject* subtype, Py_ssize_t size )
8484
if( size < 0 )
8585
return cppy::system_error( "negative list size" );
8686
if( static_cast<size_t>( size ) > PY_SSIZE_T_MAX / sizeof( PyObject* ) )
87-
return PyErr_NoMemory(); // LCOV_EXCL_LINE
87+
return PyErr_NoMemory(); // LCOV_EXCL_LINE (memory error)
8888
cppy::ptr ptr( PyType_GenericNew( subtype, 0, 0 ) );
8989
if( !ptr )
90-
return 0;
90+
return 0; // LCOV_EXCL_LINE (failed instance creation)
9191
PyListObject* op = reinterpret_cast<PyListObject*>( ptr.get() );
9292
if( size > 0 )
9393
{
9494
size_t nbytes = size * sizeof( PyObject* );
9595
op->ob_item = reinterpret_cast<PyObject**>( PyMem_Malloc( nbytes ) );
9696
if( !op->ob_item )
97-
return PyErr_NoMemory(); // LCOV_EXCL_LINE
97+
return PyErr_NoMemory(); // LCOV_EXCL_LINE (memory error)
9898
memset( op->ob_item, 0, nbytes );
9999
}
100100
#if PY_VERSION_HEX >= 0x03090000
@@ -128,7 +128,7 @@ class AtomListHandler
128128
return 0;
129129
if( PyList_Append( m_list.get(), item.get() ) != 0 )
130130
{
131-
return 0;
131+
return 0; // LCOV_EXCL_LINE (failed append, impossible)
132132
}
133133
return cppy::incref( Py_None );
134134
}
@@ -144,7 +144,7 @@ class AtomListHandler
144144
return 0;
145145
if( PyList_Insert( m_list.get(), index, valptr.get() ) != 0)
146146
{
147-
return 0;
147+
return 0; // LCOV_EXCL_LINE (failed insert, impossible)
148148
}
149149
return cppy::incref( Py_None );
150150

@@ -272,7 +272,7 @@ AtomList_new( PyTypeObject* type, PyObject* args, PyObject* kwargs )
272272
cppy::ptr ptr( PyList_Type.tp_new( type, args, kwargs ) );
273273
if( !ptr )
274274
{
275-
return 0;
275+
return 0; // LCOV_EXCL_LINE (failed instance creation)
276276
}
277277
atomlist_cast( ptr.get() )->pointer = new CAtomPointer();
278278
return ptr.release();
@@ -439,13 +439,13 @@ AtomList::New( Py_ssize_t size, CAtom* atom, Member* validator )
439439
bool AtomList::Ready()
440440
{
441441
if( !ListMethods::init_methods() ) {
442-
return false;
442+
return false; // LCOV_EXCL_LINE (failed method lookup, impossible)
443443
}
444444
// The reference will be handled by the module to which we will add the type
445445
TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) );
446446
if( !TypeObject )
447447
{
448-
return false;
448+
return false; // LCOV_EXCL_LINE (failed type creation)
449449
}
450450
return true;
451451
}
@@ -497,122 +497,122 @@ init_containerlistchange()
497497
PySStr::typestr = PyUnicode_InternFromString( "type" );
498498
if( !PySStr::typestr )
499499
{
500-
return false;
500+
return false; // LCOV_EXCL_LINE (failed interned string creation)
501501
}
502502
PySStr::namestr = PyUnicode_InternFromString( "name" );
503503
if( !PySStr::namestr )
504504
{
505-
return false;
505+
return false; // LCOV_EXCL_LINE (failed interned string creation)
506506
}
507507
PySStr::objectstr = PyUnicode_InternFromString( "object" );
508508
if( !PySStr::objectstr )
509509
{
510-
return false;
510+
return false; // LCOV_EXCL_LINE (failed interned string creation)
511511
}
512512
PySStr::valuestr = PyUnicode_InternFromString( "value" );
513513
if( !PySStr::valuestr )
514514
{
515-
return false;
515+
return false; // LCOV_EXCL_LINE (failed interned string creation)
516516
}
517517
PySStr::operationstr = PyUnicode_InternFromString( "operation" );
518518
if( !PySStr::operationstr )
519519
{
520-
return false;
520+
return false; // LCOV_EXCL_LINE (failed interned string creation)
521521
}
522522
PySStr::itemstr = PyUnicode_InternFromString( "item" );
523523
if( !PySStr::itemstr )
524524
{
525-
return false;
525+
return false; // LCOV_EXCL_LINE (failed interned string creation)
526526
}
527527
PySStr::itemsstr = PyUnicode_InternFromString( "items" );
528528
if( !PySStr::itemsstr )
529529
{
530-
return false;
530+
return false; // LCOV_EXCL_LINE (failed interned string creation)
531531
}
532532
PySStr::indexstr = PyUnicode_InternFromString( "index" );
533533
if( !PySStr::indexstr )
534534
{
535-
return false;
535+
return false; // LCOV_EXCL_LINE (failed interned string creation)
536536
}
537537
PySStr::keystr = PyUnicode_InternFromString( "key" );
538538
if( !PySStr::keystr )
539539
{
540-
return false;
540+
return false; // LCOV_EXCL_LINE (failed interned string creation)
541541
}
542542
PySStr::reversestr = PyUnicode_InternFromString( "reverse" );
543543
if( !PySStr::reversestr )
544544
{
545-
return false;
545+
return false; // LCOV_EXCL_LINE (failed interned string creation)
546546
}
547547
PySStr::containerstr = PyUnicode_InternFromString( "container" );
548548
if( !PySStr::containerstr )
549549
{
550-
return false;
550+
return false; // LCOV_EXCL_LINE (failed interned string creation)
551551
}
552552
PySStr::__delitem__str = PyUnicode_InternFromString( "__delitem__" );
553553
if( !PySStr::typestr )
554554
{
555-
return false;
555+
return false; // LCOV_EXCL_LINE (failed interned string creation)
556556
}
557557
PySStr::__iadd__str = PyUnicode_InternFromString( "__iadd__" );
558558
if( !PySStr::__iadd__str )
559559
{
560-
return false;
560+
return false; // LCOV_EXCL_LINE (failed interned string creation)
561561
}
562562
PySStr::__imul__str = PyUnicode_InternFromString( "__imul__" );
563563
if( !PySStr::__imul__str )
564564
{
565-
return false;
565+
return false; // LCOV_EXCL_LINE (failed interned string creation)
566566
}
567567
PySStr::__setitem__str = PyUnicode_InternFromString( "__setitem__" );
568568
if( !PySStr::__setitem__str )
569569
{
570-
return false;
570+
return false; // LCOV_EXCL_LINE (failed interned string creation)
571571
}
572572
PySStr::appendstr = PyUnicode_InternFromString( "append" );
573573
if( !PySStr::appendstr )
574574
{
575-
return false;
575+
return false; // LCOV_EXCL_LINE (failed interned string creation)
576576
}
577577
PySStr::extendstr = PyUnicode_InternFromString( "extend" );
578578
if( !PySStr::extendstr )
579579
{
580-
return false;
580+
return false; // LCOV_EXCL_LINE (failed interned string creation)
581581
}
582582
PySStr::insertstr = PyUnicode_InternFromString( "insert" );
583583
if( !PySStr::insertstr )
584584
{
585-
return false;
585+
return false; // LCOV_EXCL_LINE (failed interned string creation)
586586
}
587587
PySStr::popstr = PyUnicode_InternFromString( "pop" );
588588
if( !PySStr::popstr )
589589
{
590-
return false;
590+
return false; // LCOV_EXCL_LINE (failed interned string creation)
591591
}
592592
PySStr::removestr = PyUnicode_InternFromString( "remove" );
593593
if( !PySStr::removestr )
594594
{
595-
return false;
595+
return false; // LCOV_EXCL_LINE (failed interned string creation)
596596
}
597597
PySStr::sortstr = PyUnicode_InternFromString( "sort" );
598598
if( !PySStr::sortstr )
599599
{
600-
return false;
600+
return false; // LCOV_EXCL_LINE (failed interned string creation)
601601
}
602602
PySStr::olditemstr = PyUnicode_InternFromString( "olditem" );
603603
if( !PySStr::olditemstr )
604604
{
605-
return false;
605+
return false; // LCOV_EXCL_LINE (failed interned string creation)
606606
}
607607
PySStr::newitemstr = PyUnicode_InternFromString( "newitem" );
608608
if( !PySStr::newitemstr )
609609
{
610-
return false;
610+
return false; // LCOV_EXCL_LINE (failed interned string creation)
611611
}
612612
PySStr::countstr = PyUnicode_InternFromString( "count" );
613613
if( !PySStr::countstr )
614614
{
615-
return false;
615+
return false; // LCOV_EXCL_LINE (failed interned string creation)
616616
}
617617
alloced = true;
618618
return true;
@@ -1205,15 +1205,15 @@ bool AtomCList::Ready()
12051205
// Ensure the parent type was created
12061206
if( !AtomList::TypeObject )
12071207
{
1208-
return false;
1208+
return false; // LCOV_EXCL_LINE (parent type not created, impossible)
12091209
}
12101210
AtomCList_Type_slots[0].pfunc = void_cast( AtomList::TypeObject );
12111211

12121212
// The reference will be handled by the module to which we will add the type
12131213
TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) );
12141214
if( !TypeObject )
12151215
{
1216-
return false;
1216+
return false; // LCOV_EXCL_LINE (failed type creation)
12171217
}
12181218
return true;
12191219
}

atom/src/atomref.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ bool AtomRef::Ready()
186186
TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) );
187187
if( !TypeObject )
188188
{
189-
return false;
189+
return false; // LCOV_EXCL_LINE (failed type init)
190190
}
191191
return true;
192192
}

atom/src/atomset.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ init_methods()
3131
update = PyObject_GetAttrString( pyobject_cast( &PySet_Type ), "update" );
3232
if( !update )
3333
{
34-
return false;
34+
return false; // LCOV_EXCL_LINE (failed to load set 'update' method, impossible)
3535
}
3636
return true;
3737
}
@@ -94,7 +94,7 @@ PyObject* AtomSet_new( PyTypeObject* type, PyObject* args, PyObject* kwargs )
9494
cppy::ptr self( PySet_Type.tp_new( type, args, kwargs ) );
9595
if( !self )
9696
{
97-
return 0;
97+
return 0; // LCOV_EXCL_LINE (failed instance creation)
9898
}
9999
atomset_cast( self.get() )->pointer = new CAtomPointer();
100100
return self.release();
@@ -330,7 +330,7 @@ PyObject* AtomSet::New( CAtom* atom, Member* validator )
330330
cppy::ptr self( PySet_Type.tp_new( AtomSet::TypeObject, 0, 0 ) );
331331
if( !self )
332332
{
333-
return 0;
333+
return 0; // LCOV_EXCL_LINE (failed instance creation)
334334
}
335335
cppy::xincref( pyobject_cast( validator ) );
336336
atomset_cast( self.get() )->m_value_validator = validator;
@@ -369,13 +369,13 @@ int AtomSet::Update( AtomSet* set, PyObject* value )
369369
bool AtomSet::Ready()
370370
{
371371
if( !SetMethods::init_methods() ) {
372-
return false;
372+
return false; // LCOV_EXCL_LINE (failed method lookup, impossible)
373373
}
374374
// The reference will be handled by the module to which we will add the type
375375
TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) );
376376
if( !TypeObject )
377377
{
378-
return false;
378+
return false; // LCOV_EXCL_LINE (failed type creation)
379379
}
380380
return true;
381381
}

atom/src/catom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,17 @@ bool CAtom::Ready()
561561
TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) );
562562
if( !TypeObject )
563563
{
564-
return false;
564+
return false; // LCOV_EXCL_LINE (failed type init)
565565
}
566566
atom_members = PyUnicode_InternFromString( "__atom_members__" );
567567
if( !atom_members )
568568
{
569-
return false;
569+
return false; // LCOV_EXCL_LINE (failed to intern string, impossible)
570570
}
571571

572572
atom_flags = PyUnicode_InternFromString( "--frozen" );
573573
if( !atom_flags )
574-
return false;
574+
return false; // LCOV_EXCL_LINE (failed to intern string, impossible)
575575

576576
return true;
577577
}

0 commit comments

Comments
 (0)