Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What way to choose to fix Warning: ULONG_PTR differs in levels of indirection from void * in AC-generated code? #95417

Open
1 of 2 tasks
arhadthedev opened this issue Jul 29, 2022 · 2 comments · May be fixed by #95446
Open
1 of 2 tasks
Labels
type-feature A feature request or enhancement

Comments

@arhadthedev
Copy link
Contributor

arhadthedev commented Jul 29, 2022

Currently, Argument Clinic generates initialization of ULONG_PTR arguments using PyLong_AsVoidPtr(). The reason is sizeof(ULONG_PTR) == sizeof(void*) akin to C99 uintptr_t.

However, a compiler warns that implicit conversion of a pointer to a pointer-sized integer is not the best practice. This is relevant for _overlapped.CreateIoCompletionPort():

_overlapped_CreateIoCompletionPort_impl(PyObject *module, HANDLE FileHandle,
HANDLE ExistingCompletionPort,
ULONG_PTR CompletionKey,
DWORD NumberOfConcurrentThreads);
CompletionKey = PyLong_AsVoidPtr(args[2]);

I see three ways to fix it in ULONG_PTR Argument Clinic converter and need an opinion on how to address the warning best:

  • generate in-place cast: CompletionKey = (ULONG_PTR)PyLong_AsVoidPtr(args[2]); or
  • add a private Windows-only #define _PyLong_AsUlongPtr(arg) (ULONG_PTR)PyLong_AsVoidPtr(arg) macro so the generated line becomes CompletionKey = PyLong_AsUlongPtr(args[2]); or
  • add a public Windows-only PyLong_AsUlongPtr entity and document it so Python integrators and module authors also can work with this volatile WinAPI type
@arhadthedev arhadthedev added the type-feature A feature request or enhancement label Jul 29, 2022
@eryksun
Copy link
Contributor

eryksun commented Jul 29, 2022

The C API could support cross-platform PyLong_AsUintptr_t() and PyLong_FromUintptr_t(). The type definitions for ULONG_PTR and uintptr_t are compatible in Windows. For 64-bit, they're both unsigned __int64. For 32-bit, uintptr_t is unsigned int, and ULONG_PTR is unsigned long.

@arhadthedev
Copy link
Contributor Author

arhadthedev commented Aug 1, 2022

To fix the warning, two steps are necessary:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants