Half revert constructors, having two types

This commit is contained in:
altalk23 2023-03-06 21:17:08 +03:00
parent 29fde5fac5
commit 7dba804969
34 changed files with 101 additions and 43 deletions

View file

@ -34,7 +34,10 @@ public:
static constexpr auto CLASS_NAME = "{class_name}";
)GEN";
char const* zero_constructor = R"GEN( GEODE_ZERO_CONSTRUCTOR({class_name}, {first_base})
char const* custom_constructor = R"GEN( GEODE_CUSTOM_CONSTRUCTOR_GD({class_name}, {first_base})
)GEN";
char const* custom_constructor_cutoff = R"GEN( GEODE_CUSTOM_CONSTRUCTOR_CUTOFF({class_name}, {first_base})
)GEN";
char const* function_definition = R"GEN(
@ -177,7 +180,9 @@ std::string generateBindingHeader(Root& root, ghc::filesystem::path const& singl
// what.
if (!cls.superclasses.empty()) {
single_output += fmt::format(
format_strings::zero_constructor,
can_find(cls.superclasses[0], "cocos2d")
? format_strings::custom_constructor_cutoff
: format_strings::custom_constructor,
fmt::arg("class_name", cls.name),
fmt::arg("first_base", cls.superclasses[0])
);

View file

@ -85,13 +85,13 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
reinterpret_cast<FunctionType>(func)(this{parameter_comma}{arguments});
// we need to construct it back so that it uhhh ummm doesnt crash
// while going to the child destructors
auto thing = new (this) {class_name}(geode::ZeroConstructor);
auto thing = new (this) {class_name}(geode::CutoffConstructor, sizeof({class_name}));
CCDestructor::lock(this) = true;
}}
)GEN";
char const* declare_constructor = R"GEN(
{class_name}::{function_name}({parameters}) : {class_name}(geode::ZeroConstructor) {{
{class_name}::{function_name}({parameters}) : {class_name}(geode::CutoffConstructor, sizeof({class_name})) {{
// here we construct it as normal as we can, then destruct it
// using the generated functions. this ensures no memory gets leaked
// no crashes :pray:

View file

@ -73,8 +73,28 @@ namespace geode {
struct ZeroConstructorType {};
static constexpr auto ZeroConstructor = ZeroConstructorType();
struct CutoffConstructorType {};
static constexpr auto CutoffConstructor = CutoffConstructorType();
}
#define GEODE_CUSTOM_CONSTRUCTOR_BEGIN(Class_) \
GEODE_ZERO_CONSTRUCTOR_BEGIN(Class_) \
GEODE_CUTOFF_CONSTRUCTOR_BEGIN(Class_)
#define GEODE_CUSTOM_CONSTRUCTOR_COCOS(Class_, Base_) \
GEODE_ZERO_CONSTRUCTOR(Class_, Base_) \
GEODE_CUTOFF_CONSTRUCTOR_COCOS(Class_, Base_)
#define GEODE_CUSTOM_CONSTRUCTOR_GD(Class_, Base_) \
GEODE_ZERO_CONSTRUCTOR(Class_, Base_) \
GEODE_CUTOFF_CONSTRUCTOR_GD(Class_, Base_)
#define GEODE_CUSTOM_CONSTRUCTOR_CUTOFF(Class_, Base_) \
GEODE_ZERO_CONSTRUCTOR(Class_, Base_) \
GEODE_CUTOFF_CONSTRUCTOR_CUTOFF(Class_, Base_)
#define GEODE_ZERO_CONSTRUCTOR_BEGIN(Class_) \
Class_(geode::ZeroConstructorType, void*) {} \
Class_(geode::ZeroConstructorType, size_t fill) : \
@ -85,6 +105,39 @@ namespace geode {
Class_(geode::ZeroConstructorType, size_t fill) : Base_(geode::ZeroConstructor, fill) {} \
Class_(geode::ZeroConstructorType) : Base_(geode::ZeroConstructor, sizeof(Class_)) {}
#define GEODE_FILL_CONSTRUCTOR(Class_, Offset_) \
Class_(geode::CutoffConstructorType, size_t fill) : \
Class_( \
geode::CutoffConstructor, \
std::memset(reinterpret_cast<std::byte*>(this) + Offset_, 0, fill - Offset_) \
) {} \
Class_(geode::CutoffConstructorType, void*)
#define GEODE_CUTOFF_CONSTRUCTOR_BEGIN(Class_) \
GEODE_MACOS(GEODE_FILL_CONSTRUCTOR(Class_, 0){}) \
GEODE_IOS(GEODE_FILL_CONSTRUCTOR(Class_, 0){})
#define GEODE_CUTOFF_CONSTRUCTOR_COCOS(Class_, Base_) \
GEODE_MACOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){}) \
GEODE_IOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){})
#define GEODE_CUTOFF_CONSTRUCTOR_GD(Class_, Base_) \
GEODE_WINDOWS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){}) \
GEODE_MACOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){}) \
GEODE_IOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){})
#define GEODE_CUTOFF_CONSTRUCTOR_CUTOFF(Class_, Base_) \
GEODE_WINDOWS(GEODE_FILL_CONSTRUCTOR(Class_, sizeof(Base_)) : Base_(){}) \
GEODE_MACOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){}) \
GEODE_IOS(Class_(geode::CutoffConstructorType, size_t fill) \
: Base_(geode::CutoffConstructor, fill){})
#define GEODE_NUMBER_OF_ARGS(...) \
GEODE_EXPAND(GEODE_NUMBER_OF_ARGS_(__VA_ARGS__, GEODE_NUMBER_SEQUENCE(), ))
#define GEODE_NUMBER_OF_ARGS_(...) GEODE_EXPAND(GEODE_NUMBER_OF_ARGS_N(__VA_ARGS__))

