diff --git a/.ci/linters/c/00preprocess.R b/.ci/linters/c/00preprocess.R index 046db97646..3cd49144d5 100644 --- a/.ci/linters/c/00preprocess.R +++ b/.ci/linters/c/00preprocess.R @@ -1,5 +1,5 @@ .preprocess = function (f) list( - c_obj = f, lines = readLines(f), + path = f, lines = readLines(f), preprocessed = system2( "gcc", shQuote(c("-fpreprocessed", "-E", f)), stdout = TRUE, stderr = FALSE diff --git a/.ci/linters/cocci/use_ro_accessors.cocci b/.ci/linters/cocci/use_ro_accessors.cocci new file mode 100644 index 0000000000..d21a42fc5a --- /dev/null +++ b/.ci/linters/cocci/use_ro_accessors.cocci @@ -0,0 +1,79 @@ +/* Ensure _RO accessors are used for assignment to 'const' variables */ +@@ +type T; +const T *variable; +expression E; +@@ +- variable = RAW(E) ++ variable = RAW_RO(E) + +@@ +type T; +const T *variable; +expression E; +@@ +- variable = LOGICAL(E) ++ variable = LOGICAL_RO(E) + +@@ +type T; +const T *variable; +expression E; +@@ +- variable = INTEGER(E) ++ variable = INTEGER_RO(E) + +@@ +type T; +const T *variable; +expression E; +@@ +- variable = REAL(E) ++ variable = REAL_RO(E) + +@@ +type T; +const T *variable; +expression E; +@@ +- variable = COMPLEX(E) ++ variable = COMPLEX_RO(E) + +/* Just use _RO accessors directly instead of 'const' casting the writeable one */ +@@ +expression E; +type T; +@@ +-(const T*) RAW(E) ++RAW_RO(E) + +@@ +expression E; +@@ +-(const int*) LOGICAL(E) ++LOGICAL_RO(E) + +@@ +expression E; +@@ +-(const int*) INTEGER(E) ++INTEGER_RO(E) + +@@ +expression E; +@@ +-(const double*) REAL(E) ++REAL_RO(E) +@@ +expression E; +type T; +@@ +-(const T*) COMPLEX(E) ++COMPLEX_RO(E) + +@@ +expression E; +type T; +@@ +-(const T*) STRING_PTR(E) ++STRING_PTR_RO(E) diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 7e0d655aee..2fda8f60f7 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -29,6 +29,7 @@ jobs: c: - '**/*.c' - '**/*.h' + - '.ci/linters/cocci/**/*.cocci' po: - 'po/**/*.po' md: