pikapython/src/dataArg.c

545 lines
16 KiB
C
Raw Normal View History

2021-10-02 19:20:18 +08:00
/*
2021-11-16 08:46:44 +08:00
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
2021-11-16 08:49:33 +08:00
* Copyright (c) 2021 lyon liang6516@outlook.com
2021-11-16 08:46:44 +08:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
2021-10-02 19:20:18 +08:00
2021-10-01 00:21:50 +08:00
#include "dataArg.h"
#include "PikaObj.h"
2021-10-01 00:21:50 +08:00
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "stdlib.h"
2022-10-08 21:28:29 +08:00
static PIKA_BOOL _arg_cache_push(Arg* self, uint32_t size) {
#if !PIKA_ARG_CACHE_ENABLE
return PIKA_FALSE;
#else
2022-10-13 19:33:09 +08:00
if (PIKA_FALSE == __pks_hook_arg_cache_filter(self)) {
return PIKA_FALSE;
}
extern PikaMemInfo pikaMemInfo;
if (self->heap_size < PIKA_ARG_CACHE_SIZE ||
self->heap_size > 2 * PIKA_ARG_CACHE_SIZE) {
return PIKA_FALSE;
}
if (PIKA_ARG_CACHE_POOL_SIZE <= pikaMemInfo.cache_pool_top) {
return PIKA_FALSE;
}
pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top++] = (uint8_t*)self;
2022-10-08 21:28:29 +08:00
pikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
return PIKA_TRUE;
2022-10-08 21:28:29 +08:00
#endif
}
2022-10-08 21:28:29 +08:00
static Arg* _arg_cache_pop(uint32_t size) {
#if !PIKA_ARG_CACHE_ENABLE
return NULL;
#else
uint32_t req_heap_size = mem_align(sizeof(Arg) + size);
extern PikaMemInfo pikaMemInfo;
if (req_heap_size > PIKA_ARG_CACHE_SIZE) {
return NULL;
}
if (!(pikaMemInfo.cache_pool_top > 0)) {
return NULL;
}
--pikaMemInfo.cache_pool_top;
2022-10-08 21:28:29 +08:00
Arg* self = (Arg*)pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top];
pikaMemInfo.heapUsed += mem_align(sizeof(Arg) + size);
return self;
2022-10-08 21:28:29 +08:00
#endif
}
uint32_t arg_getTotleSize(Arg* self) {
return arg_totleSize(self);
2021-10-01 00:21:50 +08:00
}
2021-11-13 16:42:01 +08:00
/**
* time33 hash
*/
Hash hash_time33(char* str) {
pika_assert(str != NULL);
2022-11-03 18:51:53 +08:00
if (*str == 0) {
return 5381;
}
2021-11-13 16:42:01 +08:00
Hash hash = 5381;
while (*str) {
hash += (hash << 5) + (*str++);
}
return (hash & 0x7FFFFFFF);
}
2022-10-05 20:35:04 +08:00
static Arg* _arg_set_hash(Arg* self,
Hash nameHash,
ArgType type,
uint8_t* content,
uint32_t size,
Arg* next) {
2022-10-05 20:35:04 +08:00
/* create arg if not exist */
if (NULL == self || self->size < size) {
self = _arg_cache_pop(size);
uint32_t heap_size = sizeof(Arg) + size;
#if PIKA_ARG_CACHE_ENABLE
// if (heap_size < PIKA_ARG_CACHE_SIZE) {
// heap_size = PIKA_ARG_CACHE_SIZE;
// }
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.alloc_times++;
pikaMemInfo.alloc_times_cache++;
#endif
if (NULL == self) {
self = (Arg*)pikaMalloc(heap_size);
2022-10-08 21:28:29 +08:00
#if PIKA_ARG_CACHE_ENABLE
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.alloc_times_cache--;
self->heap_size = mem_align(heap_size);
2022-10-08 21:28:29 +08:00
#endif
}
2022-10-08 21:28:29 +08:00
self->size = size;
2022-10-05 20:35:04 +08:00
self->flag = 0;
arg_setSerialized(self, PIKA_TRUE);
// arg_setIsKeyword(self, PIKA_FALSE);
2022-10-05 20:35:04 +08:00
arg_setNext(self, next);
}
2022-01-24 18:05:16 +00:00
self->name_hash = nameHash;
2022-01-24 19:50:53 +00:00
self->type = type;
2021-10-02 19:20:18 +08:00
if (NULL != content) {
2022-07-31 17:18:29 +08:00
__platform_memcpy(arg_getContent(self), content, size);
} else {
__platform_memset(arg_getContent(self), 0,
aline_by(size, sizeof(uint32_t)));
2021-10-02 19:20:18 +08:00
}
pika_assert(self->flag < ARG_FLAG_MAX);
2022-05-22 21:11:32 +08:00
return self;
2022-01-25 08:39:10 +08:00
}
2022-10-05 20:35:04 +08:00
static Arg* arg_create_hash(Hash nameHash,
ArgType type,
uint8_t* content,
uint32_t size,
Arg* next) {
return _arg_set_hash(NULL, nameHash, type, content, size, next);
}
static Arg* arg_create(char* name,
ArgType type,
uint8_t* content,
uint32_t size,
Arg* next) {
2021-11-13 16:42:01 +08:00
Hash nameHash = hash_time33(name);
2022-10-05 20:35:04 +08:00
return arg_create_hash(nameHash, type, content, size, next);
}
static Arg* arg_set(Arg* self,
char* name,
ArgType type,
uint8_t* content,
uint32_t size) {
Hash nameHash = hash_time33(name);
return _arg_set_hash(self, nameHash, type, content, size, NULL);
2021-11-13 16:42:01 +08:00
}
2022-07-31 17:18:29 +08:00
void arg_init_stack(Arg* self, uint8_t* buffer, uint32_t size) {
2022-08-05 14:07:57 +08:00
self->_.buffer = buffer;
2022-07-31 17:18:29 +08:00
self->size = size;
}
uint32_t arg_totleSize(Arg* self) {
2022-05-22 20:50:28 +08:00
return ((Arg*)self)->size + sizeof(Arg);
2021-10-01 00:21:50 +08:00
}
void arg_freeContent(Arg* self) {
2022-10-13 01:24:58 +08:00
pika_assert(NULL != self);
if (_arg_cache_push(self, self->size)) {
return;
2021-10-02 19:20:18 +08:00
}
2022-10-13 01:24:58 +08:00
pikaFree(self, arg_totleSize(self));
return;
2021-10-01 00:21:50 +08:00
}
Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size) {
2021-10-02 19:20:18 +08:00
if (NULL == self) {
/* malloc */
2022-10-05 20:35:04 +08:00
return arg_create("", ARG_TYPE_NONE, content, size, NULL);
2021-10-02 19:20:18 +08:00
}
/* only copy */
2022-07-31 17:18:29 +08:00
if (arg_getSize(self) >= size) {
__platform_memcpy(arg_getContent((Arg*)self), content, size);
return self;
}
2022-01-25 08:39:10 +08:00
/* realloc */
2022-05-22 21:11:32 +08:00
Hash nameHash = arg_getNameHash(self);
ArgType type = arg_getType(self);
Arg* next = arg_getNext(self);
2022-10-05 20:35:04 +08:00
Arg* newContent = arg_create_hash(nameHash, type, content, size, next);
arg_freeContent(self);
2021-11-13 16:42:01 +08:00
return newContent;
}
Arg* arg_setNameHash(Arg* self, Hash nameHash) {
2021-11-13 16:42:01 +08:00
if (NULL == self) {
2022-10-05 20:35:04 +08:00
return arg_create_hash(nameHash, ARG_TYPE_NONE, NULL, 0, NULL);
2021-11-13 16:42:01 +08:00
}
2022-05-22 20:50:28 +08:00
Arg* arg = (Arg*)self;
2022-01-24 18:05:16 +00:00
arg->name_hash = nameHash;
return self;
2021-10-01 00:21:50 +08:00
}
Arg* arg_setName(Arg* self, char* name) {
pika_assert(NULL != name);
return arg_setNameHash(self, hash_time33(name));
2021-10-01 00:21:50 +08:00
}
2022-04-20 17:05:21 +08:00
Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size) {
2022-10-13 01:24:58 +08:00
self = arg_newContent(size + sizeof(size_t) + 1);
if (NULL == self) {
return NULL;
}
2022-04-18 12:11:33 +08:00
self = arg_setName(self, name);
2022-10-13 01:24:58 +08:00
pika_assert(NULL != self);
arg_setType(self, ARG_TYPE_BYTES);
2022-04-18 12:11:33 +08:00
void* dir = arg_getContent(self);
2022-05-26 15:46:34 +08:00
/* set content all to 0 */
2022-06-10 11:34:46 +08:00
__platform_memset(dir, 0, size + sizeof(size_t) + 1);
/* setsize */
2022-04-18 12:11:33 +08:00
__platform_memcpy(dir, &size, sizeof(size_t));
2022-05-26 15:46:34 +08:00
/* set init value */
if (NULL != src) {
__platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size);
}
pika_assert(self->flag < ARG_FLAG_MAX);
2022-04-18 12:11:33 +08:00
return self;
}
2022-10-13 01:24:58 +08:00
Arg* arg_newContent(uint32_t size) {
2022-10-05 20:35:04 +08:00
Arg* newContent = arg_create("", ARG_TYPE_NONE, NULL, size, NULL);
2021-10-02 19:20:18 +08:00
return newContent;
2021-10-01 00:21:50 +08:00
}
2022-04-20 17:05:21 +08:00
uint8_t* arg_getBytes(Arg* self) {
return arg_getContent(self) + sizeof(size_t);
2022-04-18 11:56:29 +08:00
}
2022-09-04 21:19:41 +08:00
char* __printBytes(PikaObj* self, Arg* arg) {
Args buffs = {0};
size_t bytes_size = arg_getBytesSize(arg);
uint8_t* bytes = arg_getBytes(arg);
Arg* str_arg = arg_newStr("b\'");
2022-04-20 14:00:05 +08:00
for (size_t i = 0; i < bytes_size; i++) {
2022-09-04 21:19:41 +08:00
char* str_item = strsFormat(&buffs, 16, "\\x%02x", bytes[i]);
str_arg = arg_strAppend(str_arg, str_item);
2022-04-20 14:00:05 +08:00
}
2022-09-04 21:19:41 +08:00
str_arg = arg_strAppend(str_arg, "\'");
char* str_res = obj_cacheStr(self, arg_getStr(str_arg));
strsDeinit(&buffs);
arg_deinit(str_arg);
return str_res;
}
void arg_printBytes(Arg* self) {
PikaObj* obj = New_PikaObj();
__platform_printf("%s\r\n", __printBytes(obj, self));
obj_deinit(obj);
2022-04-20 14:00:05 +08:00
}
2022-04-19 18:12:07 +08:00
size_t arg_getBytesSize(Arg* self) {
2022-04-18 11:56:29 +08:00
size_t mem_size = 0;
void* content = (void*)arg_getContent(self);
if (NULL == content) {
return 0;
}
__platform_memcpy(&mem_size, content, sizeof(size_t));
return mem_size;
}
Arg* arg_setStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size) {
if (NULL == struct_ptr) {
return NULL;
}
2022-10-05 20:35:04 +08:00
return arg_set(self, name, ARG_TYPE_STRUCT, (uint8_t*)struct_ptr,
struct_size);
2022-03-16 12:16:09 +08:00
}
Arg* arg_setHeapStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size,
void* struct_deinit_fun) {
if (NULL == struct_ptr) {
return NULL;
}
Arg* struct_arg =
arg_setContent(NULL, (uint8_t*)&struct_deinit_fun, sizeof(void*));
struct_arg = arg_append(struct_arg, (uint8_t*)struct_ptr, struct_size);
2022-10-13 01:24:58 +08:00
pika_assert(NULL != struct_arg);
arg_setType(struct_arg, ARG_TYPE_STRUCT_HEAP);
struct_arg = arg_setName(struct_arg, name);
return struct_arg;
}
2022-03-16 12:16:09 +08:00
void* arg_getHeapStructDeinitFun(Arg* self) {
void* deinit_fun = NULL;
__platform_memcpy(&deinit_fun, arg_getContent(self), sizeof(void*));
return deinit_fun;
}
2021-10-01 00:21:50 +08:00
Arg* arg_setInt(Arg* self, char* name, int64_t val) {
2022-10-05 20:35:04 +08:00
return arg_set(self, name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val));
2021-10-01 00:21:50 +08:00
}
2021-12-24 13:15:32 +08:00
Arg* arg_setNull(Arg* self) {
2022-10-05 20:35:04 +08:00
return arg_set(self, "", ARG_TYPE_NONE, NULL, 0);
2021-12-24 13:15:32 +08:00
}
Arg* arg_setFloat(Arg* self, char* name, pika_float val) {
2022-10-05 20:35:04 +08:00
return arg_set(self, name, ARG_TYPE_FLOAT, (uint8_t*)&val, sizeof(val));
2021-10-01 00:21:50 +08:00
}
pika_float arg_getFloat(Arg* self) {
2021-10-02 19:20:18 +08:00
if (NULL == arg_getContent(self)) {
return -999.999;
}
2021-10-01 00:21:50 +08:00
return *(pika_float*)arg_getContent(self);
2021-10-01 00:21:50 +08:00
}
2021-11-15 09:36:46 +08:00
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
2022-10-05 20:35:04 +08:00
return arg_set(self, name, type, (uint8_t*)&pointer, sizeof(uintptr_t));
2021-10-01 00:21:50 +08:00
}
Arg* arg_setStr(Arg* self, char* name, char* string) {
if (NULL == string) {
2022-07-01 23:10:51 +08:00
return NULL;
}
2022-10-05 20:35:04 +08:00
return arg_set(self, name, ARG_TYPE_STRING, (uint8_t*)string,
strGetSize(string) + 1);
2021-10-01 00:21:50 +08:00
}
int64_t arg_getInt(Arg* self) {
2022-08-16 12:21:11 +08:00
pika_assert(NULL != self);
2021-10-02 19:20:18 +08:00
if (NULL == arg_getContent(self)) {
return -999999;
}
2022-07-31 17:18:29 +08:00
return *(int64_t*)arg_getContent(self);
2021-10-01 00:21:50 +08:00
}
void* arg_getPtr(Arg* self) {
2022-09-07 14:25:25 +08:00
if (arg_getType(self) == ARG_TYPE_NONE) {
return NULL;
}
2021-10-02 19:20:18 +08:00
if (NULL == arg_getContent(self)) {
return NULL;
}
2022-07-31 17:18:29 +08:00
return *(void**)arg_getContent(self);
2021-10-01 00:21:50 +08:00
}
char* arg_getStr(Arg* self) {
2021-10-02 19:20:18 +08:00
return (char*)arg_getContent(self);
2021-10-01 00:21:50 +08:00
}
uint32_t arg_getContentSize(Arg* self) {
return arg_getSize(self);
2021-10-01 00:21:50 +08:00
}
Arg* New_arg(void* voidPointer) {
2021-10-02 19:20:18 +08:00
return NULL;
2021-10-01 00:21:50 +08:00
}
2022-07-31 19:48:35 +08:00
Arg* arg_copy(Arg* arg_src) {
if (NULL == arg_src) {
2021-10-14 23:22:48 +08:00
return NULL;
}
pika_assert(arg_src->flag < ARG_FLAG_MAX);
2022-07-31 19:48:35 +08:00
ArgType arg_type = arg_getType(arg_src);
2022-04-26 11:09:18 +08:00
if (ARG_TYPE_OBJECT == arg_type) {
2022-07-31 19:48:35 +08:00
obj_refcntInc((PikaObj*)arg_getPtr(arg_src));
}
Arg* arg_dict = New_arg(NULL);
arg_dict = arg_setContent(arg_dict, arg_getContent(arg_src),
arg_getContentSize(arg_src));
arg_dict = arg_setNameHash(arg_dict, arg_getNameHash(arg_src));
2022-10-13 01:24:58 +08:00
pika_assert(NULL != arg_dict);
arg_setType(arg_dict, arg_getType(arg_src));
arg_setIsKeyword(arg_dict, arg_getIsKeyword(arg_src));
return arg_dict;
2021-10-01 00:21:50 +08:00
}
2022-03-12 20:52:25 +08:00
2022-07-31 19:48:35 +08:00
Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
if (NULL == arg_src) {
2022-07-31 19:48:35 +08:00
return NULL;
}
2022-08-16 12:21:11 +08:00
if (NULL == arg_dict) {
return arg_copy(arg_src);
}
2022-07-31 19:48:35 +08:00
/* size is too big to be copied by noalloc */
if (arg_getSize(arg_src) > arg_getSize(arg_dict)) {
return arg_copy(arg_src);
2022-07-31 15:22:53 +08:00
}
2022-07-31 19:48:35 +08:00
ArgType arg_type = arg_getType(arg_src);
2022-07-31 15:22:53 +08:00
if (ARG_TYPE_OBJECT == arg_type) {
2022-07-31 19:48:35 +08:00
obj_refcntInc((PikaObj*)arg_getPtr(arg_src));
2022-07-31 15:22:53 +08:00
}
arg_setSerialized(arg_dict, PIKA_FALSE);
2022-07-31 19:48:35 +08:00
arg_dict = arg_setContent(arg_dict, arg_getContent(arg_src),
arg_getContentSize(arg_src));
arg_dict = arg_setNameHash(arg_dict, arg_getNameHash(arg_src));
2022-10-13 01:24:58 +08:00
pika_assert(NULL != arg_dict);
arg_setType(arg_dict, arg_getType(arg_src));
arg_setIsKeyword(arg_dict, arg_getIsKeyword(arg_src));
2022-07-31 19:48:35 +08:00
return arg_dict;
2022-07-31 15:22:53 +08:00
}
Arg* arg_append(Arg* self, void* new_content, size_t new_size) {
uint8_t* old_content = arg_getContent(self);
size_t old_size = arg_getContentSize(self);
Arg* new_arg = NULL;
#if PIKA_ARG_CACHE_ENABLE
2022-03-12 20:52:25 +08:00
/* create arg_out */
if (self->heap_size > mem_align(sizeof(Arg) + old_size + new_size)) {
new_arg = self;
new_arg->size = old_size + new_size;
extern PikaMemInfo pikaMemInfo;
pikaMemInfo.heapUsed += mem_align(sizeof(Arg) + old_size + new_size) -
mem_align(sizeof(Arg) + old_size);
}
#endif
if (NULL == new_arg) {
new_arg = arg_setContent(NULL, NULL, old_size + new_size);
}
2022-10-13 01:24:58 +08:00
pika_assert(NULL != new_arg);
arg_setType(new_arg, arg_getType(self));
arg_setNameHash(new_arg, arg_getNameHash(self));
if (self != new_arg) {
/* copy old content */
__platform_memcpy(arg_getContent(new_arg), old_content, old_size);
}
2022-03-12 20:52:25 +08:00
/* copy new content */
__platform_memcpy(arg_getContent(new_arg) + old_size, new_content,
2022-03-12 20:52:25 +08:00
new_size);
if (self != new_arg) {
arg_deinit(self);
}
return new_arg;
2022-03-12 20:52:25 +08:00
}
2022-03-16 12:16:09 +08:00
void* arg_getHeapStruct(Arg* self) {
return arg_getContent(self) + sizeof(void*);
}
2022-04-11 22:27:18 +08:00
void arg_deinitHeap(Arg* self) {
2022-10-02 19:38:20 +08:00
if (arg_getIsWeakRef(self)) {
return;
}
2022-04-26 12:23:39 +08:00
ArgType type = arg_getType(self);
/* deinit heap struct */
2022-04-27 23:38:00 +08:00
if (type == ARG_TYPE_STRUCT_HEAP) {
2022-03-16 12:16:09 +08:00
/* deinit heap strcut */
StructDeinitFun struct_deinit_fun =
(StructDeinitFun)arg_getHeapStructDeinitFun(self);
struct_deinit_fun(arg_getHeapStruct(self));
2022-10-13 01:24:58 +08:00
return;
2022-03-16 12:16:09 +08:00
}
2022-04-26 10:01:40 +08:00
/* deinit sub object */
2022-06-01 11:59:12 +08:00
if (ARG_TYPE_OBJECT == type) {
2022-04-26 10:01:40 +08:00
PikaObj* subObj = arg_getPtr(self);
obj_refcntDec(subObj);
int ref_cnt = obj_refcntNow(subObj);
if (ref_cnt <= 0) {
obj_deinit(subObj);
2022-04-25 23:38:10 +08:00
}
2022-10-13 01:24:58 +08:00
return;
2022-04-25 23:38:10 +08:00
}
2022-04-26 12:23:39 +08:00
}
2022-05-02 14:48:10 +08:00
/* load file as byte array */
Arg* arg_loadFile(Arg* self, char* filename) {
2022-05-22 17:13:01 +08:00
size_t file_size = 0;
2022-05-02 14:48:10 +08:00
char* file_buff = __platform_malloc(PIKA_READ_FILE_BUFF_SIZE);
2022-05-04 15:36:55 +08:00
Arg* res = New_arg(NULL);
2022-05-02 14:48:10 +08:00
__platform_memset(file_buff, 0, PIKA_READ_FILE_BUFF_SIZE);
FILE* input_file = __platform_fopen(filename, "rb");
if (NULL == input_file) {
__platform_printf("Error: Couldn't open file '%s'\n", filename);
2022-05-04 15:36:55 +08:00
res = NULL;
goto exit;
}
file_size =
2022-05-02 14:48:10 +08:00
__platform_fread(file_buff, 1, PIKA_READ_FILE_BUFF_SIZE, input_file);
if (file_size >= PIKA_READ_FILE_BUFF_SIZE) {
__platform_printf("Error: Not enough buff for input file.\r\n");
2022-05-02 14:48:10 +08:00
return NULL;
}
/* add '\0' to the end of the string */
res = arg_setBytes(res, "", (uint8_t*)file_buff, file_size + 1);
2022-05-04 15:36:55 +08:00
exit:
2022-05-02 14:48:10 +08:00
__platform_free(file_buff);
2022-05-04 15:36:55 +08:00
if (NULL != input_file) {
__platform_fclose(input_file);
}
2022-05-02 14:48:10 +08:00
return res;
}
2022-04-26 12:23:39 +08:00
void arg_deinit(Arg* self) {
pika_assert(NULL != self);
2022-04-26 12:23:39 +08:00
/* deinit arg pointed heap */
arg_deinitHeap(self);
2022-10-05 01:04:37 +08:00
if (!arg_isSerialized(self)) {
2022-08-01 10:06:49 +08:00
return;
}
2022-04-26 10:01:40 +08:00
/* free the ref */
2022-04-11 22:27:18 +08:00
arg_freeContent(self);
}
PIKA_BOOL arg_isEqual(Arg* self, Arg* other) {
if (NULL == self || NULL == other) {
return PIKA_FALSE;
}
if (arg_getType(self) != arg_getType(other)) {
return PIKA_FALSE;
}
if (arg_getType(self) == ARG_TYPE_OBJECT) {
if (arg_getPtr(self) != arg_getPtr(other)) {
return PIKA_FALSE;
}
2022-09-05 15:39:15 +08:00
}
2022-09-07 14:25:25 +08:00
if (arg_getType(self) == ARG_TYPE_STRING) {
if (strEqu(arg_getStr(self), arg_getStr(other))) {
2022-09-05 15:39:15 +08:00
return PIKA_TRUE;
}
}
2022-09-05 15:39:15 +08:00
if (0 != __platform_memcmp(arg_getContent(self), arg_getContent(other),
arg_getContentSize(self))) {
return PIKA_FALSE;
}
return PIKA_TRUE;
}