Skip to content

Commit d67ca54

Browse files
committed
Add braces for conditional statements and loops
1 parent 69a63a7 commit d67ca54

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

classwrapper.h

+20
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ namespace upywrap
220220
static mp_obj_t AsPyObj( T* p, bool own )
221221
{
222222
if( own )
223+
{
223224
return AsPyObj( native_obj_t( p ) );
225+
}
224226
return AsPyObj( native_obj_t( p, NoDelete ) );
225227
}
226228
#else
@@ -343,7 +345,9 @@ namespace upywrap
343345
{
344346
auto ret = map.find( attr );
345347
if( ret == map.end() )
348+
{
346349
return nullptr;
350+
}
347351
return ret->second;
348352
}
349353

@@ -352,7 +356,9 @@ namespace upywrap
352356
{
353357
const auto attrValue = FindAttrMaybe( map, attr );
354358
if( !attrValue )
359+
{
355360
RaiseAttributeException( type.name, attr );
361+
}
356362
return attrValue;
357363
}
358364

@@ -381,7 +387,9 @@ namespace upywrap
381387
this_type* self = (this_type*) self_in;
382388
const auto attrValue = FindAttrMaybe( self->getters, attr );
383389
if( attrValue )
390+
{
384391
*dest = attrValue->Call( self );
392+
}
385393
}
386394
}
387395

@@ -405,7 +413,9 @@ namespace upywrap
405413
auto self = (this_type*) self_in;
406414
auto other = (this_type*) other_in;
407415
if( op != MP_BINARY_OP_EQUAL )
416+
{
408417
return MP_OBJ_NULL; //not supported
418+
}
409419
return ToPy( self->GetPtr() == other->GetPtr() );
410420
}
411421

@@ -461,7 +471,9 @@ namespace upywrap
461471
static void CheckTypeIsRegistered()
462472
{
463473
if( type.base.type == nullptr )
474+
{
464475
RaiseTypeException( (std::string( "Native type " ) + typeid( T ).name() + " has not been registered").data() );
476+
}
465477
}
466478

467479
void AddFunctionToTable( const qstr name, mp_obj_t fun )
@@ -480,7 +492,9 @@ namespace upywrap
480492
typedef NativeMemberCall< name, Ret, A... > call_type;
481493
auto callerObject = call_type::CreateCaller( f );
482494
if( conv )
495+
{
483496
callerObject->convert_retval = conv;
497+
}
484498
functionPointers[ (void*) name ] = callerObject;
485499
AddFunctionToTable( name(), call_type::CreateUPyFunction() );
486500
}
@@ -626,7 +640,9 @@ namespace upywrap
626640
static mp_obj_t MakeNew( const mp_obj_type_t*, mp_uint_t n_args, mp_uint_t, const mp_obj_t *args )
627641
{
628642
if( n_args != sizeof...( A ) )
643+
{
629644
RaiseTypeException( "Wrong number of arguments for constructor" );
645+
}
630646
auto f = (init_call_type*) this_type::functionPointers[ (void*) index ];
631647
UPYWRAP_TRY
632648
return AsPyObj( native_obj_t( Apply( f, args, make_index_sequence< sizeof...( A ) >() ) ) );
@@ -644,7 +660,9 @@ namespace upywrap
644660
static mp_obj_t CallN( mp_uint_t n_args, const mp_obj_t* args )
645661
{
646662
if( n_args != sizeof...( A ) + 1 )
663+
{
647664
RaiseTypeException( "Wrong number of arguments" );
665+
}
648666
auto self = (this_type*) args[ 0 ];
649667
auto firstArg = &args[ 1 ];
650668
auto f = (call_type*) this_type::functionPointers[ (void*) index ];
@@ -791,7 +809,9 @@ namespace upywrap
791809
//Return None instead which is either useful (e.g. used as 'optional' return value),
792810
//or will lead to an actual Python exception when used anyway.
793811
if( !p )
812+
{
794813
return mp_const_none;
814+
}
795815
return ClassWrapper< T >::AsPyObj( std::move( p ) );
796816
}
797817
};

detail/callreturn.h