View file

@ -121,7 +121,7 @@ public:
* @js ctor
*/
CCDirector(void);
GEODE_ZERO_CONSTRUCTOR(CCDirector, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCDirector, CCObject)
/**
* @js NA
* @lua NA

View file

@ -141,7 +141,7 @@ class CC_DLL CCScheduler : public CCObject
GEODE_FRIEND_MODIFY
public:
CCScheduler();
GEODE_ZERO_CONSTRUCTOR(CCScheduler, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCScheduler, CCObject)
/**
* @js NA
* @lua NA

View file

@ -140,7 +140,7 @@ public:
* @js ctor
*/
CCNode(void);
GEODE_ZERO_CONSTRUCTOR(CCNode, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCNode, CCObject)
/**
* Default destructor
@ -1638,7 +1638,7 @@ public:
* @js ctor
*/
CCNodeRGBA();
GEODE_ZERO_CONSTRUCTOR(CCNodeRGBA, CCNode)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCNodeRGBA, CCNode)
/**
* @js NA
* @lua NA

View file

@ -112,7 +112,7 @@ protected:
int m_nUnknown;
)
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCObject)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCObject)
CCObject(void);
/**
* @lua NA

View file

@ -46,7 +46,7 @@ public:
* @lua NA
*/
CCSet(void);
GEODE_ZERO_CONSTRUCTOR(CCSet, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCSet, CCObject)
/**
* @lua NA
*/

View file

@ -47,7 +47,7 @@ class CC_DLL CCString : public CCObject
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR(CCString, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCString, CCObject)
/**
* @lua NA
*/

View file

