@@ -1241,50 +1241,53 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
12411241 "prec" , "rounding" , "Emin" , "Emax" , "capitals" , "clamp" ,
12421242 "flags" , "traps" , NULL
12431243 };
1244- PyObject * rounding = NULL ;
1245- PyObject * traps = NULL ;
1246- PyObject * status = NULL ;
1247- mpd_context_t * ctx , t ;
1248- int capitals = 1 ;
1244+ PyObject * prec = Py_None ;
1245+ PyObject * rounding = Py_None ;
1246+ PyObject * emin = Py_None ;
1247+ PyObject * emax = Py_None ;
1248+ PyObject * capitals = Py_None ;
1249+ PyObject * clamp = Py_None ;
1250+ PyObject * status = Py_None ;
1251+ PyObject * traps = Py_None ;
12491252 int ret ;
12501253
12511254 assert (PyTuple_Check (args ));
1252- ctx = CTX (self );
12531255
1254- t = * ctx ;
12551256 if (!PyArg_ParseTupleAndKeywords (
12561257 args , kwds ,
1257- "|nOnniiOO" , kwlist ,
1258- & t .prec , & rounding , & t .emin , & t .emax , & capitals , & t .clamp ,
1259- & status , & traps
1258+ "|OOOOOOOO" , kwlist ,
1259+ & prec , & rounding , & emin , & emax , & capitals , & clamp , & status , & traps
12601260 )) {
12611261 return -1 ;
12621262 }
1263- if (rounding != NULL ) {
1264- t .round = getround (rounding );
1265- if (t .round < 0 ) {
1266- return -1 ;
1267- }
1268- }
12691263
1270- if (! mpd_qsetprec ( ctx , t . prec ) ||
1271- ! mpd_qsetemin ( ctx , t . emin ) ||
1272- ! mpd_qsetemax ( ctx , t . emax ) ||
1273- ! mpd_qsetclamp ( ctx , t . clamp ) ) {
1274- return value_error_int ( "invalid context" ) ;
1264+ if (prec != Py_None && context_setprec ( self , prec , NULL ) < 0 ) {
1265+ return -1 ;
1266+ }
1267+ if ( emin != Py_None && context_setemin ( self , emin , NULL ) < 0 ) {
1268+ return -1 ;
12751269 }
1276- if (!mpd_qsetround (ctx , t .round ) ||
1277- !mpd_qsettraps (ctx , t .traps ) ||
1278- !mpd_qsetstatus (ctx , t .status )) {
1279- return type_error_int ("invalid context" );
1270+ if (emax != Py_None && context_setemax (self , emax , NULL ) < 0 ) {
1271+ return -1 ;
1272+ }
1273+ if (capitals != Py_None && context_setcapitals (self , capitals , NULL ) < 0 ) {
1274+ return -1 ;
1275+ }
1276+ if (clamp != Py_None && context_setclamp (self , clamp , NULL ) < 0 ) {
1277+ return -1 ;
12801278 }
12811279
1282- if (capitals != 0 && capitals != 1 ) {
1283- return value_error_int ("invalid context" );
1280+ if (rounding != Py_None ) {
1281+ int x = getround (rounding );
1282+ if (x < 0 ) {
1283+ return -1 ;
1284+ }
1285+ if (!mpd_qsetround (CTX (self ), x )) {
1286+ return type_error_int (invalid_rounding_err );
1287+ }
12841288 }
1285- CtxCaps (self ) = capitals ;
12861289
1287- if (traps != NULL ) {
1290+ if (traps != Py_None ) {
12881291 if (PyList_Check (traps )) {
12891292 ret = context_settraps_list (self , traps );
12901293 }
@@ -1300,7 +1303,7 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
13001303 return ret ;
13011304 }
13021305 }
1303- if (status != NULL ) {
1306+ if (status != Py_None ) {
13041307 if (PyList_Check (status )) {
13051308 ret = context_setstatus_list (self , status );
13061309 }
0 commit comments