We should at least provide an option to control this behavior
Proposal
There are two ways to improve this DX:
- Provide
bool:delete_after_request = true argument for ezjson_option_set_body_from_json
native bool:ezhttp_option_set_body_from_json(EzHttpOptions:options_id, EzJSON:json, bool:pretty = false, bool:delete_after_request = true);
- Introduce
ezjson_copy and ezjson_move to explicitly pass JSON handles with decided behaviour
MOVE_EzJSON:ezjson_move(EzJSON:handle) {
return MOVE_EzJSON:handle;
}
MOVE_EzJSON:ezjson_copy(EzJSON:handle) {
return MOVE_EzJSON:ezjson_deep_copy(handle);
}
and update function signature:
native bool:ezhttp_option_set_body_from_json(EzHttpOptions:options_id, MOVE_EzJSON:json, bool:pretty = false);
This approach will force compiler to throw tag mismatch warning when use JSON handles directly and will encourage developers to explicitly choose how to delegate JSON handles. For handles that were just created in the scope of calling this function, ezjson_move is suitable, while ezjson_copy is suitable for global handles