Skip to content

Commit 82d8f7d

Browse files
committed
fix compilation for linux
1 parent 8152fa9 commit 82d8f7d

14 files changed

+59
-23
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
cmake_minimum_required(VERSION 3.20)
1+
cmake_minimum_required(VERSION 3.0.0)
22
project(sandbox VERSION 0.1.0)
3-
set(CMAKE_CXX_STANDARD 23)
3+
set(CMAKE_CXX_STANDARD 20)
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
55

66
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

Source/Library/Date.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#include "Date.hpp"
21
#include <chrono>
2+
#include "DetectOs.hpp"
3+
4+
// skip for linux for now, c++20 must be fully implemented for clang - linux
5+
#ifdef WINDOWS
6+
7+
#include "Date.hpp"
38
#include <format>
49

510
namespace sd
@@ -291,4 +296,6 @@ namespace sd
291296
Years operator"" _y(unsigned long long years) { return Years(static_cast<int>(years)); }
292297
Months operator"" _mo(unsigned long long months) { return Months(static_cast<int>(months)); }
293298

294-
} // namespace sd
299+
} // namespace sd
300+
301+
#endif

Source/Library/MemoryManager.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#include <setjmp.h>
22

33
#include "MemoryManager.hpp"
4+
#include "DetectOs.hpp"
45

5-
#ifdef _WIN32
6+
#ifdef WINDOWS
67

78
#include <windows.h>
89

910
#include <processthreadsapi.h>
1011

11-
#define WINDOWS
1212
#endif
1313

14-
#ifdef linux
14+
#ifdef LINUX
1515

1616
#include <iostream>
1717
#include <stdio.h>
@@ -20,15 +20,14 @@
2020
#include <termios.h>
2121
#include <unistd.h>
2222

23-
#define LINUX
2423
#endif
2524

2625
namespace sd
2726
{
2827
namespace
2928
{
3029

31-
// #define __READ_RBP() __asm__ volatile("movq %%rbp, %0" : "=r"(__rbp))
30+
#define __READ_RBP(rbp) __asm__ volatile("movq %%rbp, %0" : "=r"(rbp))
3231
#define __READ_RSP(rsp) __asm__ volatile("movq %%rsp, %0" : "=r"(rsp))
3332

3433
#ifdef WINDOWS
@@ -45,6 +44,17 @@ namespace sd
4544
}
4645

4746
#endif
47+
#ifdef LINUX
48+
auto getStackBounds()
49+
{
50+
intptr_t *rsp, rbp;
51+
__READ_RSP(rsp);
52+
__READ_RBP(rbp);
53+
return std::make_tuple((uint8_t *)rbp , (uint8_t *)rsp, (uint8_t *)rsp);
54+
}
55+
56+
#endif
57+
4858
} // namespace
4959

5060
MemoryManager &MemoryManager::instance()

Source/Library/Time.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include "Time.hpp"
22
#include <chrono>
33
#include <cmath>
4-
#include <format>
54
#include <tuple>
65

6+
#include "DetectOs.hpp"
7+
8+
#ifdef WINDOWS
9+
#include <format>
10+
711
namespace sd
812
{
913

@@ -154,4 +158,5 @@ namespace sd
154158
{
155159
return Time::fromMicroseconds(static_cast<long long>(microseconds));
156160
}
157-
} // namespace sd
161+
} // namespace sd
162+
#endif

Source/Library/h/Date.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#pragma once
33
#include <chrono>
4+
#include <string>
45

56
#include "Time.hpp"
67

Source/Library/h/DetectOs.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifdef _WIN32
2+
3+
#define WINDOWS
4+
#endif
5+
6+
#ifdef linux
7+
8+
#define LINUX
9+
#endif

Source/Library/h/LinkedList.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <format>
32
#include <iostream>
43
#include <string>
54

@@ -60,8 +59,10 @@ namespace sd
6059
public:
6160
using iterator_category = std::bidirectional_iterator_tag;
6261
using value_type = T;
63-
using pointer = T *;
64-
using reference = T &;
62+
using pointer = value_type *;
63+
using difference_type = std::ptrdiff_t;
64+
using const_pointer = const value_type*;
65+
using reference = value_type &;
6566
using NodePtr =
6667
std::conditional_t<std::is_const<T>::value, const ListNode<std::remove_cv_t<T>> *, ListNode<T> *>;
6768

Source/Library/h/Map.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <format>
32
#include <iostream>
43
#include <tuple>
54
#include <utility>

Source/Library/h/MemoryManager.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "MemoryManager.hpp"
44
#include <algorithm>
55
#include <unordered_map>
6-
#include <vcruntime.h>
76

87
namespace sd
98
{

Source/Library/h/Time.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#pragma once
33
#include <chrono>
4+
#include <string>
45

56
namespace sd
67
{

Source/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <iostream>
22
#include <unordered_set>
33

4-
#include "LinkedList.hpp"
5-
#include "Map.hpp"
64
#include "MemoryManager.hpp"
75

86
int main(int, char **) { return 0; }

Tests/DateTest.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <iostream>
44
#include <stdexcept>
55
#include <thread>
6+
#include "DetectOs.hpp"
67

8+
#ifdef WINDOWS
79
#include "Date.hpp"
810

911
using namespace sd;
@@ -1032,4 +1034,6 @@ TEST_F(DateTest, TryParseHoursAndMinutesSuccessTest)
10321034
EXPECT_EQ(date, (Date{2011y / January / 12, 9_h + 19_min + 11_s + 13_ms + 20_us}));
10331035
}
10341036

1035-
#pragma endregion
1037+
#pragma endregion
1038+
1039+
#endif

Tests/MemoryManagerTest.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <cstddef>
2-
#include <format>
32
#include <gtest/gtest.h>
43
#include <iostream>
54
#include <memory>
@@ -184,8 +183,8 @@ TEST_F(MemoryManagerTest, ManagersShouldWorkInSeparateThreads)
184183
std::vector<ExampleClass *> destructorR1;
185184
std::vector<ExampleClass *> destructorR2;
186185

187-
std::jthread r1{runner, std::ref(destructorR1)};
188-
std::jthread r2{runner, std::ref(destructorR2)};
186+
std::thread r1{runner, std::ref(destructorR1)};
187+
std::thread r2{runner, std::ref(destructorR2)};
189188

190189
r1.join();
191190
r2.join();

Tests/TimeTest.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include <gtest/gtest.h>
33
#include <iostream>
44
#include <thread>
5+
#include "DetectOs.hpp"
56

7+
#ifdef WINDOWS
68
#include "Date.hpp"
79

810
using namespace sd;
@@ -671,4 +673,5 @@ TEST_F(TimeTest, ParseHoursAndMinutesTest)
671673
EXPECT_EQ(time, (Time{0, 2, 1, 0}));
672674
}
673675

674-
#pragma endregion
676+
#pragma endregion
677+
#endif

0 commit comments

Comments
 (0)