Skip to content

Commit 96a7f9b

Browse files
authored
deprecate cuchar, don't redefine it (#18505)
1 parent 089e741 commit 96a7f9b

File tree

11 files changed

+55
-54
lines changed

11 files changed

+55
-54
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
- Deprecated `std/mersenne`
88

9-
- `cuchar` now aliases `uint8` instead of `char`
9+
- `cuchar` is now deprecated as it aliased `char` where arguably it should have aliased `uint8`.
10+
Please use `char` or `uint8` instead.
1011

1112
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
1213
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.

lib/posix/posix_linux_amd64.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type
4747
d_ino*: Ino
4848
d_off*: Off
4949
d_reclen*: cushort
50-
d_type*: int8 # cuchar really!
50+
d_type*: int8 # uint8 really!
5151
d_name*: array[256, cchar]
5252

5353
Tflock* {.importc: "struct flock", final, pure,

lib/posix/posix_nintendoswitch.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type
3333
Dirent* {.importc: "struct dirent",
3434
header: "<dirent.h>", final, pure.} = object ## dirent_t struct
3535
d_ino*: Ino
36-
d_type*: int8 # cuchar really!
36+
d_type*: int8 # uint8 really!
3737
d_name*: array[256, cchar]
3838

3939
Tflock* {.importc: "struct flock", final, pure,
@@ -347,20 +347,20 @@ type
347347

348348
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
349349
pure, final.} = object ## struct sockaddr
350-
sa_len: cuchar
350+
sa_len: uint8
351351
sa_family*: TSa_Family ## Address family.
352352
sa_data*: array[14, char] ## Socket address (variable-length data).
353353

354354
Sockaddr_storage* {.importc: "struct sockaddr_storage",
355355
header: "<sys/socket.h>",
356356
pure, final.} = object ## struct sockaddr_storage
357-
ss_len: cuchar
357+
ss_len: uint8
358358
ss_family*: TSa_Family ## Address family.
359-
ss_padding1: array[64 - sizeof(cuchar) - sizeof(cshort), char]
359+
ss_padding1: array[64 - sizeof(uint8) - sizeof(cshort), char]
360360
ss_align: clonglong
361361
ss_padding2: array[
362-
128 - sizeof(cuchar) - sizeof(cshort) -
363-
(64 - sizeof(cuchar) - sizeof(cshort)) - 64, char]
362+
128 - sizeof(uint8) - sizeof(cshort) -
363+
(64 - sizeof(uint8) - sizeof(cshort)) - 64, char]
364364

365365
Tif_nameindex* {.importc: "struct if_nameindex", final,
366366
pure, header: "<net/if.h>".} = object ## struct if_nameindex

lib/pure/bitops.nim

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ when useGCC_builtins:
450450

