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

Skip to content

Commit 4b96c13

Browse files
committed
- Modernize code to use Py_ssize_t more intensively.
- Do some minor code clean-ups.
1 parent ad9afcf commit 4b96c13

18 files changed

Lines changed: 131 additions & 168 deletions

Modules/cjkcodecs/README

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
Notes on cjkcodecs
2-
-------------------
3-
This directory contains source files for cjkcodecs extension modules.
4-
They are based on CJKCodecs (http://cjkpython.i18n.org/#CJKCodecs)
5-
as of Aug 20 2004 currently.
6-
7-
8-
91
To generate or modify mapping headers
102
-------------------------------------
113
Mapping headers are imported from CJKCodecs as pre-generated form.

Modules/cjkcodecs/_codecs_cn.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_cn.c: Codecs collection for Mainland Chinese encodings
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_cn.c,v 1.8 2004/07/07 14:59:26 perky Exp $
65
*/
76

87
#include "cjkcodecs.h"

Modules/cjkcodecs/_codecs_hk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_hk.c: Codecs collection for encodings from Hong Kong
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_hk.c,v 1.4 2004/07/18 04:44:27 perky Exp $
65
*/
76

87
#define USING_IMPORTED_MAPS
@@ -32,7 +31,7 @@ ENCODER(big5hkscs)
3231
while (inleft > 0) {
3332
ucs4_t c = **inbuf;
3433
DBCHAR code;
35-
int insize;
34+
Py_ssize_t insize;
3635

3736
if (c < 0x80) {
3837
REQUIRE_OUTBUF(1)

Modules/cjkcodecs/_codecs_iso2022.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_iso2022.c: Codecs collection for ISO-2022 encodings.
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_iso2022.c,v 1.22 2004/08/19 17:08:13 perky Exp $
65
*/
76

87
#define USING_IMPORTED_MAPS
@@ -104,7 +103,7 @@
104103

105104
typedef int (*iso2022_init_func)(void);
106105
typedef ucs4_t (*iso2022_decode_func)(const unsigned char *data);
107-
typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, int *length);
106+
typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, Py_ssize_t *length);
108107

109108
struct iso2022_designation {
110109
unsigned char mark;
@@ -160,7 +159,7 @@ ENCODER(iso2022)
160159
const struct iso2022_designation *dsg;
161160
DBCHAR encoded;
162161
ucs4_t c = **inbuf;
163-
int insize;
162+
Py_ssize_t insize;
164163

165164
if (c < 0x80) {
166165
if (STATE_G0 != CHARSET_ASCII) {
@@ -183,7 +182,7 @@ ENCODER(iso2022)
183182

184183
encoded = MAP_UNMAPPABLE;
185184
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
186-
int length = 1;
185+
Py_ssize_t length = 1;
187186
encoded = dsg->encoder(&c, &length);
188187
if (encoded == MAP_MULTIPLE_AVAIL) {
189188
/* this implementation won't work for pair
@@ -300,12 +299,12 @@ DECODER_RESET(iso2022)
300299
return 0;
301300
}
302301

303-
static int
302+
static Py_ssize_t
304303
iso2022processesc(const void *config, MultibyteCodec_State *state,
305-
const unsigned char **inbuf, size_t *inleft)
304+
const unsigned char **inbuf, Py_ssize_t *inleft)
306305
{
307306
unsigned char charset, designation;
308-
size_t i, esclen;
307+
Py_ssize_t i, esclen;
309308

310309
for (i = 1;i < MAX_ESCSEQLEN;i++) {
311310
if (i >= *inleft)
@@ -388,10 +387,10 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
388387
else if ((c) == 0xa2) (assi) = 0x2019; \
389388
else if ((c) == 0xaf) (assi) = 0x2015;
390389

391-
static int
390+
static Py_ssize_t
392391
iso2022processg2(const void *config, MultibyteCodec_State *state,
393-
const unsigned char **inbuf, size_t *inleft,
394-
Py_UNICODE **outbuf, size_t *outleft)
392+
const unsigned char **inbuf, Py_ssize_t *inleft,
393+
Py_UNICODE **outbuf, Py_ssize_t *outleft)
395394
{
396395
/* not written to use encoder, decoder functions because only few
397396
* encodings use G2 designations in CJKCodecs */
@@ -425,7 +424,7 @@ DECODER(iso2022)
425424

426425
while (inleft > 0) {
427426
unsigned char c = IN1;
428-
int err;
427+
Py_ssize_t err;
429428

430429
if (STATE_GETFLAG(F_ESCTHROUGHOUT)) {
431430
/* ESC throughout mode:
@@ -589,7 +588,7 @@ ksx1001_decoder(const unsigned char *data)
589588
}
590589

591590
static DBCHAR
592-
ksx1001_encoder(const ucs4_t *data, int *length)
591+
ksx1001_encoder(const ucs4_t *data, Py_ssize_t *length)
593592
{
594593
DBCHAR coded;
595594
assert(*length == 1);
@@ -625,7 +624,7 @@ jisx0208_decoder(const unsigned char *data)
625624
}
626625

627626
static DBCHAR
628-
jisx0208_encoder(const ucs4_t *data, int *length)
627+
jisx0208_encoder(const ucs4_t *data, Py_ssize_t *length)
629628
{
630629
DBCHAR coded;
631630
assert(*length == 1);
@@ -662,7 +661,7 @@ jisx0212_decoder(const unsigned char *data)
662661
}
663662

664663
static DBCHAR
665-
jisx0212_encoder(const ucs4_t *data, int *length)
664+
jisx0212_encoder(const ucs4_t *data, Py_ssize_t *length)
666665
{
667666
DBCHAR coded;
668667
assert(*length == 1);
@@ -760,7 +759,7 @@ jisx0213_2004_2_decoder(const unsigned char *data)
760759
}
761760

762761
static DBCHAR
763-
jisx0213_encoder(const ucs4_t *data, int *length, void *config)
762+
jisx0213_encoder(const ucs4_t *data, Py_ssize_t *length, void *config)
764763
{
765764
DBCHAR coded;
766765

@@ -814,7 +813,7 @@ jisx0213_encoder(const ucs4_t *data, int *length, void *config)
814813
}
815814

816815
static DBCHAR
817-
jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
816+
jisx0213_2000_1_encoder(const ucs4_t *data, Py_ssize_t *length)
818817
{
819818
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
820819
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -826,10 +825,10 @@ jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
826825
}
827826

828827
static DBCHAR
829-
jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
828+
jisx0213_2000_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
830829
{
831830
DBCHAR coded;
832-
int ilength = *length;
831+
Py_ssize_t ilength = *length;
833832

834833
coded = jisx0213_encoder(data, length, (void *)2000);
835834
switch (ilength) {
@@ -849,7 +848,7 @@ jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
849848
}
850849

851850
static DBCHAR
852-
jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
851+
jisx0213_2000_2_encoder(const ucs4_t *data, Py_ssize_t *length)
853852
{
854853
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
855854
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -861,7 +860,7 @@ jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
861860
}
862861

863862
static DBCHAR
864-
jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
863+
jisx0213_2004_1_encoder(const ucs4_t *data, Py_ssize_t *length)
865864
{
866865
DBCHAR coded = jisx0213_encoder(data, length, NULL);
867866
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -873,10 +872,10 @@ jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
873872
}
874873

875874
static DBCHAR
876-
jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
875+
jisx0213_2004_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
877876
{
878877
DBCHAR coded;
879-
int ilength = *length;
878+
Py_ssize_t ilength = *length;
880879

881880
coded = jisx0213_encoder(data, length, NULL);
882881
switch (ilength) {
@@ -896,7 +895,7 @@ jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
896895
}
897896

898897
static DBCHAR
899-
jisx0213_2004_2_encoder(const ucs4_t *data, int *length)
898+
jisx0213_2004_2_encoder(const ucs4_t *data, Py_ssize_t *length)
900899
{
901900
DBCHAR coded = jisx0213_encoder(data, length, NULL);
902901
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -917,7 +916,7 @@ jisx0201_r_decoder(const unsigned char *data)
917916
}
918917

919918
static DBCHAR
920-
jisx0201_r_encoder(const ucs4_t *data, int *length)
919+
jisx0201_r_encoder(const ucs4_t *data, Py_ssize_t *length)
921920
{
922921
DBCHAR coded;
923922
JISX0201_R_ENCODE(*data, coded)
@@ -935,7 +934,7 @@ jisx0201_k_decoder(const unsigned char *data)
935934
}
936935

937936
static DBCHAR
938-
jisx0201_k_encoder(const ucs4_t *data, int *length)
937+
jisx0201_k_encoder(const ucs4_t *data, Py_ssize_t *length)
939938
{
940939
DBCHAR coded;
941940
JISX0201_K_ENCODE(*data, coded)
@@ -967,7 +966,7 @@ gb2312_decoder(const unsigned char *data)
967966
}
968967

969968
static DBCHAR
970-
gb2312_encoder(const ucs4_t *data, int *length)
969+
gb2312_encoder(const ucs4_t *data, Py_ssize_t *length)
971970
{
972971
DBCHAR coded;
973972
assert(*length == 1);
@@ -986,7 +985,7 @@ dummy_decoder(const unsigned char *data)
986985
}
987986

988987
static DBCHAR
989-
dummy_encoder(const ucs4_t *data, int *length)
988+
dummy_encoder(const ucs4_t *data, Py_ssize_t *length)
990989
{
991990
return MAP_UNMAPPABLE;
992991
}

Modules/cjkcodecs/_codecs_jp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_jp.c: Codecs collection for Japanese encodings
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_jp.c,v 1.14 2004/07/07 17:54:47 perky Exp $
65
*/
76

87
#define USING_BINARY_PAIR_SEARCH
@@ -150,7 +149,7 @@ ENCODER(euc_jis_2004)
150149
while (inleft > 0) {
151150
ucs4_t c = IN1;
152151
DBCHAR code;
153-
int insize;
152+
Py_ssize_t insize;
154153

155154
if (c < 0x80) {
156155
WRITE1(c)
@@ -545,7 +544,7 @@ ENCODER(shift_jis_2004)
545544
ucs4_t c = IN1;
546545
DBCHAR code = NOCHAR;
547546
int c1, c2;
548-
size_t insize;
547+
Py_ssize_t insize;
549548

550549
JISX0201_ENCODE(c, code)
551550
else DECODE_SURROGATE(c)

Modules/cjkcodecs/_codecs_kr.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_kr.c: Codecs collection for Korean encodings
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_kr.c,v 1.8 2004/07/07 14:59:26 perky Exp $
65
*/
76

87
#include "cjkcodecs.h"

Modules/cjkcodecs/_codecs_tw.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* _codecs_tw.c: Codecs collection for Taiwan's encodings
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: _codecs_tw.c,v 1.10 2004/07/07 14:59:26 perky Exp $
65
*/
76

87
#include "cjkcodecs.h"

Modules/cjkcodecs/alg_jisx0201.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* $CJKCodecs: alg_jisx0201.h,v 1.2 2004/06/29 05:42:08 perky Exp $ */
2-
31
#define JISX0201_R_ENCODE(c, assi) \
42
if ((c) < 0x80 && (c) != 0x5c && (c) != 0x7e) \
53
(assi) = (c); \

Modules/cjkcodecs/cjkcodecs.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* cjkcodecs.h: common header for cjkcodecs
33
*
44
* Written by Hye-Shik Chang <[email protected]>
5-
* $CJKCodecs: cjkcodecs.h,v 1.6 2004/07/18 15:22:31 perky Exp $
65
*/
76

87
#ifndef _CJKCODECS_H_
98
#define _CJKCODECS_H_
109

10+
#define PY_SSIZE_T_CLEAN
1111
#include "Python.h"
1212
#include "multibytecodec.h"
1313

@@ -70,25 +70,25 @@ static const struct dbcs_map *mapping_list;
7070
static int encoding##_encode_init( \
7171
MultibyteCodec_State *state, const void *config)
7272
#define ENCODER(encoding) \
73-
static int encoding##_encode( \
73+
static Py_ssize_t encoding##_encode( \
7474
MultibyteCodec_State *state, const void *config, \
75-
const Py_UNICODE **inbuf, size_t inleft, \
76-
unsigned char **outbuf, size_t outleft, int flags)
75+
const Py_UNICODE **inbuf, Py_ssize_t inleft, \
76+
unsigned char **outbuf, Py_ssize_t outleft, int flags)
7777
#define ENCODER_RESET(encoding) \
78-
static int encoding##_encode_reset( \
78+
static Py_ssize_t encoding##_encode_reset( \
7979
MultibyteCodec_State *state, const void *config, \
80-
unsigned char **outbuf, size_t outleft)
80+
unsigned char **outbuf, Py_ssize_t outleft)
8181

8282
#define DECODER_INIT(encoding) \
8383
static int encoding##_decode_init( \
8484
MultibyteCodec_State *state, const void *config)
8585
#define DECODER(encoding) \
86-
static int encoding##_decode( \
86+
static Py_ssize_t encoding##_decode( \
8787
MultibyteCodec_State *state, const void *config, \
88-
const unsigned char **inbuf, size_t inleft, \
89-
Py_UNICODE **outbuf, size_t outleft)
88+
const unsigned char **inbuf, Py_ssize_t inleft, \
89+
Py_UNICODE **outbuf, Py_ssize_t outleft)
9090
#define DECODER_RESET(encoding) \
91-
static int encoding##_decode_reset( \
91+
static Py_ssize_t encoding##_decode_reset( \
9292
MultibyteCodec_State *state, const void *config)
9393

9494
#if Py_UNICODE_SIZE == 4

Modules/cjkcodecs/emu_jisx0213_2000.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* $CJKCodecs: emu_jisx0213_2000.h,v 1.3 2004/07/08 02:53:37 perky Exp $ */
2-
31
/* These routines may be quite inefficient, but it's used only to emulate old
42
* standards. */
53

0 commit comments

Comments
 (0)