Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 8195bfe

Browse files
committed
feat: std::kallocator
fix: VS2019 build error. build: revise
1 parent b0e7656 commit 8195bfe

File tree

8 files changed

+282
-86
lines changed

8 files changed

+282
-86
lines changed

.github/workflows/build.bat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ if exist bin rd /s /q bin
1313
if exist lib rd /s /q lib
1414
if exist ucxxrt rd /s /q ucxxrt
1515

16-
%msbuild% -p:Configuration=Debug -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
17-
%msbuild% -p:Configuration=Release -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
16+
%msbuild% -m -p:Configuration=Debug -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
17+
%msbuild% -m -p:Configuration=Release -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
1818

19-
%msbuild% -p:Configuration=Debug -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
20-
%msbuild% -p:Configuration=Release -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
19+
%msbuild% -m -p:Configuration=Debug -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
20+
%msbuild% -m -p:Configuration=Release -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
2121

22-
%msbuild% -p:Configuration=Debug -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
23-
%msbuild% -p:Configuration=Release -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
22+
%msbuild% -m -p:Configuration=Debug -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
23+
%msbuild% -m -p:Configuration=Release -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
2424

25-
%msbuild% -p:Configuration=Debug -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
26-
%msbuild% -p:Configuration=Release -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
25+
%msbuild% -m -p:Configuration=Debug -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
26+
%msbuild% -m -p:Configuration=Release -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
2727

2828
:exit
2929
popd

.github/workflows/build.yaml

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is a basic workflow to help you get started with Actions
22

3-
name: build & publish
3+
name: build
44

55
# Controls when the action will run. Triggers the workflow on push or pull request
66
# events but only for the master branch
@@ -28,45 +28,12 @@ jobs:
2828
with:
2929
submodules: true
3030

31-
#- name: setup wdk.vsix
32-
# shell: pwsh
33-
# run: |
34-
# $FilePath = Resolve-Path "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix"
35-
# Install-VsixExtension -FilePath $FilePath -Name "WDK.vsix" -VSversion "2022" -InstallOnly
36-
3731
- name: enable X86 and ARM build support
3832
working-directory: ${{github.workspace}}
3933
shell: pwsh
4034
run: |
4135
.\.github\workflows\EnableX86AndARM.ps1
4236
43-
- name: build nuspec
44-
if: contains(github.ref, 'tags/')
45-
working-directory: ${{github.workspace}}
46-
shell: pwsh
47-
run: |
48-
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
49-
{
50-
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
51-
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
52-
53-
# github的内置版本有Bug,此行必须添加,否则无法获得内容
54-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
55-
56-
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
57-
$content = [System.IO.File]::ReadAllText("nuget\ucxxrt.nuspec")
58-
59-
$releaseNotesToken = '$releaseNotes$'
60-
$releaseNotesIndex = $content.IndexOf($releaseNotesToken)
61-
62-
if($releaseNotesIndex -ne -1)
63-
{
64-
echo $content.Substring(0, $releaseNotesIndex) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline
65-
echo $releaseNotes | out-file "nuget\ucxxrt-new.nuspec" -Append
66-
echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline -Append
67-
}
68-
}
69-
7037
- name: compile
7138
working-directory: ${{github.workspace}}
7239
shell: cmd
@@ -78,38 +45,3 @@ jobs:
7845
name: ucxxrt
7946
path: ucxxrt\
8047
if-no-files-found: error
81-
82-
- name: pack zip
83-
if: contains(github.ref, 'tags/')
84-
working-directory: ${{github.workspace}}
85-
shell: cmd
86-
run: 7z a -tzip ucxxrt.zip ucxxrt\
87-
88-
- name: pack nuget
89-
if: contains(github.ref, 'tags/')
90-
working-directory: ${{github.workspace}}
91-
shell: cmd
92-
run: |
93-
if "${{env.BuildVersion}}" NEQ "" (
94-
nuget pack nuget\ucxxrt-new.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA%
95-
)
96-
97-
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
98-
99-
- name: publish a version
100-
if: contains(github.ref, 'tags/')
101-
uses: "marvinpinto/action-automatic-releases@v1.2.1"
102-
with:
103-
repo_token: "${{ secrets.GITHUB_TOKEN }}"
104-
prerelease: false
105-
files: |
106-
ucxxrt.zip
107-
*.nupkg
108-
109-
- name: publish nuget
110-
if: contains(github.ref, 'tags/')
111-
working-directory: ${{github.workspace}}
112-
shell: cmd
113-
run: |
114-
nuget push ucxxrt.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
115-
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%

