This commit is contained in:
blueloveTH 2024-07-01 02:22:03 +08:00
parent 96d0c432c7
commit 69183e2d79
5 changed files with 14 additions and 42 deletions

View File

@ -1,33 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct c11_userdata{
void* _0;
void* _1;
} c11_userdata;
void c11_userdata__ctor(c11_userdata* self, void* ptr, int size);
#define c11_userdata__as(T, self) (*( (T*)(self) ))
#ifdef __cplusplus
}
namespace pkpy{
struct any: c11_userdata{
template<typename T>
any(T value){
c11_userdata__ctor(this, &value, sizeof(T));
}
any(){ }
template<typename T>
T as(){
return c11_userdata__as(T, this);
}
};
} // namespace pkpy
#endif

View File

@ -40,6 +40,20 @@ extern const char* kPlatformStrings[];
#define PK_NARGS(...) PK_NARGS_SEQ(__VA_ARGS__, 4, 3, 2, 1, 0)
#define PK_NPTRS(...) PK_NARGS_SEQ(__VA_ARGS__, int****, int***, int**, int*, int)
// ref counting
typedef struct RefCounted {
int count;
void (*dtor)(void*);
} RefCounted;
#define PK_INCREF(obj) (obj)->rc.count++
#define PK_DECREF(obj) do { \
if(--(obj)->rc.count == 0) { \
(obj)->rc.dtor(obj); \
free(obj); \
} \
} while(0)
#ifdef __cplusplus
}
#endif

View File

@ -7,7 +7,6 @@
#include "pocketpy/common/smallmap.h"
#include "pocketpy/objects/base.h"
#include "pocketpy/objects/sourcedata.h"
#include "pocketpy/common/refcount.h"
#include "pocketpy/pocketpy.h"
#ifdef __cplusplus

View File

@ -3,7 +3,6 @@
#include <stdbool.h>
#include "pocketpy/common/str.h"
#include "pocketpy/common/vector.h"
#include "pocketpy/common/refcount.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,7 +0,0 @@
#include "pocketpy/common/any.h"
#include <string.h>
void c11_userdata__ctor(c11_userdata* self, void* ptr, int size){
memcpy(self, ptr, size);
}