@@ -256,17 +256,13 @@ builtin_cmp(self, args)
256256}
257257
258258static object *
259- builtin_coerce (self , args )
260- object * self ;
261- object * args ;
262- {
259+ do_coerce (v , w )
263260 object * v , * w ;
261+ {
264262 object * res ;
265-
266- if (!newgetargs (args , "OO:coerce" , & v , & w ))
267- return NULL ;
268263 if (is_instanceobject (v ) || is_instanceobject (w ))
269- return instancebinop (v , w , "__coerce__" , "__rcoerce__" );
264+ return instancebinop (v , w , "__coerce__" , "__rcoerce__" ,
265+ do_coerce );
270266 if (coerce (& v , & w ) < 0 )
271267 return NULL ;
272268 res = mkvalue ("(OO)" , v , w );
@@ -275,6 +271,18 @@ builtin_coerce(self, args)
275271 return res ;
276272}
277273
274+ static object *
275+ builtin_coerce (self , args )
276+ object * self ;
277+ object * args ;
278+ {
279+ object * v , * w ;
280+
281+ if (!newgetargs (args , "OO:coerce" , & v , & w ))
282+ return NULL ;
283+ return do_coerce (v , w );
284+ }
285+
278286static object *
279287builtin_compile (self , args )
280288 object * self ;
@@ -336,16 +344,14 @@ builtin_dir(self, args)
336344}
337345
338346static object *
339- builtin_divmod (self , args )
340- object * self ;
341- object * args ;
347+ do_divmod (v , w )
348+ object * v , * w ;
342349{
343- object * v , * w , * x ;
350+ object * res ;
344351
345- if (!newgetargs (args , "OO:divmod" , & v , & w ))
346- return NULL ;
347352 if (is_instanceobject (v ) || is_instanceobject (w ))
348- return instancebinop (v , w , "__divmod__" , "__rdivmod__" );
353+ return instancebinop (v , w , "__divmod__" , "__rdivmod__" ,
354+ do_divmod );
349355 if (v -> ob_type -> tp_as_number == NULL ||
350356 w -> ob_type -> tp_as_number == NULL ) {
351357 err_setstr (TypeError ,
@@ -354,10 +360,22 @@ builtin_divmod(self, args)
354360 }
355361 if (coerce (& v , & w ) != 0 )
356362 return NULL ;
357- x = (* v -> ob_type -> tp_as_number -> nb_divmod )(v , w );
363+ res = (* v -> ob_type -> tp_as_number -> nb_divmod )(v , w );
358364 DECREF (v );
359365 DECREF (w );
360- return x ;
366+ return res ;
367+ }
368+
369+ static object *
370+ builtin_divmod (self , args )
371+ object * self ;
372+ object * args ;
373+ {
374+ object * v , * w ;
375+
376+ if (!newgetargs (args , "OO:divmod" , & v , & w ))
377+ return NULL ;
378+ return do_divmod (v , w );
361379}
362380
363381static object *
@@ -896,58 +914,68 @@ builtin_ord(self, args)
896914 return newintobject ((long )(c & 0xff ));
897915}
898916
917+ static object *
918+ do_pow (v , w )
919+ object * v , * w ;
920+ {
921+ object * res ;
922+ if (is_instanceobject (v ) || is_instanceobject (w ))
923+ return instancebinop (v , w , "__pow__" , "__rpow__" , do_pow );
924+ if (v -> ob_type -> tp_as_number == NULL ||
925+ w -> ob_type -> tp_as_number == NULL ) {
926+ err_setstr (TypeError , "pow() requires numeric arguments" );
927+ return NULL ;
928+ }
929+ if (coerce (& v , & w ) != 0 )
930+ return NULL ;
931+ res = (* v -> ob_type -> tp_as_number -> nb_power )(v , w , None );
932+ DECREF (v );
933+ DECREF (w );
934+ return res ;
935+ }
936+
899937static object *
900938builtin_pow (self , args )
901939 object * self ;
902940 object * args ;
903941{
904- object * v , * w , * z = None , * x ;
942+ object * v , * w , * z = None , * res ;
943+ object * v1 , * z1 , * w2 , * z2 ;
905944
906945 if (!newgetargs (args , "OO|O:pow" , & v , & w , & z ))
907946 return NULL ;
908- if (z == None ) {
909- if (is_instanceobject (v ) || is_instanceobject (w ))
910- return instancebinop (v , w , "__pow__" , "__rpow__" );
911- }
912- else {
913- /* XXX The ternary version doesn't do coercions */
914- if (is_instanceobject (v ))
915- return v -> ob_type -> tp_as_number -> nb_power (v , w , z );
916- }
947+ if (z == None )
948+ return do_pow (v , w );
949+ /* XXX The ternary version doesn't do class instance coercions */
950+ if (is_instanceobject (v ))
951+ return v -> ob_type -> tp_as_number -> nb_power (v , w , z );
917952 if (v -> ob_type -> tp_as_number == NULL ||
918- ( z != None && z -> ob_type -> tp_as_number == NULL ) ||
953+ z -> ob_type -> tp_as_number == NULL ||
919954 w -> ob_type -> tp_as_number == NULL ) {
920955 err_setstr (TypeError , "pow() requires numeric arguments" );
921956 return NULL ;
922957 }
923958 if (coerce (& v , & w ) != 0 )
924959 return NULL ;
925- if (z == None ) {
926- x = (* v -> ob_type -> tp_as_number -> nb_power )(v , w , z );
927- }
928- else {
929- object * v1 , * z1 , * w2 , * z2 ;
930- x = NULL ;
931- v1 = v ;
932- z1 = z ;
933- if (coerce (& v1 , & z1 ) != 0 )
934- goto error2 ;
935- w2 = w ;
936- z2 = z1 ;
937- if (coerce (& w2 , & z2 ) != 0 )
938- goto error1 ;
939- x = (* v1 -> ob_type -> tp_as_number -> nb_power )(v1 , w2 , z2 );
940- DECREF (w2 );
941- DECREF (z2 );
942- error1 :
943- DECREF (v1 );
944- DECREF (z1 );
945- error2 :
946- ;
947- }
960+ res = NULL ;
961+ v1 = v ;
962+ z1 = z ;
963+ if (coerce (& v1 , & z1 ) != 0 )
964+ goto error2 ;
965+ w2 = w ;
966+ z2 = z1 ;
967+ if (coerce (& w2 , & z2 ) != 0 )
968+ goto error1 ;
969+ res = (* v1 -> ob_type -> tp_as_number -> nb_power )(v1 , w2 , z2 );
970+ DECREF (w2 );
971+ DECREF (z2 );
972+ error1 :
973+ DECREF (v1 );
974+ DECREF (z1 );
975+ error2 :
948976 DECREF (v );
949977 DECREF (w );
950- return x ;
978+ return res ;
951979}
952980
953981static object *
0 commit comments