.github/workflows/publish.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: publish
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
tags:
10+
- v*
11+
12+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
13+
jobs:
14+
# This workflow contains a single job called "build"
15+
build:
16+
# The type of runner that the job will run on
17+
runs-on: windows-2022
18+
19+
# Any commit that contains [build] will now trigger these jobs, everything else will be skipped.
20+
# if: "contains(github.event.head_commit.message, '[build]')"
21+
22+
# Steps represent a sequence of tasks that will be executed as part of the job
23+
steps:
24+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25+
- uses: actions/checkout@v3
26+
with:
27+
submodules: true
28+
29+
#- name: setup wdk.vsix
30+
# shell: pwsh
31+
# run: |
32+
# $FilePath = Resolve-Path "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix"
33+
# Install-VsixExtension -FilePath $FilePath -Name "WDK.vsix" -VSversion "2022" -InstallOnly
34+
35+
- name: enable X86 and ARM build support
36+
working-directory: ${{github.workspace}}
37+
shell: pwsh
38+
run: |
39+
.\.github\workflows\EnableX86AndARM.ps1
40+
41+
- name: build nuspec
42+
if: contains(github.ref, 'tags/')
43+
working-directory: ${{github.workspace}}
44+
shell: pwsh
45+
run: |
46+
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
47+
{
48+
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
49+
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
50+
51+
# github的内置版本有Bug,此行必须添加,否则无法获得内容
52+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
53+
54+
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
55+
$content = [System.IO.File]::ReadAllText("nuget\ucxxrt.nuspec")
56+
57+
$releaseNotesToken = '$releaseNotes$'
58+
$releaseNotesIndex = $content.IndexOf($releaseNotesToken)
59+
60+
if($releaseNotesIndex -ne -1)
61+
{
62+
echo $content.Substring(0, $releaseNotesIndex) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline
63+
echo $releaseNotes | out-file "nuget\ucxxrt-new.nuspec" -Append
64+
echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline -Append
65+
}
66+
}
67+
68+
- name: compile
69+
working-directory: ${{github.workspace}}
70+
shell: cmd
71+
run: call .\.github\workflows\build.bat
72+
73+
- name: upload an artifact
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: ucxxrt
77+
path: ucxxrt\
78+
if-no-files-found: error
79+
80+
- name: pack zip
81+
if: contains(github.ref, 'tags/')
82+
working-directory: ${{github.workspace}}
83+
shell: cmd
84+
run: 7z a -tzip ucxxrt.zip ucxxrt\
85+
86+
- name: pack nuget
87+
if: contains(github.ref, 'tags/')
88+
working-directory: ${{github.workspace}}
89+
shell: cmd
90+
run: |
91+
if "${{env.BuildVersion}}" NEQ "" (
92+
nuget pack nuget\ucxxrt-new.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA%
93+
)
94+
95+
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
96+
97+
- name: publish a version
98+
if: contains(github.ref, 'tags/')
99+
uses: "marvinpinto/action-automatic-releases@v1.2.1"
100+
with:
101+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
102+
prerelease: false
103+
files: |
104+
ucxxrt.zip
105+
*.nupkg
106+
107+
- name: publish nuget
108+
if: contains(github.ref, 'tags/')
109+
working-directory: ${{github.workspace}}
110+
shell: cmd
111+
run: |
112+
nuget push ucxxrt.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
113+
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%

kext/kallocator.h

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* PROJECT: Universal C++ RunTime (UCXXRT)
3+
* FILE: kallocator.cpp
4+
* DATA: 2022/11/19
5+
*
6+
* PURPOSE: Universal C++ RunTime
7+
*
8+
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
9+
*
10+
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com)
11+
*/
12+
13+
#pragma once
14+
#include <yvals.h>
15+
#include "knew.h"
16+
#include <type_traits>
17+
18+
_STD_BEGIN
19+
20+
#ifndef _HAS_DEPRECATED_ALLOCATOR_MEMBERS
21+
#define _HAS_DEPRECATED_ALLOCATOR_MEMBERS 1
22+
#endif
23+
24+
#ifndef _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
25+
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
26+
#endif
27+
28+
#ifndef _NODISCARD_RAW_PTR_ALLOC
29+
#define _NODISCARD_RAW_PTR_ALLOC _NODISCARD
30+
#endif
31+
32+
33+
template <class T>
34+
_NODISCARD constexpr void* ___voidify_iter(T iter) noexcept {
35+
if constexpr (::std::is_pointer_v<T>) {
36+
return const_cast<void*>(static_cast<const volatile void*>(iter));
37+
}
38+
else {
39+
return const_cast<void*>(static_cast<const volatile void*>(::std::addressof(*iter)));
40+
}
41+
}
42+
43+
template <typename T, POOL_TYPE _Pool = PagedPool, unsigned long _Tag = 'trcu'>
44+
class kallocator {
45+
public:
46+
static_assert(!::std::is_const_v<T>, "The C++ Standard forbids containers of const elements "
47+
"because kallocator<const T> is ill-formed.");
48+
49+
using value_type = T;
50+
using size_type = size_t;
51+
using difference_type = ptrdiff_t;
52+
using propagate_on_container_move_assignment = true_type;
53+
54+
#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
55+
using pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = T*;
56+
using const_pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const T*;
57+
using reference _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = T&;
58+
using const_reference _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const T&;
59+
using is_always_equal _CXX20_DEPRECATE_IS_ALWAYS_EQUAL = true_type;
60+
61+
template <typename N>
62+
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
63+
using other = kallocator<N, _Pool, _Tag>;
64+
};
65+
66+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD T* address(T& value) const noexcept {
67+
return ::std::addressof(value);
68+
}
69+
70+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD const T* address(const T& value) const noexcept {
71+
return ::std::addressof(value);
72+
}
73+
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS
74+
75+
constexpr kallocator() noexcept {}
76+
constexpr kallocator(const kallocator&) noexcept = default;
77+
78+
template <typename N>
79+
constexpr kallocator(const kallocator<N, _Pool, _Tag>&) noexcept {}
80+
_CONSTEXPR20 ~kallocator() = default;
81+
_CONSTEXPR20 kallocator& operator=(const kallocator&) = default;
82+
83+
_CONSTEXPR20 void deallocate(T* const ptr, const size_t count) {
84+
_STL_ASSERT(ptr != nullptr || count == 0, "null pointer cannot point to a block of non-zero size");
85+
__noop(count); // ignore
86+
87+
// no overflow check on the following multiply; we assume allocate did that check
88+
::operator delete(ptr, _Pool, _Tag);
89+
}
90+
91+
_NODISCARD_RAW_PTR_ALLOC _CONSTEXPR20 __declspec(allocator) T* allocate(const size_t count) {
92+
static_assert(sizeof(value_type) > 0, "value_type must be complete before calling allocate.");
93+
return static_cast<T*>(::operator new(sizeof(T) * count, _Pool, _Tag));
94+
}
95+
96+
#if _HAS_CXX23
97+
_NODISCARD_RAW_PTR_ALLOC constexpr allocation_result<T*> allocate_at_least(
98+
_CRT_GUARDOVERFLOW const size_t count) {
99+
return { allocate(count), count };
100+
}
101+
#endif // _HAS_CXX23
102+
103+
#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
104+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD_RAW_PTR_ALLOC __declspec(allocator) T* allocate(
105+
_CRT_GUARDOVERFLOW const size_t count, const void*) {
106+
return allocate(count);
107+
}
108+
109+
template <typename N, typename... Ns>
110+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS void construct(N* const ptr, Ns&&... args) {
111+
::new (___voidify_iter(ptr)) N(::std::forward<Ns>(args)...);
112+
}
113+
114+
template <typename N>
115+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS void destroy(N* const object) {
116+
object->~N();
117+
}
118+
119+
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD size_t max_size() const noexcept {
120+
return static_cast<size_t>(-1) / sizeof(T);
121+
}
122+
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS
123+
};
124+
125+
126+
#if _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS
127+
template <>
128+
class kallocator<void> {
129+
public:
130+
using value_type = void;
131+
132+
#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
133+
using pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = void*;
134+
using const_pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const void*;
135+
136+
template <class N>
137+
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
138+
using other = kallocator<N>;
139+
};
140+
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS
141+
142+
#if _HAS_CXX20
143+
using size_type = size_t;
144+
using difference_type = ptrdiff_t;
145+
146+
using propagate_on_container_move_assignment = true_type;
147+
using is_always_equal _CXX20_DEPRECATE_IS_ALWAYS_EQUAL = true_type;
148+
#endif // _HAS_CXX20
149+
};
150+
#endif // _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS
151+
152+
153+
_STD_END

src/crt/stl/excptptr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" _CRTIMP2 void* __cdecl __AdjustPointer(void*, const PMD&); // defined
3838
using namespace std;
3939

4040
#ifndef _MSVC_NOOP_DTOR
41-
#define _MSVC_NOOP_DTOR [[msvc::noop_dtor]]
41+
#define _MSVC_NOOP_DTOR
4242
#endif
4343

4444
namespace {

0 commit comments

Comments
 (0)