Skip to content

Commit

Permalink
make compile-time assertions a bit more lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Dec 19, 2023
1 parent 7e2c680 commit eed16ab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/jsnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ JsVar *jsnCallFunction(void *function, JsnArgumentType argumentSpecifier, JsVar

char const sanity_test_arraybuffer_type_one_byte[sizeof(JsVarDataArrayBufferViewType) == 1 ? 1 : -1];
char const sanity_test_arraybuffer_in_jsvar[sizeof(JsVarDataArrayBufferView) <= JSVAR_DATA_ARRAYBUFFER_LEN ? 1 : -1];
char const sanity_test_native_in_jsvar[sizeof(JsVarDataNative) <= JSVAR_DATA_ARRAYBUFFER_LEN ? 1 : -1];
char const sanity_test_nativestr_in_jsvar[sizeof(JsVarDataNativeStr) <= JSVAR_DATA_ARRAYBUFFER_LEN ? 1 : -1];
char const sanity_test_native_in_jsvar[sizeof(JsVarDataNative) <= JSVAR_DATA_NATIVE_LEN ? 1 : -1];
char const sanity_test_nativestr_in_jsvar[sizeof(JsVarDataNativeStr) <= JSVAR_DATA_NATIVE_LEN ? 1 : -1];


// runtime sanity tests
Expand Down
2 changes: 2 additions & 0 deletions src/jsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ See comments after JsVar in jsvar.c for more info.
#define JSVAR_DATA_STRING_LEN (JSVAR_DATA_STRING_NAME_LEN + ((JSVARREF_BITS*3 + JSVARREFCOUNT_PACK_BITS)>>3))
/// Max length for an arraybuffer since it uses firstChild
#define JSVAR_DATA_ARRAYBUFFER_LEN (JSVAR_DATA_STRING_NAME_LEN + ((JSVARREF_BITS*2)>>3))
/// Max length for a native var since it uses refCount (but not the first 3 references)
#define JSVAR_DATA_NATIVE_LEN (JSVAR_DATA_STRING_NAME_LEN + ((JSVARREF_BITS*3)>>3))
/// Max length for a JSV_STRINGEXT, JsVar.varData.ref.lastChild (see comments under JsVar decl in jsvar.h)
#define JSVAR_DATA_STRING_MAX_LEN (JSVAR_DATA_STRING_NAME_LEN + ((JSVARREF_BITS*3 + JSVARREFCOUNT_PACK_BITS + JSVARREFCOUNT_BITS)>>3))

Expand Down
2 changes: 1 addition & 1 deletion src/jsvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ typedef struct JsVarStruct {
| 0 - 3 | 4 | varData | data | data | data | data | data | data | nativePtr | size | ptr | charLen |
| 4 - 5 | ? | next | data | data | next | next | - | data | argTypes | format | len | - |
| 6 - 7 | ? | prev | data | data | prev | prev | - | data | argTypes | format | ..len | - |
| 8 - 9 | ? | first | data | data | child | child | - | data? | first | stringPtr | - | - |
| 8 - 9 | ? | first | data | data | child | child | - | data? | first | stringPtr | ..len | - |
| 10-11 | ? | refs | refs | data | refs | refs | refs | refs | refs | refs | refs | refs |
| 12-13 | ? | last | nextPtr| nextPtr | nextPtr | - | - | - | last | - | - | - |
| 14-15 | 2 | Flags | Flags | Flags | Flags | Flags | Flags| Flags | Flags | Flags | Flags | Flags |
Expand Down

0 comments on commit eed16ab

Please sign in to comment.