static void parse_methods(const char *p) { const compress_t *c; for (;;) { if (p == NULL || p[0] == 0) usage(argv0,-1,1); else if ((c = find_method(p)) != NULL) add_method(c->id); else if (m_strcmp(p,"all") == 0 || m_strcmp(p,"avail") == 0) add_all_methods(1,M_LAST_COMPRESSOR); else if (m_strcmp(p,"ALL") == 0) { add_all_methods(1,M_LAST_COMPRESSOR); add_all_methods(9721,9729); add_all_methods(9781,9789); } else if (m_strcmp(p,"lzo") == 0) add_all_methods(1,M_MEMCPY); else if (m_strcmp(p,"bench") == 0) add_methods(benchmark_methods); else if (m_strcmp(p,"m1") == 0) add_methods(x1_methods); else if (m_strcmp(p,"m99") == 0) add_methods(x99_methods); else if (m_strcmp(p,"m999") == 0) add_methods(x999_methods); else if (m_strcmp(p,"1x999") == 0) add_all_methods(9721,9729); else if (m_strcmp(p,"1y999") == 0) add_all_methods(9821,9829); #if defined(ALG_ZLIB) else if (m_strcmp(p,"zlib") == 0) add_all_methods(M_ZLIB_8_1,M_ZLIB_8_9); #endif #if defined(MFX) # include "maint/t_opt_m.ch" #endif else if (m_strisdigit(p)) add_method(atoi(p)); else { printf("%s: invalid method '%s'\n\n",argv0,p); exit(EXIT_USAGE); } while (*p && *p != ',') p++; while (*p == ',') p++; if (*p == 0) return; } }
SIMPLE_IPC() { // turn on socket support SimpleIPC::SocketsService::Instance(); add_methods( this ) .def("CreatePort", CreatePort, "port") .def("Connect", Connect, "port", "addr") ; }
SimpleIPCPortProxy( SimpleIPC::NetworkEntity *entity ): SimpleIPC::Port( entity ) { add_methods( this ) .def_remap_0< std::string >("Recv", &SimpleIPC::Port::Recv ) .def_remap_0< std::string >("WaitRecv", &SimpleIPC::Port::WaitRecv ) .def_remap_1< void, TextUtf8 >("Send", (void (SimpleIPC::Port::*)( const std::string &))&SimpleIPC::Port::Send, "msg") .def("SendEnd", &SimpleIPC::Port::SendEnd ) ; }
/* * call-seq: * Module.load(String) => Module * * Load a module from a string. */ static VALUE module_load(VALUE klass, VALUE str) { VALUE arr, class_name, metaclass_str, metaclass, superclass_name, included_modules, class_variables_str, class_variables, instance_methods_str, instance_methods, flags, module; if( rb_safe_level() >= 4 || (rb_safe_level() >= 1 && OBJ_TAINTED(str))) { /* no playing with knives in the sandbox */ rb_raise(rb_eSecurityError, "Insecure: can't load module"); } arr = marshal_load(str); class_name = rb_ary_pop(arr); metaclass_str = rb_ary_pop(arr); superclass_name = rb_ary_pop(arr); included_modules = rb_ary_pop(arr); class_variables_str = rb_ary_pop(arr); instance_methods_str = rb_ary_pop(arr); flags = rb_ary_pop(arr); if(RTEST(superclass_name)) { VALUE superclass; rb_check_type(superclass_name, T_STRING); superclass = rb_funcall( lookup_module_proc, rb_intern("call"), 1, superclass_name); #if RUBY_VERSION_CODE >= 180 /* Can't make subclass of Class on 1.8.x */ module = rb_class_boot(superclass); rb_define_alloc_func(module, module_instance_allocate); #else module = rb_class_new(superclass); #endif } else { module = rb_module_new(); } if(!NIL_P(class_name)) { VALUE outer_module = rb_funcall(outer_module_proc, rb_intern("call"), 1, class_name); VALUE module_name = rb_funcall(module_name_proc, rb_intern("call"), 1, class_name); rb_const_set(outer_module, SYM2ID(module_name), module); } RBASIC(module)->flags = NUM2INT(flags); include_modules(module, included_modules); class_variables = marshal_load(class_variables_str); add_class_variables(module, class_variables); instance_methods = marshal_load(instance_methods_str); add_methods(module, instance_methods); metaclass = marshal_load(metaclass_str); if(RTEST(metaclass)) { rb_singleton_class_attached(metaclass, module); RBASIC(module)->klass = metaclass; } return module; }
static int riva_load(module_t *Module, const char *FileName) { riva_t *Riva = unew(riva_t); // This really should be new... module_setup(Module, Riva, (module_importer)riva_import); gzFile File = gzopen(FileName, "rb"); char *LoadPath; for (int I = strlen(FileName) - 1; I >= 0; --I) { if (FileName[I] == PATHCHR) { strncpy(LoadPath = (char *)GC_malloc_atomic(I + 2), FileName, I + 1); break; }; }; module_set_path(Module, LoadPath); uint32_t Magic; gzread(File, &Magic, 4); if (Magic != 0x41564952) { log_errorf("Error: %s is not a valid riva module\n", FileName); return 0; }; uint32_t NoOfSections; gzread(File, &NoOfSections, 4); uint32_t NoOfExports; gzread(File, &NoOfExports, 4); uint32_t NoOfRequires; gzread(File, &NoOfRequires, 4); jmp_buf OnError[1]; if (setjmp(OnError)) return 0; section_t **Sections = (Riva->Sections = (section_t **)GC_malloc(NoOfSections * sizeof(section_t *))); for (int I = 0; I < NoOfSections; ++I) Sections[I] = new(section_t); for (int I = 0; I < NoOfSections; ++I) { section_t *Section = Sections[I]; uint8_t Type; gzread(File, &Type, 1); switch (Type) { case SECT_CODE: { Section->Fixup = fixup_code_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); uint32_t NoOfRelocs; gzread(File, &NoOfRelocs, 4); Section->NoOfRelocs = NoOfRelocs; reloc_t *Relocs = (Section->Relocs = (reloc_t *)GC_malloc_uncollectable(NoOfRelocs * sizeof(reloc_t))); if (Section->Flags & FLAG_GC) { Section->Data = GC_malloc_uncollectable(Length); } else { Section->Data = GC_malloc_atomic_uncollectable(Length); }; gzread(File, Section->Data, Length); for (int J = 0; J < NoOfRelocs; ++J) { reloc_t *Reloc = &Relocs[J]; gzread(File, &Reloc->Size, 1); gzread(File, &Reloc->Flags, 1); gzread(File, &Reloc->Position, 4); uint32_t Index; gzread(File, &Index, 4); Reloc->Section = Sections[Index]; }; break;}; case SECT_LIBRARY: { Section->Fixup = fixup_library_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; if (Section->Flags == LIBRARY_ABS) { Section->Path = 0; } else if (Section->Flags == LIBRARY_REL) { Section->Path = LoadPath; }; for (char *P = Section->Name; *P; ++P) if (*P == '/') *P = PATHCHR; break;}; case SECT_IMPORT: { Section->Fixup = fixup_import_section; gzread(File, &Section->Flags, 1); uint32_t Index; gzread(File, &Index, 4); Section->Library = Sections[Index]; uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; break;}; case SECT_BSS: { Section->Fixup = fixup_bss_section; gzread(File, &Section->Flags, 1); uint32_t Size; gzread(File, &Size, 4); Section->Data = (uint8_t *)GC_malloc(Size); break;}; case SECT_SYMBOL: { Section->Fixup = fixup_symbol_section; gzread(File, &Section->Flags, 1); uint32_t Length; gzread(File, &Length, 4); gzread(File, Section->Name = (char *)GC_malloc_atomic(Length + 1), Length); Section->Name[Length] = 0; break;}; }; }; for (int I = 0; I < NoOfExports; ++I) { export_t *Export = new(export_t); gzread(File, &Export->Flags, 1); uint32_t Index; gzread(File, &Index, 4); Export->Section = Sections[Index]; gzread(File, &Export->Offset, 4); uint32_t Length; gzread(File, &Length, 4); char *Name = (char *)GC_malloc_atomic(Length + 1); gzread(File, Name, Length); Name[Length] = 0; stringtable_put(Riva->Exports, Name, Export); }; for (int I = 0; I < NoOfRequires; ++I) { uint8_t Flags; gzread(File, &Flags, 1); uint32_t Length; gzread(File, &Length, 4); char *Name = (char *)GC_malloc_atomic(Length + 1); char *Path = 0; gzread(File, Name, Length); Name[Length] = 0; if (Flags == LIBRARY_REL) Path = LoadPath; for (char *P = Name; *P; ++P) if (*P == '/') *P = PATHCHR; module_load(Path, Name); }; gzclose(File); void (*__init)(module_t *) = check_import(Riva, "__init", OnError); if (__init) __init(Module); void *Methods = check_import(Riva, "__methods", OnError); if (Methods) add_methods(Methods); return 1; };