本文整理汇总了C++中Data_Wrap_Struct函数的典型用法代码示例。如果您正苦于以下问题:C++ Data_Wrap_Struct函数的具体用法?C++ Data_Wrap_Struct怎么用?C++ Data_Wrap_Struct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Data_Wrap_Struct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Data_Wrap_Struct
inline VALUE wrap< CEGUI::FrameComponent >(CEGUI::FrameComponent *framecomponent )
{
return Data_Wrap_Struct(rb_cCeguiFrameComponent, NULL, NULL, framecomponent);
}
示例2: cState_s_allocate
static VALUE cState_s_allocate(VALUE klass)
{
JSON_Generator_State *state = State_allocate();
return Data_Wrap_Struct(klass, NULL, State_free, state);
}
示例3: connection_parent_context_alloc
static VALUE connection_parent_context_alloc(VALUE klass) {
redisParentContext *pc = malloc(sizeof(*pc));
pc->context = NULL;
pc->timeout = NULL;
return Data_Wrap_Struct(klass, parent_context_mark, parent_context_free, pc);
}
示例4: rb_cogl_program_allocate
static VALUE
rb_cogl_program_allocate (VALUE klass)
{
return Data_Wrap_Struct (klass, NULL, rb_cogl_program_free, NULL);
}
示例5: new_object
VALUE
new_object(int blocksize)
{
CvMemStorage *storage = cvCreateMemStorage(blocksize);
return Data_Wrap_Struct(rb_klass, 0, free, storage);
}
示例6: fs_watcher_init
static VALUE
fs_watcher_init(VALUE arg) {
FSWatcher *watcher = (FSWatcher *) arg;
struct kevent *events;
VALUE filename;
unsigned int i;
uint32_t fflags;
VALUE filenum;
struct stat buf;
int fd;
/* Open each file in the filenames list and add each one to the events array. */
/* +2 for the termination pipe and the interruption pipe. */
events = alloca((RARRAY_LEN(watcher->filenames) + 2) * sizeof(struct kevent));
watcher->fds = malloc(RARRAY_LEN(watcher->filenames) * sizeof(int));
if (watcher->fds == NULL) {
rb_raise(rb_eNoMemError, "Cannot allocate memory.");
return Qnil;
}
for (i = 0; i < RARRAY_LEN(watcher->filenames); i++) {
filename = rb_ary_entry(watcher->filenames, i);
if (TYPE(filename) != T_STRING) {
filename = rb_obj_as_string(filename);
}
if (stat(RSTRING_PTR(filename), &buf) == -1) {
watcher->preparation_error = 1;
goto end;
}
#ifdef O_EVTONLY
fd = open(RSTRING_PTR(filename), O_EVTONLY);
#else
fd = open(RSTRING_PTR(filename), O_RDONLY);
#endif
if (fd == -1) {
watcher->preparation_error = 1;
goto end;
}
watcher->fds[i] = fd;
watcher->fds_len++;
fflags = NOTE_WRITE | NOTE_EXTEND | NOTE_RENAME | NOTE_DELETE | NOTE_REVOKE;
EV_SET(&events[i], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
fflags, 0, 0);
}
watcher->events_len = watcher->fds_len;
/* Create pipes for inter-thread communication. */
if (pipe(watcher->notification_fd) == -1) {
rb_sys_fail("pipe()");
return Qnil;
}
if (pipe(watcher->interruption_fd) == -1) {
rb_sys_fail("pipe()");
return Qnil;
}
/* Create a kqueue and register all events. */
watcher->kq = kqueue();
if (watcher->kq == -1) {
rb_sys_fail("kqueue()");
return Qnil;
}
if (watcher->termination_pipe != Qnil) {
filenum = rb_funcall(watcher->termination_pipe,
rb_intern("fileno"), 0);
EV_SET(&events[watcher->events_len], NUM2INT(filenum),
EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0);
watcher->termination_fd = NUM2INT(filenum);
watcher->events_len++;
}
EV_SET(&events[watcher->events_len], watcher->interruption_fd[0],
EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, 0);
watcher->events_len++;
if (kevent(watcher->kq, events, watcher->events_len, NULL, 0, NULL) == -1) {
rb_sys_fail("kevent()");
return Qnil;
}
end:
if (watcher->preparation_error) {
for (i = 0; i < watcher->fds_len; i++) {
close(watcher->fds[i]);
}
free(watcher->fds);
watcher->fds = NULL;
watcher->fds_len = 0;
}
return Data_Wrap_Struct(watcher->klass, NULL, fs_watcher_free, watcher);
}
示例7: allocate
static VALUE allocate(VALUE klass)
{
return Data_Wrap_Struct(klass, NULL, deallocate, NULL);
}
示例8: audio_stream_alloc
// Allocate object
VALUE audio_stream_alloc(VALUE klass) {
AudioStreamInternal * internal = (AudioStreamInternal *)av_mallocz(sizeof(AudioStreamInternal));
if (!internal) rb_raise(rb_eNoMemError, "Failed to allocate internal structure");
return Data_Wrap_Struct(klass, audio_stream_mark, audio_stream_free, (void *)internal);
}
示例9: virtualmachine_initialize
VALUE virtualmachine_initialize(VALUE self, VALUE vmname, VALUE memsize)
{
VALUE vctx, vvme;
struct vmctx *ctx;
struct vm_exit *vme;
uint64_t *gdt, *pt4, *pt3, *pt2;
int i, err;
_vm_create(StringValuePtr(vmname));
ctx = _vm_open(StringValuePtr(vmname));
vctx = Data_Wrap_Struct(rb_cVMCtx, NULL, vmctx_free, ctx);
vme = (struct vm_exit *)calloc(1, sizeof(*vme));
vvme = Data_Wrap_Struct(rb_cVMCtx, NULL, vme_free, vme);
rb_iv_set(self, "@ctx", vctx);
rb_iv_set(self, "@vmname", vmname);
rb_iv_set(self, "@memsize", memsize);
rb_iv_set(self, "@vmexit", vvme);
_vm_setup_memory(ctx, FIX2INT(memsize) * MB, VM_MMAP_ALL);
pt4 = _vm_map_gpa(ctx, ADDR_PT4, sizeof(uint64_t) * 512);
pt3 = _vm_map_gpa(ctx, ADDR_PT3, sizeof(uint64_t) * 512);
pt2 = _vm_map_gpa(ctx, ADDR_PT2, sizeof(uint64_t) * 512);
gdt = _vm_map_gpa(ctx, ADDR_GDT, sizeof(uint64_t) * 3);
bzero(pt4, PAGE_SIZE);
bzero(pt3, PAGE_SIZE);
bzero(pt2, PAGE_SIZE);
for (i = 0; i < 512; i++) {
pt4[i] = (uint64_t)ADDR_PT3;
pt4[i] |= PG_V | PG_RW | PG_U;
pt3[i] = (uint64_t)ADDR_PT2;
pt3[i] |= PG_V | PG_RW | PG_U;
pt2[i] = i * (2 * 1024 * 1024);
pt2[i] |= PG_V | PG_RW | PG_PS | PG_U;
}
gdt[GUEST_NULL_SEL] = 0;
gdt[GUEST_CODE_SEL] = 0x0020980000000000;
gdt[GUEST_DATA_SEL] = 0x0000900000000000;
_vm_set_desc(ctx, 0, VM_REG_GUEST_CS, 0, 0, 0x0000209B);
_vm_set_desc(ctx, 0, VM_REG_GUEST_DS, 0, 0, 0x00000093);
_vm_set_desc(ctx, 0, VM_REG_GUEST_ES, 0, 0, 0x00000093);
_vm_set_desc(ctx, 0, VM_REG_GUEST_FS, 0, 0, 0x00000093);
_vm_set_desc(ctx, 0, VM_REG_GUEST_GS, 0, 0, 0x00000093);
_vm_set_desc(ctx, 0, VM_REG_GUEST_SS, 0, 0, 0x00000093);
_vm_set_desc(ctx, 0, VM_REG_GUEST_TR, 0, 0, 0x0000008b);
_vm_set_desc(ctx, 0, VM_REG_GUEST_LDTR, 0, 0, DESC_UNUSABLE);
_vm_set_desc(ctx, 0, VM_REG_GUEST_GDTR, ADDR_GDT, GUEST_GDTR_LIMIT, 0);
_vm_set_register(ctx, 0, VM_REG_GUEST_CS, GSEL(GUEST_CODE_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_DS, GSEL(GUEST_DATA_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_ES, GSEL(GUEST_DATA_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_FS, GSEL(GUEST_DATA_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_GS, GSEL(GUEST_DATA_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_SS, GSEL(GUEST_DATA_SEL, SEL_KPL));
_vm_set_register(ctx, 0, VM_REG_GUEST_TR, 0);
_vm_set_register(ctx, 0, VM_REG_GUEST_LDTR, 0);
_vm_set_register(ctx, 0, VM_REG_GUEST_CR0, CR0_PG | CR0_PE | CR0_NE);
_vm_set_register(ctx, 0, VM_REG_GUEST_CR3, ADDR_PT4);
_vm_set_register(ctx, 0, VM_REG_GUEST_CR4, CR4_PAE | CR4_VMXE);
_vm_set_register(ctx, 0, VM_REG_GUEST_EFER, EFER_LMA | EFER_LME);
_vm_set_register(ctx, 0, VM_REG_GUEST_RFLAGS, 0x2);
_vm_set_register(ctx, 0, VM_REG_GUEST_RSP, ADDR_STACK);
return self;
}
示例10: allocate
static VALUE allocate(VALUE klass)
{
alpm_handle_t* p_alpm = NULL;
VALUE obj = Data_Wrap_Struct(klass, 0, deallocate, p_alpm);
return obj;
}
示例11: fdbm_alloc
static VALUE
fdbm_alloc(VALUE klass)
{
return Data_Wrap_Struct(klass, 0, free_dbm, 0);
}
示例12: ra_sound_allocate
static VALUE ra_sound_allocate(VALUE klass) {
RA_SOUND *snd = ALLOC(RA_SOUND);
memset(snd, 0, sizeof(RA_SOUND));
VALUE self = Data_Wrap_Struct(klass, ra_sound_mark, ra_sound_free, snd);
return self;
}
示例13: rxml_xpath_context_alloc
static VALUE rxml_xpath_context_alloc(VALUE klass)
{
return Data_Wrap_Struct(cXMLXPathContext, rxml_xpath_context_mark, rxml_xpath_context_free, NULL);
}
示例14: rb_binding_new_from_binding
VALUE
rb_binding_new_from_binding(rb_vm_binding_t *bind)
{
return Data_Wrap_Struct(rb_cBinding, NULL, NULL, bind);
}
示例15: rb_allocate
VALUE
rb_allocate(VALUE klass)
{
CvMemStorage *storage = cvCreateMemStorage();
return Data_Wrap_Struct(klass, 0, free, storage);
}