Skip to content

Commit eecdb3d

Browse files
authored
Fix some sign conversions, CI cleanup (#170)
* cmake: add -Wconversion to default flags Signed-off-by: William Woodruff <[email protected]> * workflows/ci: use ubuntu-latest Signed-off-by: William Woodruff <[email protected]> * parse: avoid an implicit conversion Signed-off-by: William Woodruff <[email protected]> * parse: use static_cast Signed-off-by: William Woodruff <[email protected]> * include/parse: remove some more implicit conversions Signed-off-by: William Woodruff <[email protected]> * parse: clang-format Signed-off-by: William Woodruff <[email protected]> * cmake: remove -Wconversion Signed-off-by: William Woodruff <[email protected]> * pepy: Python 3.7 or newer Signed-off-by: William Woodruff <[email protected]> * workflows/ci: bump actions, use pypa/build Signed-off-by: William Woodruff <[email protected]> * workflows/ci: fix windows pepy matrix Signed-off-by: William Woodruff <[email protected]> * setup: macro tweaks Signed-off-by: William Woodruff <[email protected]> * setup: escape harder Signed-off-by: William Woodruff <[email protected]> * ci, setup: drop python 3.7 This setuptools bug isn't worth working around. Signed-off-by: William Woodruff <[email protected]> * Revert "ci, setup: drop python 3.7" This reverts commit d059983. * workflows/ci: update setuptools Signed-off-by: William Woodruff <[email protected]> * setup: remove escape Signed-off-by: William Woodruff <[email protected]>
1 parent 8d8daa5 commit eecdb3d

File tree

4 files changed

+59
-49
lines changed

4 files changed

+59
-49
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77
pull_request:
88
schedule:
99
# run CI every day even if no PRs/merges occur
10-
- cron: '0 12 * * *'
10+
- cron: '0 12 * * *'
1111

1212
jobs:
1313
lint:
14-
runs-on: ubuntu-18.04
14+
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717

1818
- name: deps
1919
run: |
@@ -30,7 +30,7 @@ jobs:
3030
pe-parse:
3131
strategy:
3232
matrix:
33-
platform: ["ubuntu-18.04", "macos-latest"]
33+
platform: ["ubuntu-latest", "macos-latest"]
3434
build-type: ["Debug", "Release"]
3535
build-shared: ["0", "1"]
3636
compiler:
@@ -41,14 +41,9 @@ jobs:
4141
compiler: { CC: "gcc", CXX: "g++" }
4242
runs-on: ${{ matrix.platform }}
4343
steps:
44-
- uses: actions/checkout@v2
44+
- uses: actions/checkout@v3
4545
with:
4646
submodules: 'true'
47-
# https://github.com/actions/virtual-environments/issues/3376
48-
- name: Workaround GHA Issue with GCC 11
49-
if: matrix.compiler.CC == 'clang' && matrix.platform == 'ubuntu-18.04'
50-
run: |
51-
sudo apt remove libgcc-11-dev gcc-11
5247
- name: Enable ASan+UBSan Sanitizers
5348
if: matrix.build-type == 'Debug'
5449
run: |
@@ -78,27 +73,32 @@ jobs:
7873
pepy:
7974
strategy:
8075
matrix:
81-
platform: ["ubuntu-18.04", "macos-latest"]
76+
platform: ["ubuntu-latest", "macos-latest"]
8277
python:
83-
- "3.6"
8478
- "3.7"
8579
- "3.8"
80+
- "3.9"
81+
- "3.10"
8682
runs-on: ${{ matrix.platform }}
8783
steps:
88-
- uses: actions/checkout@v2
89-
- uses: actions/setup-python@v2
84+
- uses: actions/checkout@v3
85+
- uses: actions/setup-python@v3
9086
with:
9187
python-version: ${{ matrix.python }}
9288
- name: build
9389
run: |
94-
python3 setup.py build
95-
- name: sdist and install
96-
run: |
97-
python3 setup.py sdist
98-
python3 -m pip install --user dist/*.tar.gz
99-
- name: test
90+
python -m pip install build wheel setuptools
91+
python -m build
92+
- name: test distributions
10093
run: |
101-
python3 tests/test_pepy.py tests/assets/example.exe
94+
for dist in dist/*; do
95+
python -m venv test-env
96+
97+
./test-env/bin/python -m pip install "${dist}"
98+
./test-env/bin/python tests/test_pepy.py tests/assets/example.exe
99+
100+
rm -rf test-env
101+
done
102102
103103
pe-parse-windows:
104104
strategy:
@@ -108,7 +108,7 @@ jobs:
108108
build-shared: ["0", "1"]
109109
runs-on: windows-2019
110110
steps:
111-
- uses: actions/checkout@v2
111+
- uses: actions/checkout@v3
112112
with:
113113
submodules: 'true'
114114
- name: Enable ASan Sanitizers
@@ -147,18 +147,20 @@ jobs:
147147
strategy:
148148
matrix:
149149
python:
150-
- "3.6"
151150
- "3.7"
152151
- "3.8"
152+
- "3.9"
153+
- "3.10"
153154
runs-on: windows-latest
154155
steps:
155-
- uses: actions/checkout@v2
156-
- uses: actions/setup-python@v2
156+
- uses: actions/checkout@v3
157+
- uses: actions/setup-python@v3
157158
with:
158159
python-version: ${{ matrix.python }}
159160
- name: build
160161
run: |
161-
python setup.py build
162+
python -m pip install --upgrade build wheel setuptools
163+
python -m build
162164
- name: install
163165
run: |
164166
python -m pip install --user .

pe-parser-library/include/pe-parse/parse.h

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,38 @@ THE SOFTWARE.
4040
err_loc.assign(__func__); \
4141
err_loc += ":" + to_string<std::uint32_t>(__LINE__, std::dec);
4242

43-
#define READ_WORD(b, o, inst, member) \
44-
if (!readWord(b, o + offsetof(__typeof__(inst), member), inst.member)) { \
45-
PE_ERR(PEERR_READ); \
46-
return false; \
43+
#define READ_WORD(b, o, inst, member) \
44+
if (!readWord(b, \
45+
o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
46+
inst.member)) { \
47+
PE_ERR(PEERR_READ); \
48+
return false; \
4749
}
4850

49-
#define READ_DWORD(b, o, inst, member) \
50-
if (!readDword(b, o + offsetof(__typeof__(inst), member), inst.member)) { \
51-
PE_ERR(PEERR_READ); \
52-
return false; \
51+
#define READ_DWORD(b, o, inst, member) \
52+
if (!readDword( \
53+
b, \
54+
o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
55+
inst.member)) { \
56+
PE_ERR(PEERR_READ); \
57+
return false; \
5358
}
5459

55-
#define READ_QWORD(b, o, inst, member) \
56-
if (!readQword(b, o + offsetof(__typeof__(inst), member), inst.member)) { \
57-
PE_ERR(PEERR_READ); \
58-
return false; \
60+
#define READ_QWORD(b, o, inst, member) \
61+
if (!readQword( \
62+
b, \
63+
o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
64+
inst.member)) { \
65+
PE_ERR(PEERR_READ); \
66+
return false; \
5967
}
6068

61-
#define READ_BYTE(b, o, inst, member) \
62-
if (!readByte(b, o + offsetof(__typeof__(inst), member), inst.member)) { \
63-
PE_ERR(PEERR_READ); \
64-
return false; \
69+
#define READ_BYTE(b, o, inst, member) \
70+
if (!readByte(b, \
71+
o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
72+
inst.member)) { \
73+
PE_ERR(PEERR_READ); \
74+
return false; \
6575
}
6676

6777
#define TEST_MACHINE_CHARACTERISTICS(h, m, ch) \

pe-parser-library/src/parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ bool getRelocations(parsed_pe *p) {
17771777
// Mask out the type and assign
17781778
type = entry >> 12;
17791779
// Mask out the offset and assign
1780-
offset = entry & ~0xf000;
1780+
offset = entry & static_cast<std::uint16_t>(~0xf000);
17811781

17821782
// Produce the VA of the relocation
17831783
VA relocVA;

setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@
6060
os.path.abspath(os.path.join(os.path.dirname(sys.executable), "libs")),
6161
"C:\\usr\\lib",
6262
]
63-
COMPILE_ARGS = [
64-
"/EHsc",
65-
f'/D"PEPARSE_VERSION=\\"{VERSION}\\""',
66-
]
63+
COMPILE_ARGS = ["/EHsc"]
6764
else:
6865
SOURCE_FILES.append(
6966
os.path.join(here, "pe-parser-library", "src", "unicode_codecvt.cpp")
@@ -75,10 +72,11 @@
7572
os.path.join(here, "pe-parser-library", "include"),
7673
]
7774
LIBRARY_DIRS += ["/usr/lib", "/usr/local/lib"]
78-
COMPILE_ARGS = ["-std=c++11", f'-DPEPARSE_VERSION="{VERSION}"']
75+
COMPILE_ARGS = ["-std=c++17"]
7976

8077
extension_mod = Extension(
8178
"pepy",
79+
define_macros=[("PEPARSE_VERSION", f'"{VERSION}"')],
8280
sources=SOURCE_FILES,
8381
extra_compile_args=COMPILE_ARGS,
8482
language="c++",
@@ -89,7 +87,7 @@
8987
setup(
9088
name="pepy",
9189
url="https://github.com/trailofbits/pe-parse",
92-
python_requires=">= 3.6",
90+
python_requires=">=3.7",
9391
version=VERSION,
9492
description="Python bindings for pe-parse",
9593
long_description=README,

0 commit comments

Comments
 (0)