get rid of INIT_TYPE() / initType()

A function to initialize rb_data_type_t variables is not needed.

Also fix a FIXME (WindowVX's name is now "Window") on the way.
This commit is contained in:
cremno 2014-08-29 13:52:10 +02:00
parent 0203e28436
commit 173ee07959
14 changed files with 35 additions and 62 deletions

View File

@ -29,19 +29,6 @@
#include <string.h>
#include <assert.h>
void initType(rb_data_type_t &type,
const char *name,
void (*freeInst)(void *))
{
type.wrap_struct_name = name;
type.function.dmark = 0;
type.function.dsize = 0;
type.function.dfree = freeInst;
type.function.reserved[0] =
type.function.reserved[1] = 0;
type.parent = 0;
}
RbData *getRbData()
{
return static_cast<RbData*>(shState->bindingData());

View File

@ -64,12 +64,27 @@ raiseRbExc(const Exception &exc);
#define DECL_TYPE(Klass) \
extern rb_data_type_t Klass##Type
#define DEF_TYPE(Klass) \
rb_data_type_t Klass##Type
/* 2.1 has added a new field (flags) to rb_data_type_t */
#include <ruby/version.h>
#if RUBY_API_VERSION_MINOR > 0
/* TODO: can mkxp use RUBY_TYPED_FREE_IMMEDIATELY here? */
#define DEF_TYPE_FLAGS 0
#else
#define DEF_TYPE_FLAGS
#endif
void initType(rb_data_type_t &type,
const char *name,
void (*freeInst)(void*));
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
rb_data_type_t Klass##Type = { \
Name, { 0, Free, 0, { 0, 0 } }, 0, 0, DEF_TYPE_FLAGS \
}
#define DEF_TYPE_CUSTOMFREE(Klass, Free) \
DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, #Klass, Free)
#define DEF_TYPE_CUSTOMNAME(Klass, Name) \
DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, freeInstance<Klass>)
#define DEF_TYPE(Klass) DEF_TYPE_CUSTOMNAME(Klass, #Klass)
template<rb_data_type_t *rbType>
static VALUE classAllocate(VALUE klass)
@ -83,8 +98,6 @@ static void freeInstance(void *inst)
delete static_cast<C*>(inst);
}
#define INIT_TYPE(Klass) initType(Klass##Type, #Klass, freeInstance<Klass>)
void
raiseDisposedAccess(VALUE self);

View File

@ -427,8 +427,6 @@ INITCOPY_FUN(Bitmap)
void
bitmapBindingInit()
{
INIT_TYPE(Bitmap);
VALUE klass = rb_define_class("Bitmap", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&BitmapType>);

View File

@ -169,7 +169,6 @@ INITCOPY_FUN(Rect)
#define INIT_BIND(Klass) \
{ \
INIT_TYPE(Klass); \
klass = rb_define_class(#Klass, rb_cObject); \
rb_define_alloc_func(klass, classAllocate<&Klass##Type>); \
rb_define_class_method(klass, "_load", Klass##Load); \

View File

@ -28,7 +28,16 @@
#include "ruby/encoding.h"
#include "ruby/intern.h"
DEF_TYPE(FileInt);
static void
fileIntFreeInstance(void *inst)
{
SDL_RWops *ops = static_cast<SDL_RWops*>(inst);
SDL_RWclose(ops);
SDL_FreeRW(ops);
}
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
static VALUE
fileIntForPath(const char *path)
@ -100,15 +109,6 @@ RB_METHOD(fileIntBinmode)
return Qnil;
}
static void
fileIntFreeInstance(void *inst)
{
SDL_RWops *ops = static_cast<SDL_RWops*>(inst);
SDL_RWclose(ops);
SDL_FreeRW(ops);
}
VALUE
kernelLoadDataInt(const char *filename)
{
@ -196,8 +196,6 @@ RB_METHOD(_marshalLoad)
void
fileIntBindingInit()
{
initType(FileIntType, "FileInt", fileIntFreeInstance);
VALUE klass = rb_define_class("FileInt", rb_cIO);
rb_define_alloc_func(klass, classAllocate<&FileIntType>);

View File

@ -260,8 +260,6 @@ RB_METHOD(FontSetDefaultColor)
void
fontBindingInit()
{
INIT_TYPE(Font);
VALUE klass = rb_define_class("Font", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&FontType>);

View File

@ -59,8 +59,6 @@ DEF_PROP_F(Plane, ZoomY)
void
planeBindingInit()
{
INIT_TYPE(Plane);
VALUE klass = rb_define_class("Plane", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&PlaneType>);

View File

@ -99,8 +99,6 @@ RB_METHOD(spriteHeight)
void
spriteBindingInit()
{
INIT_TYPE(Sprite);
VALUE klass = rb_define_class("Sprite", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&SpriteType>);

View File

@ -147,8 +147,6 @@ INITCOPY_FUN(Table)
void
tableBindingInit()
{
INIT_TYPE(Table);
VALUE klass = rb_define_class("Table", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&TableType>);

View File

@ -28,7 +28,7 @@
#include "binding-util.h"
#include "binding-types.h"
rb_data_type_t TilemapAutotilesType;
DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE);
RB_METHOD(tilemapAutotilesSet)
{
@ -137,16 +137,12 @@ DEF_PROP_I(Tilemap, OY)
void
tilemapBindingInit()
{
initType(TilemapAutotilesType, "TilemapAutotiles", 0);
VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>);
_rb_define_method(klass, "[]=", tilemapAutotilesSet);
_rb_define_method(klass, "[]", tilemapAutotilesGet);
INIT_TYPE(Tilemap);
klass = rb_define_class("Tilemap", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&TilemapType>);

View File

@ -29,8 +29,9 @@
#include "binding-util.h"
#include "binding-types.h"
DEF_TYPE(TilemapVX);
rb_data_type_t BitmapArrayType;
DEF_TYPE_CUSTOMNAME(TilemapVX, "Tilemap");
DEF_TYPE_CUSTOMFREE(BitmapArray, RUBY_TYPED_NEVER_FREE);
RB_METHOD(tilemapVXInitialize)
{
@ -130,8 +131,6 @@ RB_METHOD(tilemapVXBitmapsGet)
void
tilemapVXBindingInit()
{
initType(TilemapVXType, "Tilemap", freeInstance<TilemapVX>);
VALUE klass = rb_define_class("Tilemap", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&TilemapVXType>);
@ -157,8 +156,6 @@ tilemapVXBindingInit()
INIT_PROP_BIND( TilemapVX, Flags, "passages" );
}
initType(BitmapArrayType, "BitmapArray", 0);
klass = rb_define_class_under(klass, "BitmapArray", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>);

View File

@ -89,8 +89,6 @@ DEF_PROP_I(Viewport, OY)
void
viewportBindingInit()
{
INIT_TYPE(Viewport);
VALUE klass = rb_define_class("Viewport", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&ViewportType>);

View File

@ -73,8 +73,6 @@ DEF_PROP_I(Window, ContentsOpacity)
void
windowBindingInit()
{
INIT_TYPE(Window);
VALUE klass = rb_define_class("Window", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&WindowType>);

View File

@ -26,7 +26,7 @@
#include "bitmap.h"
DEF_TYPE(WindowVX);
DEF_TYPE_CUSTOMNAME(WindowVX, "Window");
void bitmapInitProps(Bitmap *b, VALUE self);
@ -135,9 +135,6 @@ DEF_PROP_B(WindowVX, Pause)
void
windowVXBindingInit()
{
// FIXME: data type name will end up as "WindowVX"
INIT_TYPE(WindowVX);
VALUE klass = rb_define_class("Window", rb_cObject);
rb_define_alloc_func(klass, classAllocate<&WindowVXType>);