Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (72 sloc) 1.87 KB
#ifndef __MOP_H__
#define __MOP_H__
#include "EXTERN.h"
#include "perl.h"
#define MOP_DEBUG(...) PerlIO_printf(PerlIO_stderr(), __VA_ARGS__)
/* forward decl */
struct _map_attribute;
struct _mop_class;
struct _mop_instance;
struct _mop_method;
typedef struct _mop_class mop_class;
typedef struct _mop_attribute mop_attribute;
typedef struct _mop_instance mop_instance;
typedef struct _mop_method mop_method;
struct mop_state {
void *obj;
unsigned int trace;
SV *sv;
};
typedef struct mop_state mop_state;
/* This is used only for structural equivalence */
struct _mop_component {
mop_state *state;
};
typedef struct _mop_component mop_component;
#define MOP_DEFAULT_TRACE_LEVEL 0
#include "mop_attribute.h"
#include "mop_class.h"
#include "mop_instance.h"
#include "mop_method.h"
#include "mop_package.h"
#define MOP_STATE_FROM_SV(sv) \
(mg_find(SvROK(sv) ? SvRV(sv) : sv, '~')->mg_obj)
#define MOP_PTR_FROM_SV(sv) \
(((mop_state *) MOP_STATE_FROM_SV(sv))->obj)
#define MOP_TRACE_LEVEL_FROM_SV(sv) \
((sv) ? ((mop_state *) MOP_STATE_FROM_SV(sv))->trace : 0)
static void
mop_init(pTHX_)
{
get_hv("mop::class::metaclass_registry", 1);
}
static mop_state *
mop_state_create(pTHX_ void *ptr, SV *sv) {
mop_state *st;
Newxz(st, 1, mop_state);
st->obj = ptr;
st->trace = MOP_DEFAULT_TRACE_LEVEL;
st->sv = sv;
((mop_component *) ptr)->state = st;
return st;
}
static int
mop_component_state_has_refs(pTHX_ mop_component *c)
{
if (c->state) {
if (!PL_dirty && SvOK(c->state->sv) && SvREFCNT(c->state->sv) > 1) {
/* still alive, keep */
return 1;
}
}
return 0;
}
static void
mop_component_state_destroy(pTHX_ mop_component *c)
{
if (c->state != NULL) {
PerlIO_printf(PerlIO_stderr(), " DESTROY state %p\n", c->state);
Safefree(c->state);
}
}
#endif /* MOP_H */