Skip to content

Commit 674075f

Browse files
trflynn89AtkinsSJ
authored andcommitted
Everywhere: Remove LibCore/System.h includes from header files
This reduces the number of compilation jobs when System.h changes from about 750 to 60. (There are still a large number of linker jobs.)
1 parent 58b3281 commit 674075f

19 files changed

+155
-97
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025, the Ladybird developers.
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <LibCore/System.h>
8+
#include <LibIPC/AutoCloseFileDescriptor.h>
9+
10+
namespace IPC {
11+
12+
AutoCloseFileDescriptor::AutoCloseFileDescriptor(int fd)
13+
: m_fd(fd)
14+
{
15+
}
16+
17+
AutoCloseFileDescriptor::~AutoCloseFileDescriptor()
18+
{
19+
if (m_fd != -1)
20+
(void)Core::System::close(m_fd);
21+
}
22+
23+
}

Libraries/LibIPC/AutoCloseFileDescriptor.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,19 @@
77
#pragma once
88

99
#include <AK/RefCounted.h>
10-
#include <LibCore/System.h>
1110

1211
namespace IPC {
1312

1413
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
1514
public:
16-
AutoCloseFileDescriptor(int fd)
17-
: m_fd(fd)
18-
{
19-
}
20-
21-
~AutoCloseFileDescriptor()
22-
{
23-
if (m_fd != -1)
24-
(void)Core::System::close(m_fd);
25-
}
15+
explicit AutoCloseFileDescriptor(int fd);
16+
~AutoCloseFileDescriptor();
2617

2718
int value() const { return m_fd; }
28-
29-
int take_fd()
30-
{
31-
int fd = m_fd;
32-
m_fd = -1;
33-
return fd;
34-
}
19+
int take_fd() { return exchange(m_fd, -1); }
3520

3621
private:
37-
int m_fd;
22+
int m_fd { -1 };
3823
};
3924

4025
}

