Skip to content

base: use int for ssize_t on 32-bit Windows - #7136

Open
Archkon wants to merge 1 commit into
google:mainfrom
Archkon:main
Open

base: use int for ssize_t on 32-bit Windows#7136
Archkon wants to merge 1 commit into
google:mainfrom
Archkon:main

Conversation

@Archkon

@Archkon Archkon commented Aug 19, 2026

Copy link
Copy Markdown

Use int for Perfetto's Windows ssize_t definition. This preserves the width and value range on all Windows architectures and makes the definition compatible with common embedders.

Electron has carried this downstream fix for Win32 builds since 2022.

@Archkon
Archkon requested a review from a team as a code owner August 19, 2026 09:47
@google-cla

google-cla Bot commented Aug 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Use int for Perfetto's Windows ssize_t definition. This preserves
the width and value range on all Windows architectures and makes the
definition compatible with common embedders.

Electron has carried this downstream fix for Win32 builds since 2022.
@primiano

primiano commented Aug 19, 2026

Copy link
Copy Markdown
Member

Do you have any link to the Electron's code you are mentioning?

From https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types I see

SSIZE_T | A signed version of SIZE_T
This type is declared in BaseTsd.h as follows:
typedef LONG_PTR SSIZE_T;

followed by

#if defined(_WIN64)
 typedef __int64 LONG_PTR; 
#else
 typedef long LONG_PTR;
#endif

So MSDN headers suggests it should be a long

@Archkon

Archkon commented Aug 19, 2026

Copy link
Copy Markdown
Author

https://github.com/electron/electron/blob/main/patches/perfetto/define_ssize_t_to_be_intptr_t_to_match_libuv.patch
The crux is the define would conflict with libuv and maybe not only limited to electron as nodejs is working on integrating with perfetto

@primiano

Copy link
Copy Markdown
Member

Hmm I see.
This is going to be tricky. I did some research.

  • MinGW-w64 basetsd.h:148: typedef LONG_PTR SSIZE_T → long on Win32 ✅ (matches MSDN)
  • MinGW-w64 corecrt.h:43-51: #ifndef _SSIZE_T_DEFINED ... typedef int ssize_t; on Win32, __int64 on Win64

So the same headers deliberately use long for the Win32 API type and int for the POSIX-ish lowercase one. libuv's intptr_t matches the CRT exactly on both
bitnesses, and it's guarded with SSIZE_T/_SSIZE_T_DEFINED and also supplies SSIZE_MAX. Perfetto's is long, unguarded, and doesn't set _SSIZE_T_DEFINED, so it
can never lose or defer a race.

so mingw seems to be on your side

  • CPython uses _W64 int on Win32;
  • libssh2 does typedef SSIZE_T ssize_t (the long camp) guarded by HAVE_SSIZE_T/defined(ssize_t) rather than
    _SSIZE_T_DEFINED, so libssh2 collides with libuv too.

Also worth knowing:

This already landed once: #4800 (Feb 2026) changed it to int, then #4830 reverted the whole PR as it broke google3 internal build.

I would probably do this instead

  // intptr_t is `int` on 32-bit and `long long` on 64-bit Windows. This matches
  // the MinGW CRT (corecrt.h) and libuv, which both define ssize_t this way.
  // Using `long` on 32-bit clashes with those (C2371) as int != long in C++.
  #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
  using ssize_t = intptr_t;
  #define _SSIZE_T_
  #define _SSIZE_T_DEFINED
  #endif

@Archkon

Archkon commented Aug 19, 2026

Copy link
Copy Markdown
Author

libuv also define SSIZE_MAX in guard block so your example code would cause some problem
how about just using ssize_t = intptr_t; as what original electron patch do to be easier to maintain?

@Archkon

Archkon commented Sep 3, 2026

Copy link
Copy Markdown
Author

@primiano What is the correct way to push this PR forward ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants