Skip to content

Commit 9df7b21

Browse files
authored
Merge pull request #254 from robotpy/zero-init-out
Zero-initialize out parameters
2 parents 32d30ba + 330ea40 commit 9df7b21

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

robotpy_build/autowrap/cxxparser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ def _on_fn_make_lambda(self, data: FunctionData, fctx: FunctionContext):
16371637
for out in reversed(tmp_params):
16381638
odef = out.default
16391639
if not odef:
1640-
lambda_pre.insert(0, f"{out.cpp_type} {out.arg_name}")
1640+
lambda_pre.insert(0, f"{out.cpp_type} {out.arg_name}{{}}")
16411641
elif odef.startswith("{"):
16421642
lambda_pre.insert(0, f"{out.cpp_type} {out.arg_name}{odef}")
16431643
else:

tests/cpp/rpytest/ft/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
fnParamFundConstRef,
109109
fnParamFundPtr,
110110
fnParamFundRef,
111+
fnParamOutNotSet,
111112
fnRenamed,
112113
fnRenamedParam,
113114
fnSimpleDefaultParam,
@@ -225,6 +226,7 @@
225226
"fnParamFundConstRef",
226227
"fnParamFundPtr",
227228
"fnParamFundRef",
229+
"fnParamOutNotSet",
228230
"fnRenamed",
229231
"fnRenamedParam",
230232
"fnSimpleDefaultParam",

tests/cpp/rpytest/ft/include/parameters.h

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ int fnParamFundPtr(int x, int * y)
2828
return x - 1;
2929
}
3030

31+
// parameters that are not set should be zero initialized
32+
int fnParamOutNotSet(int *z) {
33+
return 1;
34+
}
35+
3136
// do a namespace thing because we messed that up once
3237
namespace ohno {
3338
// parameters that are pointers and fundamental types are out by default

tests/test_ft_parameters.py

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def test_fund_const_ref():
2222
assert ft.fnParamFundConstRef(1, 2) == 3
2323

2424

25+
def test_param_out_not_set():
26+
assert ft.fnParamOutNotSet() == (1, 0)
27+
28+
2529
def test_fn_disable_none():
2630
with pytest.raises(TypeError):
2731
ft.fnParamDisableNone(None)

0 commit comments

Comments
 (0)