Skip to content

Commit

Permalink
[fcelib] refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bfut committed Aug 9, 2024
1 parent e2c2baa commit 3bfbd6e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/codeql.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: cpp
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -31,7 +31,7 @@ jobs:
./tests/codeql/test_compilers_c++17.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:cpp"
upload: False
Expand All @@ -48,7 +48,7 @@ jobs:
# output: sarif-results/${{matrix.language}}.sarif

- name: Upload results
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sarif-results/cpp.sarif

Expand All @@ -65,22 +65,22 @@ jobs:
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: python
config-file: ./.github/codeql/codeql-config.yml

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:python"
upload: False
output: sarif-results

- name: Upload results
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sarif-results/python.sarif
8 changes: 4 additions & 4 deletions src/fcelib/fcelib_fcetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct FceHeader3 {
};

static
const char *kFce3PartsNames[kFceLibImplementedFce3Parts] = {
const char *kFce3PartsNames[FCELIB_UTIL_Fce3PartsImplemented] = {
"high body", /* car.fce */
"left front wheel",
"right front wheel",
Expand Down Expand Up @@ -351,7 +351,7 @@ struct FceHeader4 {
};

static
const char *kFce4HiBodyParts[kFceLibNumFce4HiBodyParts] = {
const char *kFce4HiBodyParts[FCELIB_UTIL_Fce4PartsHighBody] = {
":HB", /* car.fce */
":OT",
":OL",
Expand Down Expand Up @@ -1626,7 +1626,7 @@ void FCELIB_FCETYPES_PrintHeaderFce3(const void *header, const int fce_size)

printf("Parts:\n"
"Idx Verts Triags (PartPos) Description Name\n");
for (i = 0; i < FCELIB_UTIL_Min(kFceLibImplementedFce3Parts, hdr.NumParts); ++i)
for (i = 0; i < FCELIB_UTIL_Min(FCELIB_UTIL_Fce3PartsImplemented, hdr.NumParts); ++i)
{
printf(" %2d %5d %5d %5d %5d (%9f, %9f, %9f) %20s %s\n",
i,
Expand All @@ -1641,7 +1641,7 @@ void FCELIB_FCETYPES_PrintHeaderFce3(const void *header, const int fce_size)
verts += hdr.PNumVertices[i];
triags += hdr.PNumTriangles[i];
}
for (i = FCELIB_UTIL_Min(kFceLibImplementedFce3Parts, hdr.NumParts); i < FCELIB_UTIL_Min(64, hdr.NumParts); ++i)
for (i = FCELIB_UTIL_Min(FCELIB_UTIL_Fce3PartsImplemented, hdr.NumParts); i < FCELIB_UTIL_Min(64, hdr.NumParts); ++i)
{
printf(" %2d %5d %5d %5d %5d (%9f, %9f, %9f) %20s %s\n",
i,
Expand Down
16 changes: 10 additions & 6 deletions src/fcelib/fcelib_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
added at the end.
Many operations are carried out on index arrays.
Array elements (parts, triags, verts) are accessed in constant time at first.
Once an index array has been flagged as dirty, access is of linear complexity.
**/

#ifndef FCELIB_TYPES_H_
Expand Down Expand Up @@ -119,7 +117,11 @@ struct FcelibMesh {
FcelibTriangle **triangles; /* may contain NULL elements */
FcelibVertex **vertices; /* may contain NULL elements */

#ifdef __cplusplus
void (*release)(struct FcelibMesh*) = NULL;
#else
void (*release)(struct FcelibMesh*);
#endif
};

#ifdef __cplusplus
Expand Down Expand Up @@ -187,13 +189,15 @@ void FCELIB_TYPES_FreeMesh(FcelibMesh *mesh)
FcelibMesh *FCELIB_TYPES_InitMesh(FcelibMesh *mesh)
{
#ifndef FCELIB_PYTHON_BINDINGS
#ifdef __cplusplus
if (mesh->release == &FCELIB_TYPES_FreeMesh)
if (mesh->release && mesh->release == &FCELIB_TYPES_FreeMesh)
mesh->release(mesh);
#endif
#endif

#ifdef __cplusplus
*mesh = {};
#else
memset(mesh, 0, sizeof(*mesh));
#endif
mesh->hdr.NumArts = 1;
mesh->release = &FCELIB_TYPES_FreeMesh;
return mesh;
Expand Down Expand Up @@ -799,7 +803,7 @@ void FCELIB_TYPES_PrintMeshInfo(const FcelibMesh *mesh)
mesh->parts[mesh->hdr.Parts[i]]->PNumVertices,
mesh->parts[mesh->hdr.Parts[i]]->PNumTriangles,
mesh->parts[mesh->hdr.Parts[i]]->PartPos.x, mesh->parts[mesh->hdr.Parts[i]]->PartPos.y, mesh->parts[mesh->hdr.Parts[i]]->PartPos.z,
j < kFceLibImplementedFce3Parts ? kFce3PartsNames[j] : "",
j < FCELIB_UTIL_Fce3PartsImplemented ? kFce3PartsNames[j] : "",
mesh->parts[mesh->hdr.Parts[i]]->PartName);

verts += mesh->parts[mesh->hdr.Parts[i]]->PNumVertices;
Expand Down
6 changes: 3 additions & 3 deletions src/fcelib/fcelib_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <stdlib.h>
#include <string.h>

#define kFceLibImplementedFce3Parts 13
#define kFceLibNumFce4HiBodyParts 18
#define FCELIB_UTIL_Fce3PartsImplemented 13
#define FCELIB_UTIL_Fce4PartsHighBody 18

/* Represent FCE dummies (light/fx objects)
Mainly used for OBJ output, hence kTrianglesDiamond has 1-based indexes. */
Expand Down Expand Up @@ -115,7 +115,7 @@ int FCELIB_UTIL_StrIsInArray(char *str, const char **arr)
{
int retv = 0;
int i;
for (i = 0; i < kFceLibNumFce4HiBodyParts; ++i)
for (i = 0; i < FCELIB_UTIL_Fce4PartsHighBody; ++i)
{
if (strncmp(str, arr[i], 64) == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/codeql/test_compilers_c++17.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ DEST="fcec-OpAddHelperPart${VERSION}"

# compiler-specific
MINGWFLAGS="-fPIE -s -O2 -Xlinker --no-insert-timestamp" # -fstack-clash-protection -Wl,-pie
GCCFLAGS="-fPIE -pie -fstack-clash-protection -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -O2"
CPPFLAGS="-D_GLIBCXX_ASSERTIONS -fPIE -pie -fstack-clash-protection -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -O2"
GCCFLAGS="-fPIE -pie -fstack-clash-protection -fstack-protector-strong -D_FORTIFY_SOURCE=2" # -s -O2
CPPFLAGS="-D_GLIBCXX_ASSERTIONS -fPIE -pie -fstack-clash-protection -fstack-protector-strong -D_FORTIFY_SOURCE=2" # -s -O2

# debug
GCCDEBUGFLAGS="-pedantic-errors -g -Wall -Wextra -Wstack-protector -fasynchronous-unwind-tables" # -fsanitize=leak
Expand Down

0 comments on commit 3bfbd6e

Please sign in to comment.