Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55dc26c

Browse files
committed
Fold some long lines.
Change fatal errors during module initialization into RuntimeErrors.
1 parent dcfdceb commit 55dc26c

1 file changed

Lines changed: 31 additions & 14 deletions

File tree

Modules/_iconv_codec.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ iconvcodec_encode(iconvcodecObject *self, PyObject *args, PyObject *kwargs)
144144
}
145145

146146
while (inplen > 0) {
147-
if (iconv(self->enchdl, (char**)&inp, &inplen, &out, &outlen) == (size_t)-1) {
147+
if (iconv(self->enchdl, (char**)&inp, &inplen, &out, &outlen)
148+
== (size_t)-1)
149+
{
148150
char reason[128];
149151
int errpos;
150152

@@ -247,8 +249,9 @@ errorexit_cbpad: Py_XDECREF(retobj);
247249
if (newpos < 0)
248250
newpos = inputlen + newpos;
249251
if (newpos < 0 || newpos > inputlen) {
250-
PyErr_Format(PyExc_IndexError, "position %ld from error handler"
251-
" out of bounds", newpos);
252+
PyErr_Format(PyExc_IndexError,
253+
"position %ld from error handler out of bounds",
254+
newpos);
252255
goto errorexit;
253256
}
254257
if (newpos == inputlen)
@@ -476,8 +479,9 @@ errorexit_cbpad: Py_DECREF(retobj);
476479
if (newpos < 0)
477480
newpos = inplen_total + newpos;
478481
if (newpos < 0 || newpos > inplen_total) {
479-
PyErr_Format(PyExc_IndexError, "position %ld from error handler"
480-
" out of bounds", newpos);
482+
PyErr_Format(PyExc_IndexError,
483+
"position %ld from error handler out of bounds",
484+
newpos);
481485
goto errorexit;
482486
}
483487
if (newpos == inplen_total)
@@ -496,7 +500,8 @@ errorexit_cbpad: Py_DECREF(retobj);
496500

497501
finalsize = (int)(out - out_top);
498502
if (finalsize != outlen_total) {
499-
if (PyUnicode_Resize(&outputobj, finalsize / Py_UNICODE_SIZE) == -1)
503+
if (PyUnicode_Resize(&outputobj, finalsize / Py_UNICODE_SIZE)
504+
== -1)
500505
goto errorexit;
501506
}
502507

@@ -668,14 +673,21 @@ init_iconv_codec(void)
668673

669674
iconv_t hdl = iconv_open(UNICODE_ENCODING, "ASCII");
670675

671-
if (hdl == (iconv_t)-1)
672-
Py_FatalError("can't initialize the _iconv_codec module: iconv_open() failed");
676+
if (hdl == (iconv_t)-1) {
677+
PyErr_SetString(PyExc_RuntimeError,
678+
"can't initialize the _iconv_codec module: iconv_open() failed");
679+
return;
680+
}
673681

674682
res = iconv(hdl, &inptr, &insize, &outptr, &outsize);
675-
if (res == (size_t)-1)
676-
Py_FatalError("can't initialize the _iconv_codec module: iconv() failed");
683+
if (res == (size_t)-1) {
684+
PyErr_SetString(PyExc_RuntimeError,
685+
"can't initialize the _iconv_codec module: iconv() failed");
686+
return;
687+
}
677688

678-
/* Check whether conv() returned native endianess or not for the chosen encoding */
689+
/* Check whether conv() returned native endianess or not for the chosen
690+
encoding */
679691
if (out == 0x1)
680692
byteswap = 0;
681693
#if Py_UNICODE_SIZE == 2
@@ -684,8 +696,12 @@ init_iconv_codec(void)
684696
else if (out == 0x01000000)
685697
#endif
686698
byteswap = 1;
687-
else
688-
Py_FatalError("can't initialize the _iconv_codec module: mixed endianess");
699+
else {
700+
iconv_close(hdl);
701+
PyErr_SetString(PyExc_RuntimeError,
702+
"can't initialize the _iconv_codec module: mixed endianess");
703+
return;
704+
}
689705
iconv_close(hdl);
690706

691707
iconvcodec_Type.ob_type = &PyType_Type;
@@ -697,7 +713,8 @@ init_iconv_codec(void)
697713
PyModule_AddStringConstant(m, "internal_encoding", UNICODE_ENCODING);
698714

699715
if (PyErr_Occurred())
700-
Py_FatalError("can't initialize the _iconv_codec module");
716+
PyErr_SetString(PyExc_RuntimeError,
717+
"can't initialize the _iconv_codec module");
701718
}
702719

703720
/*

0 commit comments

Comments
 (0)