Пример #1
0
void IR_init_File(struct IridiumContext * context)
{
  CLASS(File) = send(CLASS(Class), "new", IR_STRING("File"));
  CLASS(FileNotFoundError) = send(CLASS(Class), "new", IR_STRING("FileNotFoundError"), CLASS(Exception));
  CLASS(IOError) = send(CLASS(Class), "new", IR_STRING("IOError"), CLASS(Exception));

  DEF_METHOD(CLASS(File), "initialize", ARGLIST(argument_new(L_ATOM(filename), NULL, 0), argument_new(L_ATOM(mode), IR_STRING("r"), 0)), iridium_method_name(File, initialize));
  DEF_METHOD(CLASS(File), "read", ARGLIST(), iridium_method_name(File, read));
  DEF_METHOD(CLASS(File), "write", ARGLIST(argument_new(L_ATOM(str), NULL, 0)), iridium_method_name(File, write));
  DEF_METHOD(CLASS(File), "close", ARGLIST(), iridium_method_name(File, close));
  DEF_FUNCTION(CLASS(File), "read", ARGLIST(argument_new(L_ATOM(filename), NULL, 0)), iridium_classmethod_name(File, read));
  DEF_METHOD(CLASS(File), "each_line", ARGLIST(argument_new(L_ATOM(fn), NULL, 0)), iridium_method_name(File, each_line));

  define_constant(L_ATOM(File), CLASS(File));
}
Пример #2
0

#include "allocator.hpp"

#define DEF_METHOD_ARGS(name, ...)  const AllocatorDataTy ALLOCATOR_METHODS_ARGS_##name[] = { __VA_ARGS__ };
#define DEF_METHOD(name, ret)   { #name, AllocatorDataTy::ret, sizeof(ALLOCATOR_METHODS_ARGS_##name)/sizeof(AllocatorDataTy), ALLOCATOR_METHODS_ARGS_##name }

DEF_METHOD_ARGS(alloc, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(oom, AllocatorDataTy::AllocError)
DEF_METHOD_ARGS(dealloc, AllocatorDataTy::Ptr, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(usable_size, AllocatorDataTy::LayoutRef)
DEF_METHOD_ARGS(realloc, AllocatorDataTy::Ptr, AllocatorDataTy::Layout, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(alloc_zeroed, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(alloc_excess, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(realloc_excess, AllocatorDataTy::Ptr, AllocatorDataTy::Layout, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(grow_in_place, AllocatorDataTy::Ptr, AllocatorDataTy::Layout, AllocatorDataTy::Layout)
DEF_METHOD_ARGS(shrink_in_place, AllocatorDataTy::Ptr, AllocatorDataTy::Layout, AllocatorDataTy::Layout)

const AllocatorMethod   ALLOCATOR_METHODS[10] = {
    DEF_METHOD(alloc, ResultPtr),
    DEF_METHOD(oom, Never),
    DEF_METHOD(dealloc, Unit),
    DEF_METHOD(usable_size, UsizePair),
    DEF_METHOD(realloc, ResultPtr),
    DEF_METHOD(alloc_zeroed, ResultPtr),
    DEF_METHOD(alloc_excess, ResultExcess),
    DEF_METHOD(realloc_excess, ResultExcess),
    DEF_METHOD(grow_in_place, ResultUnit),
    DEF_METHOD(shrink_in_place, ResultUnit)
    };
Пример #3
0
    p_gc = NULL;
};

static PyObject *gc_test( PyObject *self, PyObject *args )
{
     mygc *gc = (mygc *)malloc( sizeof( mygc ) );

     vlc_gc_init( gc, mygc_destructor, NULL );
     ASSERT( gc->i_gc_refcount == 0, "Refcount should be 0" );
     vlc_gc_incref( gc );
     ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
     vlc_gc_incref( gc );
     ASSERT( gc->i_gc_refcount == 2, "Refcount should be 2" );
     gc->i++;
     vlc_gc_decref( gc );
     ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
     vlc_gc_decref( gc );

     Py_INCREF( Py_None );
     return Py_None;
};

static PyMethodDef native_gc_test_methods[] = {
   DEF_METHOD( gc_test, "Test GC" )
   { NULL, NULL, 0, NULL }
};

asserts = 0;

DECLARE_MODULE( native_gc_test )