@ -94,7 +94,7 @@ public:
void setBlendFunc(const ccBlendFunc &blendFunc);
CCDrawNode();
GEODE_ZERO_CONSTRUCTOR(CCDrawNode, CCNodeRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCDrawNode, CCNodeRGBA)
/** listen the event that coming to foreground on Android
* @js NA

View file

@ -139,7 +139,7 @@ public:
* @js ctor
*/
CCControl();
GEODE_ZERO_CONSTRUCTOR(CCControl, CCLayerRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCControl, CCLayerRGBA)
virtual bool init(void);
/**

View file

@ -58,7 +58,7 @@ public:
virtual void setColorValue(ccColor3B const&);
)
GEODE_ZERO_CONSTRUCTOR(CCControlColourPicker, CCControl)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCControlColourPicker, CCControl)
CCControlColourPicker();
virtual ~CCControlColourPicker();

View file

@ -54,7 +54,7 @@ class CC_DLL CCScale9Sprite : public CCNodeRGBA
{
public:
CCScale9Sprite();
GEODE_ZERO_CONSTRUCTOR(CCScale9Sprite, CCNodeRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCScale9Sprite, CCNodeRGBA)
virtual ~CCScale9Sprite();
public:

View file

@ -69,7 +69,7 @@ public:
* @js ctor
*/
CCScrollView();
GEODE_ZERO_CONSTRUCTOR(CCScrollView, CCLayer)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCScrollView, CCLayer)
/**
* @js NA
* @lua NA

View file

@ -59,7 +59,7 @@ class CC_DLL CCKeypadHandler : public CCObject
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR(CCKeypadHandler, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCKeypadHandler, CCObject)
inline CCKeypadHandler() = default;
virtual ~CCKeypadHandler(void);

View file

@ -198,7 +198,7 @@ public:
* @js ctor
*/
CCLabelBMFont();
GEODE_ZERO_CONSTRUCTOR(CCLabelBMFont, CCSpriteBatchNode)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCLabelBMFont, CCSpriteBatchNode)
/**
* @js NA
* @lua NA

View file

@ -63,7 +63,7 @@ public:
* @js ctor
*/
CCLabelTTF();
GEODE_ZERO_CONSTRUCTOR(CCLabelTTF, CCSprite)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCLabelTTF, CCSprite)
/**
* @js NA
* @lua NA

View file

@ -75,7 +75,7 @@ public:
* @js ctor
*/
CCLayer();
GEODE_ZERO_CONSTRUCTOR(CCLayer, CCNode)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCLayer, CCNode)
/**
* @js NA
* @lua NA
@ -233,7 +233,7 @@ public:
* @js ctor
*/
CCLayerRGBA();
GEODE_ZERO_CONSTRUCTOR(CCLayerRGBA, CCLayer)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCLayerRGBA, CCLayer)
/**
* @js NA
* @lua NA
@ -290,7 +290,7 @@ public:
* @js ctor
*/
CCLayerColor();
GEODE_ZERO_CONSTRUCTOR(CCLayerColor, CCLayerRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCLayerColor, CCLayerRGBA)
/**
* @js NA
* @lua NA

View file

@ -63,7 +63,7 @@ public:
* @js ctor
*/
CCScene();
GEODE_ZERO_CONSTRUCTOR(CCScene, CCNode)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCScene, CCNode)
/**
* @js NA
* @lua NA

View file

@ -64,7 +64,7 @@ public:
* @js ctor
*/
CCMenu() : m_pSelectedItem(NULL) {}
GEODE_ZERO_CONSTRUCTOR(CCMenu, CCLayerRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMenu, CCLayerRGBA)
/**
* @js NA
* @lua NA

View file

@ -71,7 +71,7 @@ public:
, m_pfnSelector(NULL)
, m_nScriptTapHandler(0)
{}
GEODE_ZERO_CONSTRUCTOR(CCMenuItem, CCNodeRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMenuItem, CCNodeRGBA)
/**
* @js NA
* @lua NA
@ -139,7 +139,7 @@ public:
: m_pLabel(NULL)
, m_fOriginalScale(0.0)
{}
GEODE_ZERO_CONSTRUCTOR(CCMenuItemLabel, CCMenuItem)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMenuItemLabel, CCMenuItem)
/**
* @js NA
* @lua NA
@ -292,7 +292,7 @@ public:
,m_pSelectedImage(NULL)
,m_pDisabledImage(NULL)
{}
GEODE_ZERO_CONSTRUCTOR(CCMenuItemSprite, CCMenuItem)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMenuItemSprite, CCMenuItem)
/** creates a menu item with a normal, selected and disabled image*/
static CCMenuItemSprite * create(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite = NULL);
@ -337,7 +337,7 @@ public:
* @lua NA
*/
CCMenuItemImage(){}
GEODE_ZERO_CONSTRUCTOR(CCMenuItemImage, CCMenuItemSprite)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMenuItemImage, CCMenuItemSprite)
/**
* @js NA
* @lua NA

View file

@ -53,7 +53,7 @@ class CC_DLL CCFileUtils : public TypeInfo
friend class CCDictionary;
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCFileUtils)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCFileUtils)
/**
* Returns an unique ID for this class.
* @note It's only used for JSBindings now.

View file

@ -46,7 +46,7 @@ public:
@js ctor
*/
CCImage();
GEODE_ZERO_CONSTRUCTOR(CCImage, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCImage, CCObject)
/**
* @js NA
* @lua NA

View file

@ -36,7 +36,7 @@ class CC_DLL CCApplication : public CCApplicationProtocol
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCApplication)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCApplication)
CCApplication();
/**
* @js NA

View file

@ -35,7 +35,7 @@ class CC_DLL CCApplication : public CCApplicationProtocol
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCApplication)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCApplication)
CCApplication();
virtual ~CCApplication();

View file

@ -15,7 +15,7 @@ class CC_DLL CCApplication : public CCApplicationProtocol
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCApplication)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCApplication)
CCApplication();
virtual ~CCApplication();

View file

@ -45,7 +45,7 @@ protected:
RT_ADD( virtual ~CCEGLView(); )
public:
CCEGLView();
GEODE_ZERO_CONSTRUCTOR(CCEGLView, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCEGLView, CCObject)
RT_REMOVE( virtual ~CCEGLView(); )
/* override functions */

