Skip to content

Commit c77ec4a

Browse files
authored
Merge pull request #647 from ajaust/fix/silent-some-warnings-pybindings
Silent warnings emitted by Python binding's build process
2 parents 988a1c0 + d127d60 commit c77ec4a

2 files changed

Lines changed: 100 additions & 2 deletions

File tree

.github/workflows/build.yaml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
test:
1212
runs-on: ${{ matrix.os }}
13-
name: Build and test ${{ matrix.build_type }} on ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.cmake_generator }}
13+
name: Build and test ${{ matrix.build_type }} on ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.cmake_generator }} BUILD_PYTHON=${{ matrix.build_python }}
1414
strategy:
1515
fail-fast: false
1616
matrix:
@@ -19,37 +19,56 @@ jobs:
1919
cmake_generator: "-G \"Visual Studio 17 2022\" -A x64"
2020
build_type: "Release"
2121
compiler_flags: "-D_CRT_SECURE_NO_WARNINGS /EHsc"
22+
build_python: "OFF"
2223
- os: windows-2022
2324
cmake_generator: "-G \"Visual Studio 17 2022\" -A x64"
2425
build_type: "Debug"
2526
compiler_flags: "-D_CRT_SECURE_NO_WARNINGS /EHsc"
27+
build_python: "OFF"
2628
- os: windows-2022
2729
cmake_generator: "-G \"Visual Studio 17 2022\" -A Win32"
2830
build_type: "Release"
2931
compiler_flags: "-D_CRT_SECURE_NO_WARNINGS /EHsc"
32+
build_python: "OFF"
3033
- os: ubuntu-latest
3134
privledges: "sudo"
3235
build_type: "Release"
36+
build_python: "OFF"
3337
- os: ubuntu-latest
3438
privledges: "sudo"
3539
build_type: "Debug"
3640
compiler_flags: "-Wextra -Wall -pedantic"
41+
build_python: "OFF"
42+
- os: ubuntu-latest
43+
privledges: "sudo"
44+
build_type: "Debug"
45+
compiler_flags: "-Wextra -Wall -pedantic"
46+
build_python: "ON"
3747
- os: ubuntu-latest
3848
privledges: "sudo"
3949
compiler: "clang"
4050
mkdoc: "-DBUILD_DOC=ON -DSPHINX_ARGS=-WT"
4151
build_type: "Release"
52+
build_python: "OFF"
4253
- os: ubuntu-latest
4354
privledges: "sudo"
4455
compiler: "clang"
4556
build_type: "Debug"
4657
compiler_flags: "-Wextra -Wall -pedantic"
58+
build_python: "OFF"
4759
- os: macos-13
4860
privledges: "sudo"
4961
build_type: "Release"
62+
build_python: "OFF"
5063
- os: macos-latest
5164
privledges: "sudo"
5265
build_type: "Release"
66+
build_python: "OFF"
67+
- os: macos-latest
68+
privledges: "sudo"
69+
build_type: "Debug"
70+
compiler_flags: "-Wextra -Wall -pedantic"
71+
build_python: "ON"
5372

5473
steps:
5574
- uses: actions/checkout@v4
@@ -62,12 +81,24 @@ jobs:
6281
echo "CC=/usr/bin/clang" >> $GITHUB_ENV
6382
echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV
6483
84+
# Required to be able to install Python packages on MacOS
85+
- uses: actions/setup-python@v6
86+
if: ${{ matrix.build_python == 'ON' }}
87+
with:
88+
python-version: '3.13'
89+
90+
- name: Install build/test for Python dependencies
91+
working-directory: python
92+
if: ${{ matrix.build_python == 'ON' }}
93+
run: |
94+
python3 -m pip install -r requirements-dev.txt
95+
6596
- name: Configure
6697
shell: bash
6798
run: |
6899
cmake -S . -B build \
69100
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
70-
-DBUILD_PYTHON=OFF \
101+
-DBUILD_PYTHON=${{ matrix.build_python }} \
71102
-DBUILD_SHARED_LIBS=ON \
72103
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
73104
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON \

python/segyio/segyio.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#define IS_PY3K
2525
#endif
2626

