mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
- Modernize code to use Py_ssize_t more intensively.
- Do some minor code clean-ups.
This commit is contained in:
parent
ad9afcf213
commit
4b96c1384e
18 changed files with 131 additions and 168 deletions
|
@ -2,7 +2,6 @@
|
|||
* _codecs_iso2022.c: Codecs collection for ISO-2022 encodings.
|
||||
*
|
||||
* Written by Hye-Shik Chang <perky@FreeBSD.org>
|
||||
* $CJKCodecs: _codecs_iso2022.c,v 1.22 2004/08/19 17:08:13 perky Exp $
|
||||
*/
|
||||
|
||||
#define USING_IMPORTED_MAPS
|
||||
|
@ -104,7 +103,7 @@
|
|||
|
||||
typedef int (*iso2022_init_func)(void);
|
||||
typedef ucs4_t (*iso2022_decode_func)(const unsigned char *data);
|
||||
typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, int *length);
|
||||
typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, Py_ssize_t *length);
|
||||
|
||||
struct iso2022_designation {
|
||||
unsigned char mark;
|
||||
|
@ -160,7 +159,7 @@ ENCODER(iso2022)
|
|||
const struct iso2022_designation *dsg;
|
||||
DBCHAR encoded;
|
||||
ucs4_t c = **inbuf;
|
||||
int insize;
|
||||
Py_ssize_t insize;
|
||||
|
||||
if (c < 0x80) {
|
||||
if (STATE_G0 != CHARSET_ASCII) {
|
||||
|
@ -183,7 +182,7 @@ ENCODER(iso2022)
|
|||
|
||||
encoded = MAP_UNMAPPABLE;
|
||||
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
|
||||
int length = 1;
|
||||
Py_ssize_t length = 1;
|
||||
encoded = dsg->encoder(&c, &length);
|
||||
if (encoded == MAP_MULTIPLE_AVAIL) {
|
||||
/* this implementation won't work for pair
|
||||
|
@ -300,12 +299,12 @@ DECODER_RESET(iso2022)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static Py_ssize_t
|
||||
iso2022processesc(const void *config, MultibyteCodec_State *state,
|
||||
const unsigned char **inbuf, size_t *inleft)
|
||||
const unsigned char **inbuf, Py_ssize_t *inleft)
|
||||
{
|
||||
unsigned char charset, designation;
|
||||
size_t i, esclen;
|
||||
Py_ssize_t i, esclen;
|
||||
|
||||
for (i = 1;i < MAX_ESCSEQLEN;i++) {
|
||||
if (i >= *inleft)
|
||||
|
@ -388,10 +387,10 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
|
|||
else if ((c) == 0xa2) (assi) = 0x2019; \
|
||||
else if ((c) == 0xaf) (assi) = 0x2015;
|
||||
|
||||
static int
|
||||
static Py_ssize_t
|
||||
iso2022processg2(const void *config, MultibyteCodec_State *state,
|
||||
const unsigned char **inbuf, size_t *inleft,
|
||||
Py_UNICODE **outbuf, size_t *outleft)
|
||||
const unsigned char **inbuf, Py_ssize_t *inleft,
|
||||
Py_UNICODE **outbuf, Py_ssize_t *outleft)
|
||||
{
|
||||
/* not written to use encoder, decoder functions because only few
|
||||
* encodings use G2 designations in CJKCodecs */
|
||||
|
@ -425,7 +424,7 @@ DECODER(iso2022)
|
|||
|
||||
while (inleft > 0) {
|
||||
unsigned char c = IN1;
|
||||
int err;
|
||||
Py_ssize_t err;
|
||||
|
||||
if (STATE_GETFLAG(F_ESCTHROUGHOUT)) {
|
||||
/* ESC throughout mode:
|
||||
|
@ -589,7 +588,7 @@ ksx1001_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
ksx1001_encoder(const ucs4_t *data, int *length)
|
||||
ksx1001_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
assert(*length == 1);
|
||||
|
@ -625,7 +624,7 @@ jisx0208_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0208_encoder(const ucs4_t *data, int *length)
|
||||
jisx0208_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
assert(*length == 1);
|
||||
|
@ -662,7 +661,7 @@ jisx0212_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0212_encoder(const ucs4_t *data, int *length)
|
||||
jisx0212_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
assert(*length == 1);
|
||||
|
@ -760,7 +759,7 @@ jisx0213_2004_2_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_encoder(const ucs4_t *data, int *length, void *config)
|
||||
jisx0213_encoder(const ucs4_t *data, Py_ssize_t *length, void *config)
|
||||
{
|
||||
DBCHAR coded;
|
||||
|
||||
|
@ -814,7 +813,7 @@ jisx0213_encoder(const ucs4_t *data, int *length, void *config)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
|
||||
jisx0213_2000_1_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
|
||||
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
||||
|
@ -826,10 +825,10 @@ jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
|
||||
jisx0213_2000_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
int ilength = *length;
|
||||
Py_ssize_t ilength = *length;
|
||||
|
||||
coded = jisx0213_encoder(data, length, (void *)2000);
|
||||
switch (ilength) {
|
||||
|
@ -849,7 +848,7 @@ jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
|
||||
jisx0213_2000_2_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
|
||||
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
||||
|
@ -861,7 +860,7 @@ jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
|
||||
jisx0213_2004_1_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded = jisx0213_encoder(data, length, NULL);
|
||||
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
||||
|
@ -873,10 +872,10 @@ jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
|
||||
jisx0213_2004_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
int ilength = *length;
|
||||
Py_ssize_t ilength = *length;
|
||||
|
||||
coded = jisx0213_encoder(data, length, NULL);
|
||||
switch (ilength) {
|
||||
|
@ -896,7 +895,7 @@ jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0213_2004_2_encoder(const ucs4_t *data, int *length)
|
||||
jisx0213_2004_2_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded = jisx0213_encoder(data, length, NULL);
|
||||
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
||||
|
@ -917,7 +916,7 @@ jisx0201_r_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0201_r_encoder(const ucs4_t *data, int *length)
|
||||
jisx0201_r_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
JISX0201_R_ENCODE(*data, coded)
|
||||
|
@ -935,7 +934,7 @@ jisx0201_k_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
jisx0201_k_encoder(const ucs4_t *data, int *length)
|
||||
jisx0201_k_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
JISX0201_K_ENCODE(*data, coded)
|
||||
|
@ -967,7 +966,7 @@ gb2312_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
gb2312_encoder(const ucs4_t *data, int *length)
|
||||
gb2312_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
DBCHAR coded;
|
||||
assert(*length == 1);
|
||||
|
@ -986,7 +985,7 @@ dummy_decoder(const unsigned char *data)
|
|||
}
|
||||
|
||||
static DBCHAR
|
||||
dummy_encoder(const ucs4_t *data, int *length)
|
||||
dummy_encoder(const ucs4_t *data, Py_ssize_t *length)
|
||||
{
|
||||
return MAP_UNMAPPABLE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue