2 more coding rules

This commit is contained in:
2026-04-02 23:30:20 +02:00
parent a2069eea74
commit 3e5a979331
2 changed files with 10 additions and 0 deletions

View File

@@ -42,3 +42,7 @@ Assume memory allocation will eventually fail. Assume the filesystem will eventu
- Avoid separate functions for each method handler. Inline them into the single handler that handles dispatch. This not only net-shrinks the codebase, - Avoid separate functions for each method handler. Inline them into the single handler that handles dispatch. This not only net-shrinks the codebase,
but also means that navigating by searching for `== NN_<COMPONENT>_<REQUEST>)` (in NCL) or `== NN_<COMPONENT>NUM_<METHOD>)` (in NN) will show the but also means that navigating by searching for `== NN_<COMPONENT>_<REQUEST>)` (in NCL) or `== NN_<COMPONENT>NUM_<METHOD>)` (in NN) will show the
dispatch logic and implementation. dispatch logic and implementation.
- Properties which are always equal to a constant from the config, or simply has no dependency on state, must not be requests, and instead handled by
the component class directly.
- All loops inside methods must be bound by something controlled by either the config or a compile-time constant, to prevent denial of service attacks on
the worker thread.

View File

@@ -3150,6 +3150,9 @@ typedef enum nn_EENum {
NN_EENUM_SETDATA, NN_EENUM_SETDATA,
NN_EENUM_SETLABEL, NN_EENUM_SETLABEL,
NN_EENUM_SETARCH, NN_EENUM_SETARCH,
NN_EENUM_ISRO,
NN_EENUM_GETCHKSUM,
NN_EENUM_MKRO,
NN_EENUM_COUNT, NN_EENUM_COUNT,
} nn_EENum; } nn_EENum;
@@ -3294,6 +3297,9 @@ nn_Component *nn_createEEPROM(nn_Universe *universe, const char *address, const
[NN_EENUM_SETDATA] = {"setData", "function(data: string) - Set the data on the EEPROM", NN_INDIRECT}, [NN_EENUM_SETDATA] = {"setData", "function(data: string) - Set the data on the EEPROM", NN_INDIRECT},
[NN_EENUM_SETLABEL] = {"setLabel", "function(label?: string) - Set the label", NN_INDIRECT}, [NN_EENUM_SETLABEL] = {"setLabel", "function(label?: string) - Set the label", NN_INDIRECT},
[NN_EENUM_SETARCH] = {"setArchitecture", "function(arch?: string) - Set the desired architecture", NN_INDIRECT}, [NN_EENUM_SETARCH] = {"setArchitecture", "function(arch?: string) - Set the desired architecture", NN_INDIRECT},
[NN_EENUM_ISRO] = {"isReadonly", "function(): boolean - Returns whether the EEPROM is read-only.", NN_DIRECT},
[NN_EENUM_GETCHKSUM] = {"getChecksum", "function(): string - Returns a checksum of the EEPROM code.", NN_DIRECT},
[NN_EENUM_MKRO] = {"makeReadonly", "function(checksum: string): boolean - Make the EEPROM read-only if checksum passes.", NN_INDIRECT},
}; };
nn_Exit e = nn_setComponentMethodsArray(c, methods, NN_EENUM_COUNT); nn_Exit e = nn_setComponentMethodsArray(c, methods, NN_EENUM_COUNT);
if(e) { if(e) {