-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
AK: Simplify usage of windows.h and winsock2.h #2674
base: master
Are you sure you want to change the base?
Conversation
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
676d4fd
to
cc61467
Compare
This is not like for like. Winsock isn't the same as windows. So if we name it windows.h we should be including windows.h. winsock is only for the sockets. Maybe we can include both in AK/Windows.h. |
winsock2.h includes windows.h, no need to include both. |
Didn't know that. Then it's fine. Is there anything else we might want here? |
Maybe, we will know when we need that. |
Any reason this starts with lower case specifically? |
Just my preference. |
This doesn't match convention in AK, nor the normal name for it. Causes a compilation error due to non-portable-include if you write with uppercase. |
Not matching the AK convention is deliberate. I wanted this file to be different because it is a special platform header, it doesn't define any classes/functions in AK namespace. The same goes for sockaddr-win.h. The "normal" name for <windows.h> debatable, but I think it is more lowercase than titlecase. MSDN examples use lowercase, Visual Studio templates use lowercase. I saw lowercase version much more often in real code. Also, this header is supposed to include everything from win32 API that is not included by other headers (like sockets and time), so it doesn't directly correspond to <windows.h> and doesn't have to follow its conventions. But again, it is more a matter of preference. If maintainers make me change it I'll change it, but for now I want to keep lowercase. |
AK/windows.h
Outdated
#ifdef AK_OS_WINDOWS // needed for Swift | ||
# define timeval dummy_timeval | ||
# include <winsock2.h> | ||
# undef timeval | ||
# include <io.h> | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea: be more restrictive with ideas like in the following?
#ifdef AK_OS_WINDOWS // needed for Swift | |
# define timeval dummy_timeval | |
# include <winsock2.h> | |
# undef timeval | |
# include <io.h> | |
#endif | |
#ifndef AK_OS_WINDOWS | |
static_assert(false, "Windows header included on non-Windows target"); | |
#endif | |
// needed for Swift | |
#define timeval dummy_timeval | |
#include <winsock2.h> | |
#undef timeval | |
#include <io.h> |
Consider this a maintainer request to change the names of any headers added in your PRs to |
AK/windows.h
Outdated
|
||
#pragma once | ||
|
||
#ifdef AK_OS_WINDOWS // needed for Swift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "needed for swift" comment is confusing. Have you tried enabling swift on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is related to wanting to error out on other platforms if they include this header, the path to it will need updated in the ENABLE_SWIFT branch of AK/CMakeLists.txt to be an EXCLUDED path for the Swift bridging header. See LibCore for an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added #ifdef to fix this error. LibCore (or other libs) doesn't have the word EXCLUDED in their CMakeLists files. Can you provide the exact line that should be added to exclude Windows.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, found it: set(SWIFT_EXCLUDE_HEADERS ...
in LibGfx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding set(SWIFT_EXCLUDE_HEADERS Windows.h)
to AK/CMakeLists.txt didn't fix the problem (same error), so I am still using #ifdef.
@ADKaster I changed it to title case, but note that AK already has similar platform-specific files, kmalloc.h/.cpp, and they use lowercase. I think you are wrong on this one. |
@awesomekling Can you comment on this ^^^ ? (Platform-specific windows.h vs Windows.h in AK) |
8e15027
to
a36425f
Compare
kmalloc.h is an ancient artifact from Serenity's kernel using AK. It is not a good argument to break naming conventions in new files. |
5e38c90
to
4c7b143
Compare
8fa05a1
to
7bb10ff
Compare
Please conform to project convention and name it |
@ADKaster I renamed the file and added AK/Platform.h, but was unable to get rid of #ifdef. |
Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest |
Use <AK/Windows.h> instead of windows.h/winsock2.h to avoid timeval-related errors. Note: winsock2.h includes windows.h
Use <AK/windows.h> instead of windows.h/winsock2.h to avoid timeval-related errors.