7.3. Generic parameters Arg
7.3.2. Overview
arg can hold a value of any type in it. The types supported by arg are: int, float, pointer, string, null, bytes. 1.
arg can be put into an object and the value of arg can be accessed directly in the python script.
The data type of a generic argument is Arg.
Arg* next;
uint32_t size;
uint8_t type;
Hash name_hash;
uint8_t content[];
The generic arguments internally include header information ( size, type, name_hash ), the data body (content), and a pointer (next) used to form the chain.
7.3.4. Creating and destroying generic arguments
- Creating a new generic argument
Creates a new generic argument from the heap and returns a pointer to the generic argument.
**Note that newly created generic parameters need to be manually destroyed to reclaim memory. Constantly creating new generic parameters but not destroying them can lead to memory leaks. **
[Note] The following api requires a kernel version of at least v1.9.2
New arg The argument passed in is the value of arg.
- Destroy generic arguments.
void arg_deinit(Arg* self);
- Copy generic arguments
Use the following API to determine the current type of a generic argument.
ArgType arg_getType(Arg* self);
Use the following API to convert a generic argument to a basic type.
7.3.6. Important Notes
Direct use of the arg_new<Type>() api **is highly likely to cause **memory leaks or dangling references, resulting in fatal flaws.
Please develop under docker development environment to ensure sufficient unit testing and memory checking.
...
/* Create a list object */
PikaObj* list = newNormalObj(New_PikaStdData_List);
PikaStdData_List___init__(list);
/* Create arg with api of arg_new<type> */
Arg* str_arg1 = arg_newStr("aaa");
/* add to list object */
PikaStdData_List_append(list, str_arg1);
/* destroy arg */