Libraries/LibIPC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(SOURCES
2+
AutoCloseFileDescriptor.cpp
23
Connection.cpp
34
Decoder.cpp
45
Encoder.cpp

Libraries/LibIPC/File.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,65 @@
11
/*
22
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
33
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
4-
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
4+
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
55
*
66
* SPDX-License-Identifier: BSD-2-Clause
77
*/
88

9+
#include <LibCore/File.h>
10+
#include <LibCore/System.h>
911
#include <LibIPC/Decoder.h>
1012
#include <LibIPC/File.h>
1113

1214
namespace IPC {
1315

16+
File File::adopt_file(NonnullOwnPtr<Core::File> file)
17+
{
18+
return File(file->leak_fd());
19+
}
20+
21+
File File::adopt_fd(int fd)
22+
{
23+
return File(fd);
24+
}
25+
26+
ErrorOr<File> File::clone_fd(int fd)
27+
{
28+
int new_fd = TRY(Core::System::dup(fd));
29+
return File(new_fd);
30+
}
31+
32+
File::File(int fd)
33+
: m_fd(fd)
34+
{
35+
}
36+
37+
File::File(File&& other)
38+
: m_fd(exchange(other.m_fd, -1))
39+
{
40+
}
41+
42+
File& File::operator=(File&& other)
43+
{
44+
if (this != &other) {
45+
m_fd = exchange(other.m_fd, -1);
46+
}
47+
return *this;
48+
}
49+
50+
File::~File()
51+
{
52+
if (m_fd != -1)
53+
(void)Core::System::close(m_fd);
54+
}
55+
56+
// FIXME: IPC::Files transferred over the wire always set O_CLOEXEC during decoding. Perhaps we should add an option to
57+
// allow the receiver to decide whether to make it O_CLOEXEC or not. Or an attribute in the .ipc file?
58+
ErrorOr<void> File::clear_close_on_exec()
59+
{
60+
return Core::System::set_close_on_exec(m_fd, false);
61+
}
62+
1463
template<>
1564
ErrorOr<File> decode(Decoder& decoder)
1665
{

Libraries/LibIPC/File.h

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
#include <AK/Noncopyable.h>
1111
#include <AK/StdLibExtras.h>
12-
#include <LibCore/File.h>
13-
#include <LibCore/System.h>
12+
#include <LibCore/Forward.h>
1413

1514
namespace IPC {
1615

@@ -20,62 +19,24 @@ class File {
2019
public:
2120
File() = default;
2221

23-
static File adopt_file(NonnullOwnPtr<Core::File> file)
24-
{
25-
return File(file->leak_fd());
26-
}
22+
static File adopt_file(NonnullOwnPtr<Core::File> file);
23+
static File adopt_fd(int fd);
24+
static ErrorOr<File> clone_fd(int fd);
2725

28-
static File adopt_fd(int fd)
29-
{
30-
return File(fd);
31-
}
26+
File(File&& other);
27+
File& operator=(File&& other);
3228

33-
static ErrorOr<File> clone_fd(int fd)
34-
{
35-
int new_fd = TRY(Core::System::dup(fd));
36-
return File(new_fd);
37-
}
38-
39-
File(File&& other)
40-
: m_fd(exchange(other.m_fd, -1))
41-
{
42-
}
43-
44-
File& operator=(File&& other)
45-
{
46-
if (this != &other) {
47-
m_fd = exchange(other.m_fd, -1);
48-
}
49-
return *this;
50-
}
51-
52-
~File()
53-
{
54-
if (m_fd != -1)
55-
(void)Core::System::close(m_fd);
56-
}
29+
~File();
5730

5831
int fd() const { return m_fd; }
5932

60-
// NOTE: This is 'const' since generated IPC messages expose all parameters by const reference.
61-
[[nodiscard]] int take_fd() const
62-
{
63-
return exchange(m_fd, -1);
64-
}
33+
// This is 'const' since generated IPC messages expose all parameters by const reference.
34+
[[nodiscard]] int take_fd() const { return exchange(m_fd, -1); }
6535

66-
// FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding.
67-
// Perhaps we should add an option to IPC::File to allow the receiver to decide whether to
68-
// make it O_CLOEXEC or not. Or an attribute in the .ipc file?
69-
ErrorOr<void> clear_close_on_exec()
70-
{
71-
return Core::System::set_close_on_exec(m_fd, false);
72-
}
36+
ErrorOr<void> clear_close_on_exec();
7337

7438
private:
75-
explicit File(int fd)
76-
: m_fd(fd)
77-
{
78-
}
39+
explicit File(int fd);
7940

8041
mutable int m_fd { -1 };
8142
};

Libraries/LibIPC/SingleServer.h

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

77
#pragma once
88

9-
#include <LibCore/System.h>
109
#include <LibCore/SystemServerTakeover.h>
1110
#include <LibIPC/ConnectionFromClient.h>
1211

Libraries/LibRequests/Request.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7+
#include <LibCore/File.h>
78
#include <LibRequests/Request.h>
89
#include <LibRequests/RequestClient.h>
910

Libraries/LibWeb/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ set(SOURCES
592592
HTML/NavigationTransition.cpp
593593
HTML/Navigator.cpp
594594
HTML/NavigatorBeacon.cpp
595+
HTML/NavigatorConcurrentHardware.cpp
596+
HTML/NavigatorDeviceMemory.cpp
595597
HTML/NavigatorID.cpp
596598
HTML/Numbers.cpp
597599
HTML/OffscreenCanvas.cpp
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
3+
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
4+
*
5+
* SPDX-License-Identifier: BSD-2-Clause
6+
*/
7+
8+
#include <LibCore/System.h>
9+
#include <LibWeb/HTML/NavigatorConcurrentHardware.h>
10+
11+
namespace Web::HTML {
12+
13+
// https://html.spec.whatwg.org/multipage/workers.html#dom-navigator-hardwareconcurrency
14+
WebIDL::UnsignedLongLong NavigatorConcurrentHardwareMixin::hardware_concurrency()
15+
{
16+
return Core::System::hardware_concurrency();
17+
}
18+
19+
}

Libraries/LibWeb/HTML/NavigatorConcurrentHardware.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
#pragma once
99

10-
#include <LibCore/System.h>
1110
#include <LibWeb/WebIDL/Types.h>
1211

1312
namespace Web::HTML {
1413

1514
class NavigatorConcurrentHardwareMixin {
1615
public:
17-
// https://html.spec.whatwg.org/multipage/workers.html#dom-navigator-hardwareconcurrency
18-
static WebIDL::UnsignedLongLong hardware_concurrency() { return Core::System::hardware_concurrency(); }
16+
static WebIDL::UnsignedLongLong hardware_concurrency();
1917
};
2018

2119
}

0 commit comments

Comments
 (0)