+4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace upywrap
2929
{
3030
UPYWRAP_TRY
3131
if( f->convert_retval )
32+
{
3233
return f->convert_retval( f->Call( FromPy< A >( args )... ) );
34+
}
3335
return ToPy( f->Call( FromPy< A >( args )... ) );
3436
UPYWRAP_CATCH
3537
}
@@ -39,7 +41,9 @@ namespace upywrap
3941
{
4042
UPYWRAP_TRY
4143
if( f->convert_retval )
44+
{
4245
return f->convert_retval( f->Call( self, FromPy< A >( args )... ) );
46+
}
4347
return ToPy( f->Call( self, FromPy< A >( args )... ) );
4448
UPYWRAP_CATCH
4549
}

detail/frompyobj.h

+12
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ namespace upywrap
8383
{
8484
mp_uint_t value;
8585
if( mpz_as_uint_checked( &self->mpz, &value ) )
86+
{
8687
return value;
88+
}
8789
RaiseOverflowException( "Value too large for integer" );
8890
#if !defined( _MSC_VER ) || defined( _DEBUG )
8991
return 0u;
@@ -162,23 +164,29 @@ namespace upywrap
162164

163165
auto i = &arg->mpz;
164166
if( !is_signed && i->neg )
167+
{
165168
RaiseTypeException( "Source integer must be unsigned" );
169+
}
166170

167171
auto d = i->dig + i->len;
168172
std::uint64_t val = 0;
169173

170174
while( d-- > i->dig )
171175
{
172176
if( val > maxCalcThreshold )
177+
{
173178
RaiseOverflowException( "Value too large for 64bit integer" );
179+
}
174180
val = ( val << MPZ_DIG_SIZE ) | *d;
175181
}
176182

177183
#ifdef _MSC_VER
178184
#pragma warning( disable : 4146 )
179185
#endif
180186
if( i->neg )
187+
{
181188
val = -val;
189+
}
182190
#ifdef _MSC_VER
183191
#pragma warning( default : 4146 )
184192
#endif
@@ -310,7 +318,9 @@ namespace upywrap
310318
mp_obj_t* items;
311319
mp_obj_get_array( arg, &len, &items );
312320
if( len != sizeof...( A ) )
321+
{
313322
RaiseTypeException( "Not enough tuple elements" );
323+
}
314324
return make_it( items, make_index_sequence< sizeof...( A ) >() );
315325
}
316326

