use memcpy in args_getStruct

This commit is contained in:
lyon 2021-11-14 10:43:15 +08:00
parent 7e8b60ed96
commit d10bcdf399
4 changed files with 31 additions and 13 deletions

View File

@ -145,6 +145,22 @@ TEST(args, test12) {
EXPECT_EQ(pikaMemNow(), 0);
}
struct test {
int a;
float b;
};
TEST(args, struct_) {
Args* args = New_args(NULL);
struct test test_struct = {1, 2.2};
args_setStruct(args, (char*)"test", &test_struct, sizeof(struct test));
struct test test_struct_out;
args_getStruct(args, (char*)"test", &test_struct_out);
EXPECT_EQ(test_struct_out.a, 1);
EXPECT_FLOAT_EQ(test_struct_out.b, 2.2);
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, mem) {
EXPECT_EQ(pikaMemNow(), mem);
EXPECT_EQ(pikaMemNow(), 0);

View File

@ -1,8 +1,8 @@
#include "PikaPlatform.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
PIKA_WEAK void __platformDisableIrqHandle() {
/* disable irq to support thread */
@ -17,7 +17,7 @@ PIKA_WEAK void* __platformMalloc(size_t size) {
}
PIKA_WEAK void __platformFree(void* ptr) {
return free(ptr);
free(ptr);
}
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
@ -28,21 +28,21 @@ PIKA_WEAK void __platformPrintf(char* fmt, ...) {
va_end(args);
}
PIKA_WEAK char* __platformLoadPikaAsm(){
PIKA_WEAK char* __platformLoadPikaAsm() {
/* faild */
return NULL;
}
PIKA_WEAK int32_t __platformSavePikaAsm(char *PikaAsm){
PIKA_WEAK int32_t __platformSavePikaAsm(char* PikaAsm) {
/* faild */
return 1;
}
PIKA_WEAK uint8_t __platformAsmIsToFlash(char *pyMultiLine){
PIKA_WEAK uint8_t __platformAsmIsToFlash(char* pyMultiLine) {
/* not to flash */
return 0;
}
PIKA_WEAK int32_t __platformSavePikaAsmEOF(){
PIKA_WEAK int32_t __platformSavePikaAsmEOF() {
return 1;
}

View File

@ -129,14 +129,16 @@ int32_t args_setStruct(Args* self,
if (NULL == struct_ptr) {
return 1;
}
Arg* structArg = arg_setContent(NULL, (uint8_t*)struct_ptr, struct_size);
structArg = arg_setName(structArg, name);
args_setArg(self, structArg);
Arg* struct_arg = arg_setContent(NULL, (uint8_t*)struct_ptr, struct_size);
struct_arg = arg_setName(struct_arg, name);
args_setArg(self, struct_arg);
return 0;
}
void* args_getStruct(Args* self, char* name) {
return arg_getContent(args_getArg(self, name));
void* args_getStruct(Args* self, char* name, void* struct_out) {
Arg* struct_arg = args_getArg(self, name);
uint32_t struct_size = arg_getContentSize(struct_arg);
return memcpy(struct_out, arg_getContent(struct_arg), struct_size);
}
int32_t args_copyArgByName(Args* self, char* name, Args* directArgs) {

View File

@ -57,7 +57,7 @@ int32_t args_setStruct(Args* self,
char* name,
void* struct_ptr,
uint32_t struct_size);
void* args_getStruct(Args* self, char* name);
void* args_getStruct(Args* self, char* name, void* struct_out);
int32_t args_set(Args* self, char* name, char* valueStr);
int32_t args_setObjectWithClass(Args* self,