451451
elif useVCC_builtins:
452452
# Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
453-
func bitScanReverse(index: ptr culong, mask: culong): cuchar {.
453+
func bitScanReverse(index: ptr culong, mask: culong): uint8 {.
454454
importc: "_BitScanReverse", header: "<intrin.h>".}
455-
func bitScanReverse64(index: ptr culong, mask: uint64): cuchar {.
455+
func bitScanReverse64(index: ptr culong, mask: uint64): uint8 {.
456456
importc: "_BitScanReverse64", header: "<intrin.h>".}
457457

458458
# Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1).
459-
func bitScanForward(index: ptr culong, mask: culong): cuchar {.
459+
func bitScanForward(index: ptr culong, mask: culong): uint8 {.
460460
importc: "_BitScanForward", header: "<intrin.h>".}
461-
func bitScanForward64(index: ptr culong, mask: uint64): cuchar {.
461+
func bitScanForward64(index: ptr culong, mask: uint64): uint8 {.
462462
importc: "_BitScanForward64", header: "<intrin.h>".}
463463

464464
template vcc_scan_impl(fnc: untyped; v: untyped): int =
@@ -468,15 +468,15 @@ elif useVCC_builtins:
468468

469469
elif useICC_builtins:
470470
# Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
471-
func bitScanForward(p: ptr uint32, b: uint32): cuchar {.
471+
func bitScanForward(p: ptr uint32, b: uint32): uint8 {.
472472
importc: "_BitScanForward", header: "<immintrin.h>".}
473-
func bitScanForward64(p: ptr uint32, b: uint64): cuchar {.
473+
func bitScanForward64(p: ptr uint32, b: uint64): uint8 {.
474474
importc: "_BitScanForward64", header: "<immintrin.h>".}
475475

476476
# Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
477-
func bitScanReverse(p: ptr uint32, b: uint32): cuchar {.
477+
func bitScanReverse(p: ptr uint32, b: uint32): uint8 {.
478478
importc: "_BitScanReverse", header: "<immintrin.h>".}
479-
func bitScanReverse64(p: ptr uint32, b: uint64): cuchar {.
479+
func bitScanReverse64(p: ptr uint32, b: uint64): uint8 {.
480480
importc: "_BitScanReverse64", header: "<immintrin.h>".}
481481

482482
template icc_scan_impl(fnc: untyped; v: untyped): int =
@@ -664,7 +664,7 @@ when useBuiltinsRotate:
664664
when defined(gcc):
665665
# GCC was tested until version 4.8.1 and intrinsics were present. Not tested
666666
# in previous versions.
667-
func builtin_rotl8(value: cuchar, shift: cint): cuchar
667+
func builtin_rotl8(value: uint8, shift: cint): uint8
668668
{.importc: "__rolb", header: "<x86intrin.h>".}
669669
func builtin_rotl16(value: cushort, shift: cint): cushort
670670
{.importc: "__rolw", header: "<x86intrin.h>".}
@@ -674,7 +674,7 @@ when useBuiltinsRotate:
674674
func builtin_rotl64(value: culonglong, shift: cint): culonglong
675675
{.importc: "__rolq", header: "<x86intrin.h>".}
676676

677-
func builtin_rotr8(value: cuchar, shift: cint): cuchar
677+
func builtin_rotr8(value: uint8, shift: cint): uint8
678678
{.importc: "__rorb", header: "<x86intrin.h>".}
679679
func builtin_rotr16(value: cushort, shift: cint): cushort
680680
{.importc: "__rorw", header: "<x86intrin.h>".}
@@ -690,7 +690,7 @@ when useBuiltinsRotate:
690690
# https://releases.llvm.org/8.0.0/tools/clang/docs/ReleaseNotes.html#non-comprehensive-list-of-changes-in-this-release
691691
# https://releases.llvm.org/8.0.0/tools/clang/docs/LanguageExtensions.html#builtin-rotateleft
692692
# source for correct declarations: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Builtins.def
693-
func builtin_rotl8(value: cuchar, shift: cuchar): cuchar
693+
func builtin_rotl8(value: uint8, shift: uint8): uint8
694694
{.importc: "__builtin_rotateleft8", nodecl.}
695695
func builtin_rotl16(value: cushort, shift: cushort): cushort
696696
{.importc: "__builtin_rotateleft16", nodecl.}
@@ -700,7 +700,7 @@ when useBuiltinsRotate:
700700
func builtin_rotl64(value: culonglong, shift: culonglong): culonglong
701701
{.importc: "__builtin_rotateleft64", nodecl.}
702702

703-
func builtin_rotr8(value: cuchar, shift: cuchar): cuchar
703+
func builtin_rotr8(value: uint8, shift: uint8): uint8
704704
{.importc: "__builtin_rotateright8", nodecl.}
705705
func builtin_rotr16(value: cushort, shift: cushort): cushort
706706
{.importc: "__builtin_rotateright16", nodecl.}
@@ -716,19 +716,19 @@ when useBuiltinsRotate:
716716
# https://docs.microsoft.com/en-us/cpp/intrinsics/rotl8-rotl16?view=msvc-160
717717
# https://docs.microsoft.com/en-us/cpp/intrinsics/rotr8-rotr16?view=msvc-160
718718
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rotl-rotl64-rotr-rotr64?view=msvc-160
719-
func builtin_rotl8(value: cuchar, shift: cuchar): cuchar
719+
func builtin_rotl8(value: uint8, shift: uint8): uint8
720720
{.importc: "_rotl8", header: "<intrin.h>".}
721-
func builtin_rotl16(value: cushort, shift: cuchar): cushort
721+
func builtin_rotl16(value: cushort, shift: uint8): cushort
722722
{.importc: "_rotl16", header: "<intrin.h>".}
723723
func builtin_rotl32(value: cuint, shift: cint): cuint
724724
{.importc: "_rotl", header: "<stdlib.h>".}
725725
when defined(amd64):
726726
func builtin_rotl64(value: culonglong, shift: cint): culonglong
727727
{.importc: "_rotl64", header: "<stdlib.h>".}
728728

729-
func builtin_rotr8(value: cuchar, shift: cuchar): cuchar
729+
func builtin_rotr8(value: uint8, shift: uint8): uint8
730730
{.importc: "_rotr8", header: "<intrin.h>".}
731-
func builtin_rotr16(value: cushort, shift: cuchar): cushort
731+
func builtin_rotr16(value: cushort, shift: uint8): cushort
732732
{.importc: "_rotr16", header: "<intrin.h>".}
733733
func builtin_rotr32(value: cuint, shift: cint): cuint
734734
{.importc: "_rotr", header: "<stdlib.h>".}
@@ -738,7 +738,7 @@ when useBuiltinsRotate:
738738
elif defined(icl):
739739
# Tested on Intel(R) C++ Intel(R) 64 Compiler Classic Version 2021.1.2 Build
740740
# 20201208_000000 x64 and x86. Not tested in previous versions.
741-
func builtin_rotl8(value: cuchar, shift: cint): cuchar
741+
func builtin_rotl8(value: uint8, shift: cint): uint8
742742
{.importc: "__rolb", header: "<immintrin.h>".}
743743
func builtin_rotl16(value: cushort, shift: cint): cushort
744744
{.importc: "__rolw", header: "<immintrin.h>".}
@@ -748,7 +748,7 @@ when useBuiltinsRotate:
748748
func builtin_rotl64(value: culonglong, shift: cint): culonglong
749749
{.importc: "__rolq", header: "<immintrin.h>".}
750750

751-
func builtin_rotr8(value: cuchar, shift: cint): cuchar
751+
func builtin_rotr8(value: uint8, shift: cint): uint8
752752
{.importc: "__rorb", header: "<immintrin.h>".}
753753
func builtin_rotr16(value: cushort, shift: cint): cushort
754754
{.importc: "__rorw", header: "<immintrin.h>".}
@@ -777,7 +777,7 @@ func shiftTypeTo(size: static int, shift: int): auto {.inline.} =
777777
when (defined(vcc) and (size in [4, 8])) or defined(gcc) or defined(icl):
778778
cint(shift)
779779
elif (defined(vcc) and (size in [1, 2])) or (defined(clang) and size == 1):
780-
cuchar(shift)
780+
uint8(shift)
781781
elif defined(clang):
782782
when size == 2:
783783
cushort(shift)
@@ -802,7 +802,7 @@ func rotateLeftBits*[T: SomeUnsignedInt](value: T, shift: range[0..(sizeof(T) *
802802
when useBuiltinsRotate:
803803
const size = sizeof(T)
804804
when size == 1:
805-
builtin_rotl8(value.cuchar, shiftTypeTo(size, shift)).T
805+
builtin_rotl8(value.uint8, shiftTypeTo(size, shift)).T
806806
elif size == 2:
807807
builtin_rotl16(value.cushort, shiftTypeTo(size, shift)).T
808808
elif size == 4:
@@ -830,7 +830,7 @@ func rotateRightBits*[T: SomeUnsignedInt](value: T, shift: range[0..(sizeof(T) *
830830
when useBuiltinsRotate:
831831
const size = sizeof(T)
832832
when size == 1:
833-
builtin_rotr8(value.cuchar, shiftTypeTo(size, shift)).T
833+
builtin_rotr8(value.uint8, shiftTypeTo(size, shift)).T
834834
elif size == 2:
835835
builtin_rotr16(value.cushort, shiftTypeTo(size, shift)).T
836836
elif size == 4:

lib/pure/net.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ when defineSsl:
503503
## Retrieve the ssl pointer of `socket`.
504504
## Useful for interfacing with `openssl`.
505505
self.sslHandle
506-
506+
507507
proc raiseSSLError*(s = "") =
508508
## Raises a new SSL error.
509509
if s != "":
@@ -688,7 +688,7 @@ when defineSsl:
688688
return ctx.getExtraInternal().clientGetPskFunc
689689

690690
proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring;
691-
max_identity_len: cuint; psk: ptr cuchar;
691+
max_identity_len: cuint; psk: ptr uint8;
692692
max_psk_len: cuint): cuint {.cdecl.} =
693693
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
694694
let hintString = if hint == nil: "" else: $hint
@@ -714,7 +714,7 @@ when defineSsl:
714714
proc serverGetPskFunc*(ctx: SslContext): SslServerGetPskFunc =
715715
return ctx.getExtraInternal().serverGetPskFunc
716716

717-
proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr cuchar;
717+
proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr uint8;
718718
max_psk_len: cint): cuint {.cdecl.} =
719719
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
720720
let pskString = (ctx.serverGetPskFunc)($identity)

lib/pure/terminal.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ template styledWriteLine*(f: File, args: varargs[untyped]) =
761761
runnableExamples:
762762
proc error(msg: string) =
763763
styledWriteLine(stderr, fgRed, "Error: ", resetStyle, msg)
764-
764+
765765
styledWrite(f, args)
766766
write(f, "\n")
767767

lib/std/sysrand.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ elif defined(windows):
132132
type
133133
PVOID = pointer
134134
BCRYPT_ALG_HANDLE = PVOID
135-
PUCHAR = ptr cuchar
135+
PUCHAR = ptr uint8
136136
NTSTATUS = clong
137137
ULONG = culong
138138

lib/system.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,8 @@ type # these work for most platforms:
14271427
## This is the same as the type `long double` in *C*.
14281428
## This C type is not supported by Nim's code generator.
14291429

1430-
cuchar* {.importc: "unsigned char", nodecl.} = uint8
1431-
## This is the same as the type `unsigned char` in *C*.
1430+
cuchar* {.importc: "unsigned char", nodecl, deprecated: "use `char` or `uint8` instead".} = char
1431+
## Deprecated: Use `uint8` instead.
14321432
cushort* {.importc: "unsigned short", nodecl.} = uint16
14331433
## This is the same as the type `unsigned short` in *C*.
14341434
cuint* {.importc: "unsigned int", nodecl.} = uint32

lib/windows/winlean.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type
4242
PULONG_PTR* = ptr uint
4343
HDC* = Handle
4444
HGLRC* = Handle
45-
BYTE* = cuchar
45+
BYTE* = uint8
4646

4747
SECURITY_ATTRIBUTES* {.final, pure.} = object
4848
nLength*: int32
@@ -717,7 +717,7 @@ const
717717
FILE_WRITE_DATA* = 0x00000002 # file & pipe
718718

719719
# Error Constants
720-
const
720+
const
721721
ERROR_FILE_NOT_FOUND* = 2 ## https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
722722
ERROR_PATH_NOT_FOUND* = 3
723723
ERROR_ACCESS_DENIED* = 5

lib/wrappers/openssl.nim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,16 +520,16 @@ proc OPENSSL_sk_num*(stack: PSTACK): int {.cdecl, dynlib: DLLSSLName, importc.}
520520
proc OPENSSL_sk_value*(stack: PSTACK, index: int): pointer {.cdecl,
521521
dynlib: DLLSSLName, importc.}
522522

523-
proc d2i_X509*(px: ptr PX509, i: ptr ptr cuchar, len: cint): PX509 {.cdecl,
523+
proc d2i_X509*(px: ptr PX509, i: ptr ptr uint8, len: cint): PX509 {.cdecl,
524524
dynlib: DLLUtilName, importc.}
525525

526-
proc i2d_X509*(cert: PX509; o: ptr ptr cuchar): cint {.cdecl,
526+
proc i2d_X509*(cert: PX509; o: ptr ptr uint8): cint {.cdecl,
527527
dynlib: DLLUtilName, importc.}
528528

529529
proc d2i_X509*(b: string): PX509 =
530530
## decode DER/BER bytestring into X.509 certificate struct
531531
var bb = b.cstring
532-
let i = cast[ptr ptr cuchar](addr bb)
532+
let i = cast[ptr ptr uint8](addr bb)
533533
let ret = d2i_X509(addr result, i, b.len.cint)
534534
if ret.isNil:
535535
raise newException(Exception, "X.509 certificate decoding failed")
@@ -539,7 +539,7 @@ proc i2d_X509*(cert: PX509): string =
539539
let encoded_length = i2d_X509(cert, nil)
540540
result = newString(encoded_length)
541541
var q = result.cstring
542-
let o = cast[ptr ptr cuchar](addr q)
542+
let o = cast[ptr ptr uint8](addr q)
543543
let length = i2d_X509(cert, o)
544544
if length.int <= 0:
545545
raise newException(Exception, "X.509 certificate encoding failed")
@@ -599,11 +599,11 @@ proc SSL_CTX_set_tlsext_servername_arg*(ctx: SslCtx, arg: pointer): int =
599599

600600
type
601601
PskClientCallback* = proc (ssl: SslPtr;
602-
hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr cuchar;
602+
hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr uint8;
603603
max_psk_len: cuint): cuint {.cdecl.}
604604

605605
PskServerCallback* = proc (ssl: SslPtr;
606-
identity: cstring; psk: ptr cuchar; max_psk_len: cint): cuint {.cdecl.}
606+
identity: cstring; psk: ptr uint8; max_psk_len: cint): cuint {.cdecl.}
607607

608608
proc SSL_CTX_set_psk_client_callback*(ctx: SslCtx; callback: PskClientCallback) {.cdecl, dynlib: DLLSSLName, importc.}
609609
## Set callback called when OpenSSL needs PSK (for client).
@@ -672,13 +672,13 @@ proc PEM_read_bio_RSAPublicKey*(bp: BIO, x: ptr PRSA, cb: pem_password_cb, u: po
672672
dynlib: DLLUtilName, importc.}
673673
proc PEM_read_bio_RSAPrivateKey*(bp: BIO, x: ptr PRSA, cb: pem_password_cb, u: pointer): PRSA {.cdecl,
674674
dynlib: DLLUtilName, importc.}
675-
proc RSA_private_encrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl,
675+
proc RSA_private_encrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
676676
dynlib: DLLUtilName, importc.}
677-
proc RSA_public_encrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl,
677+
proc RSA_public_encrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
678678
dynlib: DLLUtilName, importc.}
679-
proc RSA_private_decrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl,
679+
proc RSA_private_decrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
680680
dynlib: DLLUtilName, importc.}
681-
proc RSA_public_decrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl,
681+
proc RSA_public_decrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
682682
dynlib: DLLUtilName, importc.}
683683
proc RSA_free*(rsa: PRSA) {.cdecl, dynlib: DLLUtilName, importc.}
684684
proc RSA_size*(rsa: PRSA): cint {.cdecl, dynlib: DLLUtilName, importc.}
@@ -744,8 +744,8 @@ type
744744
proc md5_Init*(c: var MD5_CTX): cint{.importc: "MD5_Init".}
745745
proc md5_Update*(c: var MD5_CTX; data: pointer; len: csize_t): cint{.importc: "MD5_Update".}
746746
proc md5_Final*(md: cstring; c: var MD5_CTX): cint{.importc: "MD5_Final".}
747-
proc md5*(d: ptr cuchar; n: csize_t; md: ptr cuchar): ptr cuchar{.importc: "MD5".}
748-
proc md5_Transform*(c: var MD5_CTX; b: ptr cuchar){.importc: "MD5_Transform".}
747+
proc md5*(d: ptr uint8; n: csize_t; md: ptr uint8): ptr uint8{.importc: "MD5".}
748+
proc md5_Transform*(c: var MD5_CTX; b: ptr uint8){.importc: "MD5_Transform".}
749749
{.pop.}
750750

751751
from strutils import toHex, toLowerAscii

0 commit comments

Comments
 (0)