27+
#if defined(__GNUC__) && !defined(__clang__)
28+
#define IS_GCC
29+
#endif
30+
#if defined(__clang__)
31+
#define IS_CLANG
32+
#endif
33+
2734
namespace {
2835

2936
std::string segy_errstr( int err ) {
@@ -1753,6 +1760,16 @@ PyObject* stanza_names( segyfd* self ) {
17531760
return names;
17541761
}
17551762

1763+
#ifdef IS_CLANG
1764+
#pragma clang diagnostic push
1765+
#pragma clang diagnostic ignored "-Wcast-function-type"
1766+
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
1767+
#endif
1768+
#ifdef IS_GCC
1769+
#pragma GCC diagnostic push
1770+
#pragma GCC diagnostic ignored "-Wcast-function-type"
1771+
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
1772+
#endif
17561773
PyMethodDef methods [] = {
17571774
{ "segyopen", (PyCFunction) fd::segyopen,
17581775
METH_VARARGS | METH_KEYWORDS, "Open file." },
@@ -1797,9 +1814,23 @@ PyMethodDef methods [] = {
17971814

17981815
{ NULL }
17991816
};
1817+
#ifdef IS_GCC
1818+
#pragma GCC diagnostic pop
1819+
#endif
1820+
#ifdef IS_CLANG
1821+
#pragma clang diagnostic pop
1822+
#endif
18001823

18011824
}
18021825

1826+
#ifdef IS_CLANG
1827+
#pragma clang diagnostic push
1828+
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
1829+
#endif
1830+
#ifdef IS_GCC
1831+
#pragma GCC diagnostic push
1832+
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
1833+
#endif
18031834
PyTypeObject Segyfd = {
18041835
PyVarObject_HEAD_INIT( NULL, 0 )
18051836
"_segyio.segyfd", /* name */
@@ -1838,6 +1869,12 @@ PyTypeObject Segyfd = {
18381869
0, /* tp_dictoffset */
18391870
(initproc)fd::init, /* tp_init */
18401871
};
1872+
#ifdef IS_GCC
1873+
#pragma GCC diagnostic pop
1874+
#endif
1875+
#ifdef IS_CLANG
1876+
#pragma clang diagnostic pop
1877+
#endif
18411878

18421879
PyObject* binsize( PyObject* ) {
18431880
return PyLong_FromLong( segy_binheader_size() );
@@ -2166,6 +2203,16 @@ PyObject* format( PyObject* , PyObject* args ) {
21662203
return out;
21672204
}
21682205

2206+
#ifdef IS_CLANG
2207+
#pragma clang diagnostic push
2208+
#pragma clang diagnostic ignored "-Wcast-function-type"
2209+
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
2210+
#endif
2211+
#ifdef IS_GCC
2212+
#pragma GCC diagnostic push
2213+
#pragma GCC diagnostic ignored "-Wcast-function-type"
2214+
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
2215+
#endif
21692216
PyMethodDef SegyMethods[] = {
21702217
{ "binsize", (PyCFunction) binsize, METH_NOARGS, "Size of the binary header." },
21712218
{ "thsize", (PyCFunction) thsize, METH_NOARGS, "Size of the trace header." },
@@ -2182,6 +2229,12 @@ PyMethodDef SegyMethods[] = {
21822229

21832230
{ NULL }
21842231
};
2232+
#ifdef IS_GCC
2233+
#pragma GCC diagnostic pop
2234+
#endif
2235+
#ifdef IS_CLANG
2236+
#pragma clang diagnostic pop
2237+
#endif
21852238

21862239
namespace {
21872240

@@ -2709,13 +2762,27 @@ int extract_layout_stanza(
27092762

27102763
/* module initialization */
27112764
#ifdef IS_PY3K
2765+
#ifdef IS_CLANG
2766+
#pragma clang diagnostic push
2767+
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
2768+
#endif
2769+
#ifdef IS_GCC
2770+
#pragma GCC diagnostic push
2771+
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
2772+
#endif
27122773
static struct PyModuleDef segyio_module = {
27132774
PyModuleDef_HEAD_INIT,
27142775
"_segyio", /* name of module */
27152776
NULL, /* module documentation, may be NULL */
27162777
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
27172778
SegyMethods
27182779
};
2780+
#ifdef IS_GCC
2781+
#pragma GCC diagnostic pop
2782+
#endif
2783+
#ifdef IS_CLANG
2784+
#pragma clang diagnostic pop
2785+
#endif
27192786

27202787
PyMODINIT_FUNC
27212788
PyInit__segyio(void) {

0 commit comments

Comments
 (0)