View file

@ -207,7 +207,7 @@ RT_ADD(
class CC_DLL CCKeyboardHandler : public CCObject
{
public:
GEODE_ZERO_CONSTRUCTOR(CCKeyboardHandler, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCKeyboardHandler, CCObject)
inline CCKeyboardHandler() = default;
virtual ~CCKeyboardHandler();

View file

@ -22,7 +22,7 @@ RT_ADD(
class CC_DLL CCMouseHandler : public CCObject
{
public:
GEODE_ZERO_CONSTRUCTOR(CCMouseHandler, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCMouseHandler, CCObject)
inline CCMouseHandler() = default;
virtual ~CCMouseHandler();

View file

@ -168,7 +168,7 @@ public:
* @js ctor
*/
CCSprite(void);
GEODE_ZERO_CONSTRUCTOR(CCSprite, CCNodeRGBA)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCSprite, CCNodeRGBA)
/**
* Default destructor

View file

@ -68,7 +68,7 @@ public:
* @js ctor
*/
CCSpriteBatchNode();
GEODE_ZERO_CONSTRUCTOR(CCSpriteBatchNode, CCNode)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCSpriteBatchNode, CCNode)
/**
* @js NA
* @lua NA

View file

@ -50,7 +50,7 @@ class CC_DLL CCIMEDelegate
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR_BEGIN(CCIMEDelegate)
GEODE_CUSTOM_CONSTRUCTOR_BEGIN(CCIMEDelegate)
virtual ~CCIMEDelegate();
virtual bool attachWithIME();

View file

@ -117,7 +117,7 @@ public:
* @js ctor
*/
CCTexture2D();
GEODE_ZERO_CONSTRUCTOR(CCTexture2D, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCTexture2D, CCObject)
/**
* @js NA
* @lua NA

View file

@ -48,7 +48,7 @@ class CC_DLL CCTouchHandler : public CCObject
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR(CCTouchHandler, CCObject)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCTouchHandler, CCObject)
inline CCTouchHandler() = default;
virtual ~CCTouchHandler(void);
@ -86,7 +86,7 @@ class CC_DLL CCStandardTouchHandler : public CCTouchHandler
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR(CCStandardTouchHandler, CCTouchHandler)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCStandardTouchHandler, CCTouchHandler)
inline CCStandardTouchHandler() = default;
~CCStandardTouchHandler(void);
@ -110,7 +110,7 @@ class CC_DLL CCTargetedTouchHandler : public CCTouchHandler
{
GEODE_FRIEND_MODIFY
public:
GEODE_ZERO_CONSTRUCTOR(CCTargetedTouchHandler, CCTouchHandler)
GEODE_CUSTOM_CONSTRUCTOR_COCOS(CCTargetedTouchHandler, CCTouchHandler)
inline CCTargetedTouchHandler() = default;
~CCTargetedTouchHandler(void);