Commit 1852eff
Default initialize properties in custom structs
Summary:
If a native module spec declares a custom type:
https://www.internalfb.com/code/fbsource/[f6aeb413dbc3]/xplat/js/RKJSModules/Libraries/hsr/tm/code/editable_object/NativeEditableObjectModule.js?lines=151-154
The codegen will generate a c++ struct for that type, like so:
```
template <typename P0, typename P1>
struct NativeEditableObjectModuleChangedProperty {
P0 propertyPath;
P1 value;
bool operator==(const NativeEditableObjectModuleChangedProperty &other) const {
return propertyPath == other.propertyPath && value == other.value;
}
};
```
## Problem
People can sometimes forget to default initialize this struct:
- **Report:** [post](https://fb.workplace.com/groups/rn.support/permalink/28506993098922601/)
- **Diff facebook#1:** D74868762
- **Diff facebook#2:** D77182083
In this scenario, all the members contain garbage data.
## Changes
This diff ensures that all the members are always default initialized, like so:
```
template <typename P0, typename P1>
struct NativeEditableObjectModuleChangedProperty {
P0 propertyPath{};
P1 value{};
bool operator==(const NativeEditableObjectModuleChangedProperty &other) const {
return propertyPath == other.propertyPath && value == other.value;
}
};
```
This way, even if you forget to default initailize the struct, the members will still be default initialized.
## Concerns/Risks
This could cause compilation issues in some of our existing native modules. (if one of the member types doesn't have a default constructor).
Code could start behaving differently, now that all the members are default initialized. (my hunch is that the risk from this causing a problem is low).
Changelog: [General][Changed] c++ tm codegen: Default initialize properties in custom structs
Reviewed By: christophpurrer
Differential Revision: D773157421 parent 847721d commit 1852eff
File tree
3 files changed
+112
-82
lines changed- packages/react-native-codegen
- e2e/deep_imports/__tests__/modules/__snapshots__
- src/generators/modules
- __tests__/__snapshots__
3 files changed
+112
-82
lines changedLines changed: 42 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
| 352 | + | |
352 | 353 | | |
353 | 354 | | |
354 | 355 | | |
| |||
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
397 | 399 | | |
398 | 400 | | |
399 | 401 | | |
| |||
862 | 864 | | |
863 | 865 | | |
864 | 866 | | |
865 | | - | |
866 | | - | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
867 | 870 | | |
868 | 871 | | |
869 | 872 | | |
| |||
1055 | 1058 | | |
1056 | 1059 | | |
1057 | 1060 | | |
1058 | | - | |
| 1061 | + | |
| 1062 | + | |
1059 | 1063 | | |
1060 | 1064 | | |
1061 | 1065 | | |
| |||
1257 | 1261 | | |
1258 | 1262 | | |
1259 | 1263 | | |
1260 | | - | |
| 1264 | + | |
| 1265 | + | |
1261 | 1266 | | |
1262 | 1267 | | |
1263 | 1268 | | |
| |||
1459 | 1464 | | |
1460 | 1465 | | |
1461 | 1466 | | |
1462 | | - | |
| 1467 | + | |
| 1468 | + | |
1463 | 1469 | | |
1464 | 1470 | | |
1465 | 1471 | | |
| |||
1661 | 1667 | | |
1662 | 1668 | | |
1663 | 1669 | | |
1664 | | - | |
| 1670 | + | |
| 1671 | + | |
1665 | 1672 | | |
1666 | 1673 | | |
1667 | 1674 | | |
| |||
1865 | 1872 | | |
1866 | 1873 | | |
1867 | 1874 | | |
1868 | | - | |
| 1875 | + | |
| 1876 | + | |
1869 | 1877 | | |
1870 | 1878 | | |
1871 | 1879 | | |
| |||
2478 | 2486 | | |
2479 | 2487 | | |
2480 | 2488 | | |
2481 | | - | |
| 2489 | + | |
| 2490 | + | |
2482 | 2491 | | |
2483 | 2492 | | |
2484 | 2493 | | |
| |||
2519 | 2528 | | |
2520 | 2529 | | |
2521 | 2530 | | |
2522 | | - | |
2523 | | - | |
2524 | | - | |
2525 | | - | |
2526 | | - | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
2527 | 2537 | | |
2528 | 2538 | | |
2529 | 2539 | | |
| |||
2992 | 3002 | | |
2993 | 3003 | | |
2994 | 3004 | | |
2995 | | - | |
2996 | | - | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
2997 | 3008 | | |
2998 | 3009 | | |
2999 | 3010 | | |
| |||
3185 | 3196 | | |
3186 | 3197 | | |
3187 | 3198 | | |
3188 | | - | |
| 3199 | + | |
| 3200 | + | |
3189 | 3201 | | |
3190 | 3202 | | |
3191 | 3203 | | |
| |||
3387 | 3399 | | |
3388 | 3400 | | |
3389 | 3401 | | |
3390 | | - | |
| 3402 | + | |
| 3403 | + | |
3391 | 3404 | | |
3392 | 3405 | | |
3393 | 3406 | | |
| |||
3589 | 3602 | | |
3590 | 3603 | | |
3591 | 3604 | | |
3592 | | - | |
| 3605 | + | |
| 3606 | + | |
3593 | 3607 | | |
3594 | 3608 | | |
3595 | 3609 | | |
| |||
3791 | 3805 | | |
3792 | 3806 | | |
3793 | 3807 | | |
3794 | | - | |
| 3808 | + | |
| 3809 | + | |
3795 | 3810 | | |
3796 | 3811 | | |
3797 | 3812 | | |
| |||
3995 | 4010 | | |
3996 | 4011 | | |
3997 | 4012 | | |
3998 | | - | |
| 4013 | + | |
| 4014 | + | |
3999 | 4015 | | |
4000 | 4016 | | |
4001 | 4017 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| |||
0 commit comments