@@ -398,7 +408,9 @@ namespace upywrap
398408
static std_fun_type Convert( mp_obj_t arg )
399409
{
400410
if( arg == mp_const_none )
411+
{
401412
return std_fun_type();
413+
}
402414
const auto obj = reinterpret_cast< mp_obj_base_t* >( MP_OBJ_TO_PTR( arg ) );
403415
const auto type = obj->type;
404416
if( type == &mp_type_fun_builtin_0 ||

detail/micropython.h

+22
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ namespace upywrap
131131
{
132132
mp_obj_exception_t* o = m_new_obj_var( mp_obj_exception_t, mp_obj_t, 0 );
133133
if( !o )
134+
{
134135
throw std::bad_alloc();
136+
}
135137
o->base.type = exc_type;
136138
o->traceback_data = nullptr;
137139
o->args = reinterpret_cast< mp_obj_tuple_t* >( MP_OBJ_TO_PTR( mp_obj_new_tuple( 1, nullptr ) ) );
@@ -223,14 +225,18 @@ namespace upywrap
223225
static void IntegerBoundCheck( S src )
224226
{
225227
if( abs_all< S, std::is_unsigned< S >::value >::abs( src ) > static_cast< S >( std::numeric_limits< T >::max() ) )
228+
{
226229
RaiseOverflowException( "Integer overflow" );
230+
}
227231
}
228232

229233
template< class T >
230234
static void PositiveIntegerCheck( T src )
231235
{
232236
if( src < 0 )
237+
{
233238
RaiseTypeException( "Source integer must be unsigned" );
239+
}
234240
}
235241

236242
template<>
@@ -342,21 +348,27 @@ namespace upywrap
342348

343349
static const size_t maxLen = 50;
344350
if( (*List())->len > maxLen )
351+
{
345352
RaiseRuntimeException( "StaticPyObjectStore: list is full" );
353+
}
346354
}
347355

348356
static void Remove( mp_obj_t obj )
349357
{
350358
if( !Contains( obj ) )
359+
{
351360
RaiseRuntimeException( "StaticPyObjectStore: item not added" );
361+
}
352362
mp_obj_list_remove( *List(), obj );
353363
}
354364

355365
static mp_obj_list_t* InitBackEnd()
356366
{
357367
auto list = List();
358368
if( *list )
369+
{
359370
RaiseRuntimeException( "StaticPyObjectStore: already initialized" );
371+
}
360372
*list = m_new_obj( mp_obj_list_t );
361373
mp_obj_list_init( *list, 0 );
362374
return *list;
@@ -372,13 +384,19 @@ namespace upywrap
372384
{
373385
const auto list = *List();
374386
if( !list )
387+
{
375388
RaiseRuntimeException( "StaticPyObjectStore: not initialized" );
389+
}
376390
size_t len;
377391
mp_obj_t* items;
378392
mp_obj_list_get( list, &len, &items );
379393
for( size_t i = 0 ; i < len ; ++i )
394+
{
380395
if( items[ i ] == obj )
396+
{
381397
return true;
398+
}
399+
}
382400
return false;
383401
}
384402

@@ -426,12 +444,16 @@ namespace upywrap
426444
const qstr qname = qstr_from_str( name );
427445
mp_obj_module_t* mod = (mp_obj_module_t*) mp_obj_new_module( qname );
428446
if( doRegister )
447+
{
429448
mp_module_register( qname, mod );
449+
}
430450
//Create StaticPyObjectStore instance and store it in the module's globals dict,
431451
//which ensures anything in the list will also not be sweeped by the GC.
432452
//Do this only once though, so all translation units in the binary use the same list.
433453
if( !StaticPyObjectStore::Initialized() )
454+
{
434455
mp_obj_dict_store( mod->globals, new_qstr( "_StaticPyObjectStore" ), StaticPyObjectStore::InitBackEnd() );
456+
}
435457
return mod;
436458
}
437459

functionwrapper.h

+4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ namespace upywrap
5353

5454
auto callerObject = call_type::CreateCaller( f );
5555
if( conv )
56+
{
5657
callerObject->convert_retval = conv;
58+
}
5759
functionPointers[ (void*) name ] = callerObject;
5860
mp_obj_dict_store( globals, new_qstr( name() ), call_type::CreateUPyFunction() );
5961
}
@@ -85,7 +87,9 @@ namespace upywrap
8587
static mp_obj_t CallN( mp_uint_t nargs, const mp_obj_t* args )
8688
{
8789
if( nargs != sizeof...( A ) )
90+
{
8891
RaiseTypeException( "Wrong number of arguments" );
92+
}
8993
auto f = (call_type*) FunctionWrapper::functionPointers[ (void*) index ];
9094
return CallVar( f, args, make_index_sequence< sizeof...( A ) >() );
9195
}

variable.h

+8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ namespace upywrap
3535
{
3636
const auto numNames = names.size();
3737
if( !numNames )
38+
{
3839
throw std::runtime_error( "cannot get variable without a name" );
40+
}
3941
auto var = GetVariable( names[ 0 ].data() );
4042
for( size_t i = 1 ; i < numNames ; ++i )
43+
{
4144
var = GetVariable( var, names[ i ].data() );
45+
}
4246
return var;
4347
}
4448

@@ -70,7 +74,9 @@ namespace upywrap
7074
{
7175
const auto numNames = names.size();
7276
if( !numNames )
77+
{
7378
throw std::runtime_error( "cannot get variable without a name" );
79+
}
7480
if( numNames == 1 )
7581
{
7682
SetVariable( value, names[ 0 ].data() );
@@ -79,7 +85,9 @@ namespace upywrap
7985
{
8086
auto var = GetVariable( names[ 0 ].data() );
8187
for( size_t i = 1 ; i < numNames - 1 ; ++i )
88+
{
8289
var = GetVariable( var, names[ i ].data() );
90+
}
8391
SetVariable( var, value, names[ numNames - 1 ].data() );
8492
}
8593
}

0 commit comments

Comments
 (0)