Skip to content

Commit ad27722

Browse files
committed
Use a new typedef utf8proc_ssize_t to avoid define collisions
with MSVC
1 parent 498ecbd commit ad27722

3 files changed

Lines changed: 38 additions & 37 deletions

File tree

test/graphemetest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char **argv)
4141
if (si) {
4242
uint8_t utf8[1024]; /* copy src without 0xff grapheme separators */
4343
size_t i = 0, j = 0;
44-
ssize_t glen;
44+
utf8proc_ssize_t glen;
4545
uint8_t *g; /* utf8proc_map grapheme results */
4646
while (i < si) {
4747
if (src[i] != '/')

utf8proc.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ UTF8PROC_DLLEXPORT const char *utf8proc_version(void) {
9191
return STRINGIZE(UTF8PROC_VERSION_MAJOR) "." STRINGIZE(UTF8PROC_VERSION_MINOR) "." STRINGIZE(UTF8PROC_VERSION_PATCH) "";
9292
}
9393

94-
UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode) {
94+
UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(utf8proc_ssize_t errcode) {
9595
switch (errcode) {
9696
case UTF8PROC_ERROR_NOMEM:
9797
return "Memory for processing UTF-8 data could not be allocated.";
@@ -108,8 +108,8 @@ UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode) {
108108
}
109109
}
110110

111-
UTF8PROC_DLLEXPORT ssize_t utf8proc_iterate(
112-
const uint8_t *str, ssize_t strlen, int32_t *dst
111+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(
112+
const uint8_t *str, utf8proc_ssize_t strlen, int32_t *dst
113113
) {
114114
int length;
115115
int i;
@@ -155,7 +155,7 @@ UTF8PROC_DLLEXPORT bool utf8proc_codepoint_valid(int32_t uc) {
155155
else return true;
156156
}
157157

158-
UTF8PROC_DLLEXPORT ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst) {
158+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst) {
159159
if (uc < 0x00) {
160160
return 0;
161161
} else if (uc < 0x80) {
@@ -250,7 +250,7 @@ UTF8PROC_DLLEXPORT const char *utf8proc_category_string(int32_t c) {
250250
return utf8proc_decompose_char((replacement_uc), dst, bufsize, \
251251
options & ~UTF8PROC_LUMP, last_boundclass)
252252

253-
UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssize_t bufsize, utf8proc_option_t options, int *last_boundclass) {
253+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, utf8proc_ssize_t bufsize, utf8proc_option_t options, int *last_boundclass) {
254254
const utf8proc_property_t *property;
255255
utf8proc_propval_t category;
256256
int32_t hangul_sindex;
@@ -313,7 +313,7 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssi
313313
if (options & UTF8PROC_CASEFOLD) {
314314
if (property->casefold_mapping) {
315315
const int32_t *casefold_entry;
316-
ssize_t written = 0;
316+
utf8proc_ssize_t written = 0;
317317
for (casefold_entry = property->casefold_mapping;
318318
*casefold_entry >= 0; casefold_entry++) {
319319
written += utf8proc_decompose_char(*casefold_entry, dst+written,
@@ -328,7 +328,7 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssi
328328
if (property->decomp_mapping &&
329329
(!property->decomp_type || (options & UTF8PROC_COMPAT))) {
330330
const int32_t *decomp_entry;
331-
ssize_t written = 0;
331+
utf8proc_ssize_t written = 0;
332332
for (decomp_entry = property->decomp_mapping;
333333
*decomp_entry >= 0; decomp_entry++) {
334334
written += utf8proc_decompose_char(*decomp_entry, dst+written,
@@ -354,21 +354,21 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(int32_t uc, int32_t *dst, ssi
354354
return 1;
355355
}
356356

357-
UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose(
358-
const uint8_t *str, ssize_t strlen,
359-
int32_t *buffer, ssize_t bufsize, utf8proc_option_t options
357+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose(
358+
const uint8_t *str, utf8proc_ssize_t strlen,
359+
int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options
360360
) {
361361
/* strlen will be ignored, if UTF8PROC_NULLTERM is set in options */
362-
ssize_t wpos = 0;
362+
utf8proc_ssize_t wpos = 0;
363363
if ((options & UTF8PROC_COMPOSE) && (options & UTF8PROC_DECOMPOSE))
364364
return UTF8PROC_ERROR_INVALIDOPTS;
365365
if ((options & UTF8PROC_STRIPMARK) &&
366366
!(options & UTF8PROC_COMPOSE) && !(options & UTF8PROC_DECOMPOSE))
367367
return UTF8PROC_ERROR_INVALIDOPTS;
368368
{
369369
int32_t uc;
370-
ssize_t rpos = 0;
371-
ssize_t decomp_result;
370+
utf8proc_ssize_t rpos = 0;
371+
utf8proc_ssize_t decomp_result;
372372
int boundclass = UTF8PROC_BOUNDCLASS_START;
373373
while (1) {
374374
if (options & UTF8PROC_NULLTERM) {
@@ -395,7 +395,7 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose(
395395
}
396396
}
397397
if ((options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) && bufsize >= wpos) {
398-
ssize_t pos = 0;
398+
utf8proc_ssize_t pos = 0;
399399
while (pos < wpos-1) {
400400
int32_t uc1, uc2;
401401
const utf8proc_property_t *property1, *property2;
@@ -416,12 +416,12 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose(
416416
return wpos;
417417
}
418418

419-
UTF8PROC_DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, utf8proc_option_t options) {
419+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_reencode(int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options) {
420420
/* UTF8PROC_NULLTERM option will be ignored, 'length' is never ignored
421421
ASSERT: 'buffer' has one spare byte of free space at the end! */
422422
if (options & (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS | UTF8PROC_STRIPCC)) {
423-
ssize_t rpos;
424-
ssize_t wpos = 0;
423+
utf8proc_ssize_t rpos;
424+
utf8proc_ssize_t wpos = 0;
425425
int32_t uc;
426426
for (rpos = 0; rpos < length; rpos++) {
427427
uc = buffer[rpos];
@@ -455,8 +455,8 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, ut
455455
int32_t current_char;
456456
const utf8proc_property_t *starter_property = NULL, *current_property;
457457
utf8proc_propval_t max_combining_class = -1;
458-
ssize_t rpos;
459-
ssize_t wpos = 0;
458+
utf8proc_ssize_t rpos;
459+
utf8proc_ssize_t wpos = 0;
460460
int32_t composition;
461461
for (rpos = 0; rpos < length; rpos++) {
462462
current_char = buffer[rpos];
@@ -520,7 +520,7 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, ut
520520
length = wpos;
521521
}
522522
{
523-
ssize_t rpos, wpos = 0;
523+
utf8proc_ssize_t rpos, wpos = 0;
524524
int32_t uc;
525525
for (rpos = 0; rpos < length; rpos++) {
526526
uc = buffer[rpos];
@@ -531,11 +531,11 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, ut
531531
}
532532
}
533533

534-
UTF8PROC_DLLEXPORT ssize_t utf8proc_map(
535-
const uint8_t *str, ssize_t strlen, uint8_t **dstptr, utf8proc_option_t options
534+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map(
535+
const uint8_t *str, utf8proc_ssize_t strlen, uint8_t **dstptr, utf8proc_option_t options
536536
) {
537537
int32_t *buffer;
538-
ssize_t result;
538+
utf8proc_ssize_t result;
539539
*dstptr = NULL;
540540
result = utf8proc_decompose(str, strlen, NULL, 0, options);
541541
if (result < 0) return result;

utf8proc.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ typedef short int16_t;
8383
typedef unsigned short uint16_t;
8484
typedef int int32_t;
8585
# ifdef _WIN64
86-
# define ssize_t __int64
86+
typedef __int64 utf8proc_ssize_t;
8787
# else
88-
# define ssize_t int
88+
typedef int utf8proc_ssize_t;
8989
# endif
9090
# ifndef __cplusplus
9191
typedef unsigned char bool;
@@ -94,6 +94,7 @@ enum {false, true};
9494
#else
9595
# include <stdbool.h>
9696
# include <inttypes.h>
97+
typedef ssize_t utf8proc_ssize_t;
9798
#endif
9899
#include <limits.h>
99100

@@ -364,7 +365,7 @@ UTF8PROC_DLLEXPORT const char *utf8proc_version(void);
364365
* Returns an informative error string for the given utf8proc error code
365366
* (e.g. the error codes returned by @ref utf8proc_map).
366367
*/
367-
UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode);
368+
UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(utf8proc_ssize_t errcode);
368369

369370
/**
370371
* Reads a single codepoint from the UTF-8 sequence being pointed to by `str`.
@@ -376,7 +377,7 @@ UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode);
376377
* In case of success, the number of bytes read is returned; otherwise, a
377378
* negative error code is returned.
378379
*/
379-
UTF8PROC_DLLEXPORT ssize_t utf8proc_iterate(const uint8_t *str, ssize_t strlen, int32_t *codepoint_ref);
380+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(const uint8_t *str, utf8proc_ssize_t strlen, int32_t *codepoint_ref);
380381

381382
/**
382383
* Check if a codepoint is valid (regardless of whether it has been
@@ -395,7 +396,7 @@ UTF8PROC_DLLEXPORT bool utf8proc_codepoint_valid(int32_t codepoint);
395396
*
396397
* This function does not check whether `codepoint` is valid Unicode.
397398
*/
398-
UTF8PROC_DLLEXPORT ssize_t utf8proc_encode_char(int32_t codepoint, uint8_t *dst);
399+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_encode_char(int32_t codepoint, uint8_t *dst);
399400

400401
/**
401402
* Look up the properties for a given codepoint.
@@ -438,8 +439,8 @@ UTF8PROC_DLLEXPORT const utf8proc_property_t *utf8proc_get_property(int32_t code
438439
* required buffer size is returned, while the buffer will be overwritten with
439440
* undefined data.
440441
*/
441-
UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(
442-
int32_t codepoint, int32_t *dst, ssize_t bufsize,
442+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(
443+
int32_t codepoint, int32_t *dst, utf8proc_ssize_t bufsize,
443444
utf8proc_option_t options, int *last_boundclass
444445
);
445446

@@ -459,9 +460,9 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose_char(
459460
* required buffer size is returned, while the buffer will be overwritten with
460461
* undefined data.
461462
*/
462-
UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose(
463-
const uint8_t *str, ssize_t strlen,
464-
int32_t *buffer, ssize_t bufsize, utf8proc_option_t options
463+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose(
464+
const uint8_t *str, utf8proc_ssize_t strlen,
465+
int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options
465466
);
466467

467468
/**
@@ -489,7 +490,7 @@ UTF8PROC_DLLEXPORT ssize_t utf8proc_decompose(
489490
* entries of the array pointed to by `str` have to be in the
490491
* range `0x0000` to `0x10FFFF`. Otherwise, the program might crash!
491492
*/
492-
UTF8PROC_DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, utf8proc_option_t options);
493+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_reencode(int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
493494

494495
/**
495496
* Given a pair of consecutive codepoints, return whether a grapheme break is
@@ -537,8 +538,8 @@ UTF8PROC_DLLEXPORT const char *utf8proc_category_string(int32_t codepoint);
537538
* @note The memory of the new UTF-8 string will have been allocated
538539
* with `malloc`, and should therefore be deallocated with `free`.
539540
*/
540-
UTF8PROC_DLLEXPORT ssize_t utf8proc_map(
541-
const uint8_t *str, ssize_t strlen, uint8_t **dstptr, utf8proc_option_t options
541+
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map(
542+
const uint8_t *str, utf8proc_ssize_t strlen, uint8_t **dstptr, utf8proc_option_t options
542543
);
543544

544545
/** @name Unicode normalization

0 commit comments

Comments
 (0)