Skip to content

Commit 5c78969

Browse files
authored
code-style: Fix/c headers (#3214)
* refactor: replace <c*> headers with C headers, remove std:: prefix - <cassert> -> <assert.h>, <cctype> -> <ctype.h>, <cfloat> -> <float.h>, <cstdint> -> <stdint.h>, <cstdlib> -> <stdlib.h>, <cstring> -> <string.h> - Remove <cstddef> includes (available transitively) - Remove std:: prefix from non-math C types/functions globally - <cmath> exempted (C++ overloaded math); std::nullptr_t and std::abs preserved - Add check-cstd-inc.ps1 for CI and C++ Wrapper C Headers rule to CODING_STYLE.md * Add ci * fix: restore std:: prefix for std::remove algorithm calls - 3 occurrences in ProgramState.cpp and Console.cpp were incorrectly stripped * Cleanup code
1 parent 318f0d6 commit 5c78969

126 files changed

Lines changed: 753 additions & 542 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: check-cstd-headers
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'axmol/**'
7+
- 'extensions/**'
8+
push:
9+
branches:
10+
- dev*
11+
- release/*
12+
paths:
13+
- 'axmol/**'
14+
- 'extensions/**'
15+
- 'tests'
16+
- 'templates'
17+
workflow_dispatch:
18+
19+
jobs:
20+
check-cstd-headers:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v6
24+
25+
- name: Check for forbidden C++ wrapper C headers
26+
shell: pwsh
27+
run: ./tools/cmdline/check-cstd-inc.ps1

axmol/2d/ActionTiledGrid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void ShuffleTiles::startWithTarget(Node* target)
277277

278278
if (_seed != (unsigned int)-1)
279279
{
280-
std::srand(_seed);
280+
srand(_seed);
281281
}
282282

283283
_tilesCount = (unsigned int)(_gridSize.width * _gridSize.height);
@@ -603,7 +603,7 @@ void TurnOffTiles::startWithTarget(Node* target)
603603

604604
if (_seed != (unsigned int)-1)
605605
{
606-
std::srand(_seed);
606+
srand(_seed);
607607
}
608608

609609
_tilesCount = (unsigned int)(_gridSize.width * _gridSize.height);

axmol/2d/Label.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,7 @@ void Label::recordLetterInfo(const ax::Vec2& point,
32003200
float offsetX,
32013201
float offsetY)
32023202
{
3203-
if (static_cast<std::size_t>(letterIndex) >= _lettersInfo.size())
3203+
if (static_cast<size_t>(letterIndex) >= _lettersInfo.size())
32043204
{
32053205
LetterInfo tmpInfo;
32063206
_lettersInfo.emplace_back(tmpInfo);
@@ -3217,7 +3217,7 @@ void Label::recordLetterInfo(const ax::Vec2& point,
32173217

32183218
void Label::recordPlaceholderInfo(int letterIndex, char32_t utf32Char)
32193219
{
3220-
if (static_cast<std::size_t>(letterIndex) >= _lettersInfo.size())
3220+
if (static_cast<size_t>(letterIndex) >= _lettersInfo.size())
32213221
{
32223222
LetterInfo tmpInfo;
32233223
_lettersInfo.emplace_back(tmpInfo);

axmol/3d/ObjLoader.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
THE SOFTWARE.
2323
****************************************************************************/
2424

25-
#include <cstdlib>
26-
#include <cstring>
27-
#include <cassert>
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include <assert.h>
2828
#include <cmath>
29-
#include <cstddef>
3029

3130
#include <string>
3231
#include <vector>
@@ -666,7 +665,7 @@ std::string LoadMtl(tlx::string_map<int>& material_map, std::vector<material_t>&
666665
}
667666
if (_space)
668667
{
669-
std::ptrdiff_t len = _space - token;
668+
ptrdiff_t len = _space - token;
670669
std::string key(token, len);
671670
std::string value = _space + 1;
672671
material.unknown_parameter.emplace(std::move(key), std::move(value));

axmol/base/Console.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <thread>
3131
#include <algorithm>
3232
#include <functional>
33-
#include <cctype>
33+
#include <ctype.h>
3434
#include <locale>
3535
#include <sstream>
3636
#include <optional>
@@ -1138,7 +1138,7 @@ void Console::commandTouchSubCommandTap(socket_native_type fd, std::string_view
11381138

11391139
if (argi == 3)
11401140
{
1141-
std::srand((unsigned)time(nullptr));
1141+
srand((unsigned)time(nullptr));
11421142
_touchId = rand();
11431143
Director::getInstance()->postTask([this, x, y]() {
11441144
PointerInputState pointerDownData{.id = _touchId};
@@ -1176,15 +1176,15 @@ void Console::commandTouchSubCommandSwipe(socket_native_type fd, std::string_vie
11761176
// return;
11771177
// }
11781178
char* endptr = nullptr;
1179-
points[i] = std::strtod(val.data(), &endptr);
1179+
points[i] = strtod(val.data(), &endptr);
11801180
}
11811181

11821182
float& x1 = points[0];
11831183
float& y1 = points[1];
11841184
float& x2 = points[2];
11851185
float& y2 = points[3];
11861186

1187-
std::srand((unsigned)time(nullptr));
1187+
srand((unsigned)time(nullptr));
11881188
_touchId = rand();
11891189

11901190
Director::getInstance()->postTask([x1, y1, this]() {

axmol/base/InputSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ THE SOFTWARE.
3333
#include "axmol/scene/Camera.h"
3434

3535
#include <list>
36-
#include <cfloat>
36+
#include <float.h>
3737
#include <map>
3838

3939
// Touch bookkeeping was migrated into InputSystem private members.

axmol/base/Properties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <string>
2727
#include <functional>
28-
#include <cstdint>
28+
#include <stdint.h>
2929
#include <vector>
3030

3131
#include "axmol/renderer/Texture2D.h"

axmol/base/Random.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
#pragma once
2828

2929
#include <random>
30-
#include <cstdlib>
30+
#include <stdlib.h>
3131

3232
#include "axmol/platform/PlatformConfig.h"
3333

@@ -104,25 +104,25 @@ inline int random()
104104
return ax::random(0, AX_RAND_MAX);
105105
};
106106

107-
/// Follow random APIs is device independent, need set seed by std::srand
107+
/// Follow random APIs is device independent, need set seed by srand
108108
/// DEPRECATED: use FastRGN.h or c++11 'std::minstd_rand' or 'std::minstd_rand0' instead
109109

110110
/**
111111
* Returns a random float between -1 and 1.
112-
* It can be seeded using std::srand(seed);
112+
* It can be seeded using srand(seed);
113113
*/
114114
inline float rand_minus1_1()
115115
{
116-
return ((std::rand() / (float)RAND_MAX) * 2) - 1;
116+
return ((rand() / (float)RAND_MAX) * 2) - 1;
117117
}
118118

119119
/**
120120
* Returns a random float between 0 and 1.
121-
* It can be seeded using std::srand(seed);
121+
* It can be seeded using srand(seed);
122122
*/
123123
inline float rand_0_1()
124124
{
125-
return std::rand() / (float)RAND_MAX;
125+
return rand() / (float)RAND_MAX;
126126
}
127127

128128
} // namespace ax

axmol/base/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ namespace braceinit
902902
{
903903
inline void skip_ws(const char*& p, const char* end)
904904
{
905-
while (p < end && std::isspace(static_cast<unsigned char>(*p)))
905+
while (p < end && isspace(static_cast<unsigned char>(*p)))
906906
++p;
907907
}
908908
inline bool expect(const char*& p, const char* end, char c)

axmol/base/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ AX_DLL std::vector<Node*> findChildren(const Node& node, std::string_view name);
113113
#
114114

115115
/** Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof.
116-
* Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal
116+
* Why we need this? Because in android c++_static, atof ( and atof ) is unsupported for numbers have long decimal
117117
* part and contain several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. This function
118118
* is used to fix this bug.
119119
* @param str The string be to converted to double.

0 commit comments

Comments
 (0)