void Init_vm_eval(void) { rb_objc_define_module_function(rb_mKernel, "catch", rb_f_catch, -1); rb_objc_define_module_function(rb_mKernel, "throw", rb_f_throw, -1); rb_objc_define_module_function(rb_mKernel, "loop", rb_f_loop, 0); rb_objc_define_method(rb_cNSObject, "instance_eval", rb_obj_instance_eval_imp, -3); rb_objc_define_method(rb_cNSObject, "instance_exec", rb_obj_instance_exec, -1); rb_objc_define_private_method(rb_cNSObject, "method_missing", rb_method_missing, -1); rb_objc_define_method(rb_cNSObject, "__send__", rb_f_send, -1); rb_objc_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval_imp, -3); rb_objc_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1); rb_objc_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1); rb_objc_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_objc_define_method(rb_mKernel, "send", rb_f_send, -1); rb_objc_define_method(rb_mKernel, "public_send", rb_f_public_send, -1); rb_objc_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1); rb_objc_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1); rb_objc_define_module_function(rb_mKernel, "caller", rb_f_caller, -1); }
void Init_load() { const char *var_load_path = "$:"; ID id_load_path = rb_intern(var_load_path); rbo_enabled = !ruby_is_miniruby && getenv("VM_DISABLE_RBO") == NULL; rb_define_virtual_variable("$:", rb_vm_load_path, 0); rb_alias_variable((rb_intern)("$-I"), id_load_path); rb_alias_variable((rb_intern)("$LOAD_PATH"), id_load_path); rb_define_virtual_variable("$\"", rb_vm_loaded_features, 0); rb_define_virtual_variable("$LOADED_FEATURES", rb_vm_loaded_features, 0); rb_objc_define_module_function(rb_mKernel, "load", rb_f_load, -1); rb_objc_define_module_function(rb_mKernel, "require", rb_f_require_imp, 1); rb_objc_define_method(rb_cModule, "autoload", rb_mod_autoload, 2); rb_objc_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1); rb_objc_define_module_function(rb_mKernel, "autoload", rb_f_autoload, 2); rb_objc_define_module_function(rb_mKernel, "autoload?", rb_f_autoload_p, 1); rb_objc_define_module_function(rb_mKernel, "framework", rb_require_framework, -1); }
void rb_define_object_special_methods(VALUE klass) { RCLASS_SET_VERSION(*(VALUE *)klass, (RCLASS_VERSION(*(VALUE *)klass) | RCLASS_HAS_ROBJECT_ALLOC)); rb_objc_define_method(*(VALUE *)klass, "new", rb_class_new_instance_imp, -1); rb_objc_define_method(klass, "dup", rb_obj_dup, 0); rb_objc_define_private_method(klass, "initialize", rb_objc_init, -1); rb_objc_define_private_method(klass, "initialize_copy", rb_obj_init_copy, 1); rb_objc_define_method(klass, "hash", rb_obj_id, 0); // To make sure singleton classes will be filtered. rb_objc_define_method(*(VALUE *)klass, "superclass", rb_obj_superclass, 0); rb_objc_define_method(klass, "class", rb_obj_class, 0); rb_objc_install_method(*(Class *)klass, selAllocWithZone, (IMP)rb_obj_imp_allocWithZone); rb_objc_install_method((Class)klass, selIsEqual, (IMP)rb_obj_imp_isEqual); rb_objc_install_method((Class)klass, selInit, (IMP)rb_obj_imp_init); rb_objc_install_method((Class)klass, selDescription, (IMP)rb_obj_imp_description); // Create -copyWithZone:, since the method doesn't exist yet we need to // find the type encoding somewhere, here we check Symbol since it's // created very early. Method m = class_getInstanceMethod((Class)rb_cSymbol, selCopyWithZone); assert(m != NULL); class_replaceMethod((Class)klass, selCopyWithZone, (IMP)rb_obj_imp_copyWithZone, method_getTypeEncoding(m)); }
/* * Many operating systems allow signals to be sent to running * processes. Some signals have a defined effect on the process, while * others may be trapped at the code level and acted upon. For * example, your process may trap the USR1 signal and use it to toggle * debugging, and may use TERM to initiate a controlled shutdown. * * pid = fork do * Signal.trap("USR1") do * $debug = !$debug * puts "Debug now: #$debug" * end * Signal.trap("TERM") do * puts "Terminating..." * shutdown() * end * # . . . do some work . . . * end * * Process.detach(pid) * * # Controlling program: * Process.kill("USR1", pid) * # ... * Process.kill("USR1", pid) * # ... * Process.kill("TERM", pid) * * produces: * Debug now: true * Debug now: false * Terminating... * * The list of available signal names and their interpretation is * system dependent. Signal delivery semantics may also vary between * systems; in particular signal delivery may not always be reliable. */ void Init_signal(void) { #ifndef MACOS_UNUSE_SIGNAL VALUE mSignal = rb_define_module("Signal"); rb_objc_define_module_function(rb_mKernel, "trap", sig_trap, -1); rb_objc_define_method(*(VALUE *)mSignal, "trap", sig_trap, -1); rb_objc_define_method(*(VALUE *)mSignal, "list", sig_list, 0); rb_objc_define_method(rb_eSignal, "initialize", esignal_init, -1); rb_objc_define_method(rb_eSignal, "signo", esignal_signo, 0); rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message")); rb_objc_define_method(rb_eInterrupt, "initialize", interrupt_init, -1); /* install_sighandler(SIGINT, sighandler); */ /* install_sighandler(SIGHUP, sighandler); */ /* install_sighandler(SIGQUIT, sighandler); */ /* install_sighandler(SIGTERM, sighandler); */ /* install_sighandler(SIGALRM, sighandler); */ /* install_sighandler(SIGUSR1, sighandler); */ /* install_sighandler(SIGUSR2, sighandler); */ #ifdef RUBY_DEBUG_ENV if (!ruby_enable_coredump) #endif install_sighandler(SIGPIPE, sigpipe); init_sigchld(SIGCHLD); #endif /* !MACOS_UNUSE_SIGNAL */ }
static VALUE make_struct(VALUE name, VALUE members, VALUE klass) { VALUE nstr; ID id; long i, len; OBJ_FREEZE(members); if (NIL_P(name)) { nstr = rb_class_new(klass); #if !WITH_OBJC rb_make_metaclass(nstr, RBASIC(klass)->klass); #endif rb_class_inherited(klass, nstr); } else { /* old style: should we warn? */ name = rb_str_to_str(name); id = rb_to_id(name); if (!rb_is_const_id(id)) { rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); } if (rb_const_defined_at(klass, id)) { rb_warn("redefining constant Struct::%s", StringValuePtr(name)); rb_mod_remove_const(klass, ID2SYM(id)); } nstr = rb_define_class_under(klass, rb_id2name(id), klass); } rb_ivar_set(nstr, id_members, members); rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0); rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0); len = RARRAY_LEN(members); for (i=0; i< len; i++) { ID id = SYM2ID(RARRAY_AT(members, i)); if (rb_is_local_id(id) || rb_is_const_id(id)) { long j = i; /* Needed for block data reference. */ /* Struct attribute reader */ rb_objc_define_method(nstr, rb_id2name(id), pl_imp_implementationWithBlock(^(VALUE obj) { return RSTRUCT_PTR(obj)[j]; }), 0); /* Struct attribute writer */ rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)), pl_imp_implementationWithBlock(^(VALUE obj, VALUE val) { VALUE *ptr = RSTRUCT_PTR(obj); rb_struct_modify(obj); GC_WB(&ptr[i], val); return val; }), 1);
void rb_objc_define_module_function(VALUE module, const char *name, void *imp, const int arity) { rb_objc_define_private_method(module, name, imp, arity); rb_objc_define_method(*(VALUE *)module, name, imp, arity); }
void Init_eval_method(void) { rb_objc_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); rb_objc_define_method(rb_mKernel, "respond_to_missing?", obj_respond_to_missing, 2); selRespondToDefault = sel_registerName("respond_to_missing?:"); basic_respond_to_imp = class_getMethodImplementation((Class)rb_mKernel, selRespondTo); rb_objc_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1); rb_objc_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1); rb_objc_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_objc_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_objc_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_objc_define_private_method(rb_cModule, "private", rb_mod_private, -1); rb_objc_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_objc_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1); rb_objc_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); rb_objc_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1); rb_objc_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1); rb_objc_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_objc_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); VALUE cTopLevel = *(VALUE *)rb_vm_top_self(); rb_objc_define_method(cTopLevel, "public", top_public, -1); rb_objc_define_method(cTopLevel, "private", top_private, -1); object_id = rb_intern("object_id"); __send__ = rb_intern("__send__"); eqq = rb_intern("==="); each = rb_intern("each"); aref = rb_intern("[]"); aset = rb_intern("[]="); match = rb_intern("=~"); missing = rb_intern("method_missing"); added = rb_intern("method_added"); singleton_added = rb_intern("singleton_method_added"); removed = rb_intern("method_removed"); singleton_removed = rb_intern("singleton_method_removed"); undefined = rb_intern("method_undefined"); singleton_undefined = rb_intern("singleton_method_undefined"); }
/* * INIT */ void Init_ossl_digest() { rb_require("digest"); #if 0 /* let rdoc know about mOSSL */ mOSSL = rb_define_module("OpenSSL"); #endif cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class")); eDigestError = rb_define_class_under(cDigest, "DigestError", eOSSLError); rb_objc_define_method(*(VALUE *)cDigest, "alloc", ossl_digest_alloc, 0); rb_objc_define_method(cDigest, "initialize", ossl_digest_initialize, -1); rb_define_copy_func(cDigest, ossl_digest_copy); rb_objc_define_method(cDigest, "reset", ossl_digest_reset, 0); rb_objc_define_method(cDigest, "update", ossl_digest_update, 1); rb_define_alias(cDigest, "<<", "update"); rb_objc_define_private_method(cDigest, "finish", ossl_digest_finish, -1); rb_objc_define_method(cDigest, "digest_length", ossl_digest_size, 0); rb_objc_define_method(cDigest, "block_length", ossl_digest_block_length, 0); rb_objc_define_method(cDigest, "name", ossl_digest_name, 0); }
void Init_Binding(void) { rb_cBinding = rb_define_class("Binding", rb_cObject); rb_undef_alloc_func(rb_cBinding); rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_objc_define_method(rb_cBinding, "clone", binding_clone, 0); rb_objc_define_method(rb_cBinding, "dup", binding_dup, 0); rb_objc_define_method(rb_cBinding, "eval", bind_eval, -1); rb_objc_define_module_function(rb_mKernel, "binding", rb_f_binding, 0); rb_vm_binding_t *binding = (rb_vm_binding_t *)xmalloc( sizeof(rb_vm_binding_t)); GC_WB(&binding->self, rb_vm_top_self()); binding->outer_stack = NULL; rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new_from_binding(binding)); }
VALUE rb_define_module_id(ID id) { const char *name = id == 0 ? NULL : rb_id2name(id); VALUE mdl = rb_objc_alloc_class(name, rb_cModuleObject, T_MODULE, rb_cModule); if (rb_mKernel != 0 && id == 0) { // Because Module#initialize can accept a block. rb_objc_define_method(*(VALUE *)mdl, "initialize", rb_mod_initialize, 0); } return mdl; }
/* * This module adds some methods to Digest classes to perform * BubbleBabble encoding. */ void Init_bubblebabble(void) { VALUE mDigest, mDigest_Instance, cDigest_Class; rb_require("digest"); mDigest = rb_path2class("Digest"); mDigest_Instance = rb_path2class("Digest::Instance"); cDigest_Class = rb_path2class("Digest::Class"); /* Digest::bubblebabble() */ rb_objc_define_method(*(VALUE *)mDigest, "bubblebabble", rb_digest_s_bubblebabble, 1); /* Digest::Class::bubblebabble() */ rb_objc_define_method(*(VALUE *)cDigest_Class, "bubblebabble", rb_digest_class_s_bubblebabble, -1); /* Digest::Instance#bubblebabble() */ rb_define_method(mDigest_Instance, "bubblebabble", rb_digest_instance_bubblebabble, 0); id_digest = rb_intern("digest"); }
void Init_eval(void) { rb_define_virtual_variable("$@", errat_getter, errat_setter); rb_define_virtual_variable("$!", errinfo_getter, 0); rb_objc_define_module_function(rb_mKernel, "eval", rb_f_eval, -1); rb_objc_define_module_function(rb_mKernel, "iterator?", rb_f_block_given_p, 0); rb_objc_define_module_function(rb_mKernel, "block_given?", rb_f_block_given_p, 0); rb_objc_define_module_function(rb_mKernel, "fail", rb_f_raise, -1); rb_objc_define_module_function(rb_mKernel, "raise", rb_f_raise, -1); rb_objc_define_module_function(rb_mKernel, "global_variables", rb_f_global_variables, 0); /* in variable.c */ rb_objc_define_module_function(rb_mKernel, "local_variables", rb_f_local_variables, 0); rb_objc_define_method(rb_mKernel, "__method__", rb_f_method_name, 0); rb_objc_define_method(rb_mKernel, "__callee__", rb_f_method_name, 0); rb_objc_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1); rb_objc_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1); rb_objc_define_private_method(rb_cModule, "include", rb_mod_include, -1); rb_objc_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1); rb_objc_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1); rb_undef_method(rb_cClass, "module_function"); Init_vm_eval(); Init_eval_method(); rb_objc_define_method(*(VALUE *)rb_cModule, "nesting", rb_mod_nesting, -3); rb_objc_define_method(*(VALUE *)rb_cModule, "constants", rb_mod_s_constants, -1); VALUE cTopLevel = *(VALUE *)rb_vm_top_self(); rb_objc_define_method(cTopLevel, "include", top_include, -1); rb_objc_define_method(rb_mKernel, "extend", rb_obj_extend, -1); rb_objc_define_module_function(rb_mKernel, "trace_var", rb_f_trace_var, -1); /* in variable.c */ rb_objc_define_module_function(rb_mKernel, "untrace_var", rb_f_untrace_var, -1); /* in variable.c */ rb_define_virtual_variable("$SAFE", safe_getter, safe_setter); exception_error = rb_exc_new2(rb_eFatal, "exception reentered"); //rb_ivar_set(exception_error, idThrowState, INT2FIX(TAG_FATAL)); GC_RETAIN(exception_error); }
static VALUE make_struct(VALUE name, VALUE members, VALUE klass) { VALUE nstr; ID id; long i, count; OBJ_FREEZE(members); if (NIL_P(name)) { nstr = rb_class_new(klass); #if !WITH_OBJC rb_make_metaclass(nstr, RBASIC(klass)->klass); #endif rb_class_inherited(klass, nstr); } else { /* old style: should we warn? */ name = rb_str_to_str(name); id = rb_to_id(name); if (!rb_is_const_id(id)) { rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); } if (rb_const_defined_at(klass, id)) { rb_warn("redefining constant Struct::%s", StringValuePtr(name)); rb_mod_remove_const(klass, ID2SYM(id)); } nstr = rb_define_class_under(klass, rb_id2name(id), klass); } rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY_LEN(members))); rb_iv_set(nstr, "__members__", members); rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0); rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0); for (i = 0, count = RARRAY_LEN(members); i < count; i++) { ID id = SYM2ID(RARRAY_AT(members, i)); if (rb_is_local_id(id) || rb_is_const_id(id)) { if (i < N_REF_FUNC) { rb_objc_define_method(nstr, rb_id2name(id), ref_func[i], 0); } else { rb_objc_define_method(nstr, rb_id2name(id), rb_struct_ref, 0); } rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)), rb_struct_set, 1); } } return nstr; }
void Init_GC(void) { VALUE rb_mObSpace; rb_mGC = rb_define_module("GC"); rb_objc_define_module_function(rb_mGC, "start", rb_gc_start, 0); rb_objc_define_module_function(rb_mGC, "enable", rb_gc_enable, 0); rb_objc_define_module_function(rb_mGC, "disable", rb_gc_disable, 0); rb_objc_define_module_function(rb_mGC, "stress", gc_stress_get, 0); rb_objc_define_module_function(rb_mGC, "stress=", gc_stress_set, 1); rb_objc_define_module_function(rb_mGC, "count", gc_count, 0); rb_objc_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0); rb_mObSpace = rb_define_module("ObjectSpace"); rb_objc_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1); rb_objc_define_module_function(rb_mObSpace, "garbage_collect", rb_gc_start, 0); rb_objc_define_module_function(rb_mObSpace, "define_finalizer", define_final, -1); rb_objc_define_module_function(rb_mObSpace, "undefine_finalizer", undefine_final, 1); rb_objc_define_module_function(rb_mObSpace, "_id2ref", id2ref, 1); nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); GC_RETAIN(nomem_error); rb_objc_define_method(rb_mKernel, "__id__", rb_obj_id, 0); rb_objc_define_method(rb_mKernel, "object_id", rb_obj_id, 0); rb_objc_define_module_function(rb_mObSpace, "count_objects", count_objects, -1); rb_cFinalizer = rb_define_class("__Finalizer", rb_cObject); rb_objc_finalizer_finalize_super = rb_objc_install_method2((Class)rb_cFinalizer, "finalize", (IMP)rb_objc_finalizer_finalize); }
void Init_Comparable(void) { rb_mComparable = rb_define_module("Comparable"); rb_objc_define_method(rb_mComparable, "==", cmp_equal, 1); rb_objc_define_method(rb_mComparable, ">", cmp_gt, 1); rb_objc_define_method(rb_mComparable, ">=", cmp_ge, 1); rb_objc_define_method(rb_mComparable, "<", cmp_lt, 1); rb_objc_define_method(rb_mComparable, "<=", cmp_le, 1); rb_objc_define_method(rb_mComparable, "between?", cmp_between, 2); cmp = sel_registerName("<=>:"); }
VALUE rb_struct_define_without_accessor(const char *class_name, VALUE super, rb_alloc_func_t alloc, ...) { VALUE klass; va_list ar; VALUE members; long i; char *name; members = rb_ary_new2(0); va_start(ar, alloc); i = 0; while ((name = va_arg(ar, char*)) != NULL) { rb_ary_push(members, ID2SYM(rb_intern(name))); } va_end(ar); OBJ_FREEZE(members); if (class_name) { klass = rb_define_class(class_name, super); } else { klass = rb_class_new(super); rb_make_metaclass(klass, RBASIC(super)->klass); rb_class_inherited(super, klass); } rb_iv_set(klass, "__size__", LONG2NUM(RARRAY_LEN(members))); rb_iv_set(klass, "__members__", members); rb_objc_define_method(*(VALUE *)klass, "alloc", alloc != NULL ? alloc : struct_alloc, 0); return klass; }
void Init_Dispatch(void) { high_priority_id = rb_intern("high"); low_priority_id = rb_intern("low"); default_priority_id = rb_intern("default"); /* * Grand Central Dispatch (GCD) is a novel approach to multicore computing * first release in Mac OS X version 10.6 Snow Leopard, and available as * open source via the libdispatch project. GCD shifts the * responsibility for managing threads and their execution from * applications onto the operating system. This allows programmers to easily * refactor their programs into small chunks of independent work, which GCD * then schedules onto per-process thread pools. Because GCD knows the load * across the entire system, it ensures the resulting programs perform * optimally on a wide range of hardware. * * The Dispatch module allows Ruby blocks to be scheduled for asynchronous and * concurrent execution, either explicitly or in response to * various kinds of events. It provides a convenient high-level interface * to the underlying C API via objects for the four primary abstractions. * * Dispatch::Queue is the basic units of organization of blocks. * Several queues are created by default, and applications may create * additional queues for their own use. * * Dispatch::Group allows applications to track the progress of blocks * submitted to queues and take action when the blocks complete. * * Dispatch::Source monitors and coalesces low-level system events so that they * can be responded to asychronously via simple event handlers. * * Dispatch::Semaphore synchronizes threads via a combination of * waiting and signalling. * * For more information, see the dispatch(3)[http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man3/dispatch.3.html] man page. */ mDispatch = rb_define_module("Dispatch"); cObject = rb_define_class_under(mDispatch, "Object", rb_cObject); rb_objc_define_method(cObject, "resume!", rb_dispatch_resume, 0); rb_objc_define_method(cObject, "suspend!", rb_dispatch_suspend, 0); rb_objc_define_method(cObject, "suspended?", rb_dispatch_suspended_p, 0); // This API allows Ruby code to pass the internal dispatch_queue_t object // to C/Objective-C APIs. class_replaceMethod((Class)cObject, sel_registerName("dispatch_object"), (IMP)dispatch_object_imp, "^v@:"); /* * A Dispatch::Queue is the fundamental mechanism for scheduling blocks for * execution, either synchronously or asychronously. * * All blocks submitted to dispatch queues begin executing in the order * they were received. The system-defined concurrent queues can execute * multiple blocks in parallel, depending on the number of idle threads * in the thread pool. Serial queues (the main and user-created queues) * wait for the prior block to complete before dequeuing and executing * the next block. * * Queues are not bound to any specific thread of execution and blocks * submitted to independent queues may execute concurrently. */ cQueue = rb_define_class_under(mDispatch, "Queue", cObject); rb_objc_define_method(*(VALUE *)cQueue, "alloc", rb_queue_alloc, 0); rb_objc_define_method(*(VALUE *)cQueue, "concurrent", rb_queue_get_concurrent, -1); rb_objc_define_method(*(VALUE *)cQueue, "current", rb_queue_get_current, 0); rb_objc_define_method(*(VALUE *)cQueue, "main", rb_queue_get_main, 0); rb_objc_define_method(cQueue, "initialize", rb_queue_init, 1); rb_objc_define_method(cQueue, "initialize", rb_raise_init, 0); rb_objc_define_method(cQueue, "apply", rb_queue_apply, 1); rb_objc_define_method(cQueue, "async", rb_queue_dispatch_async, -1); rb_objc_define_method(cQueue, "sync", rb_queue_dispatch_sync, 0); rb_objc_define_method(cQueue, "after", rb_queue_dispatch_after, 1); rb_objc_define_method(cQueue, "label", rb_queue_label, 0); // deprecated rb_objc_define_method(cQueue, "to_s", rb_queue_label, 0); rb_queue_finalize_super = rb_objc_install_method2((Class)cQueue, "finalize", (IMP)rb_queue_finalize); qHighPriority = rb_queue_from_dispatch(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0), true); qDefaultPriority = rb_queue_from_dispatch(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), true); qLowPriority = rb_queue_from_dispatch(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), true); qMain = rb_queue_from_dispatch(dispatch_get_main_queue(), true); rb_objc_define_method(rb_singleton_class(qMain), "run", rb_main_queue_run, 0); /* * Dispatch::Group is used to aggregate multiple blocks * that have been submitted asynchronously to different queues. * This lets you ensure they have all completed before beginning * or submitting additional work. */ cGroup = rb_define_class_under(mDispatch, "Group", cObject); rb_objc_define_method(*(VALUE *)cGroup, "alloc", rb_group_alloc, 0); rb_objc_define_method(cGroup, "initialize", rb_group_init, 0); rb_objc_define_method(cGroup, "notify", rb_group_notify, 1); rb_objc_define_method(cGroup, "on_completion", rb_group_notify, 1); // deprecated rb_objc_define_method(cGroup, "wait", rb_group_wait, -1); rb_group_finalize_super = rb_objc_install_method2((Class)cGroup, "finalize", (IMP)rb_group_finalize); /* * Dispatch::Source monitors a variety of system objects and events including * file descriptors, processes, virtual filesystem nodes, signals and timers. * * When a state change occurs, the dispatch source will submit its event * handler block to its target queue, with the source as a parameter. * * gcdq = Dispatch::Queue.new('doc') * src = Dispatch::Source.new(Dispatch::Source::DATA_ADD, 0, 0, gcdq) do |s| * puts "Fired with #{s.data}" * end * * Unlike GCD's C API, Dispatch::Source objects start off resumed * (since the event handler -et al- have already been set). * * src.suspended? #=? false * src.merge(0) * gcdq.sync { } #=> Fired! */ cSource = rb_define_class_under(mDispatch, "Source", cObject); rb_define_const(cSource, "DATA_ADD", INT2NUM(SOURCE_TYPE_DATA_ADD)); rb_define_const(cSource, "DATA_OR", INT2NUM(SOURCE_TYPE_DATA_OR)); rb_define_const(cSource, "PROC", INT2NUM(SOURCE_TYPE_PROC)); rb_define_const(cSource, "READ", INT2NUM(SOURCE_TYPE_READ)); rb_define_const(cSource, "SIGNAL", INT2NUM(SOURCE_TYPE_SIGNAL)); rb_define_const(cSource, "VNODE", INT2NUM(SOURCE_TYPE_VNODE)); rb_define_const(cSource, "WRITE", INT2NUM(SOURCE_TYPE_WRITE)); rb_define_const(cSource, "PROC_EXIT", INT2NUM(DISPATCH_PROC_EXIT)); rb_define_const(cSource, "PROC_FORK", INT2NUM(DISPATCH_PROC_FORK)); rb_define_const(cSource, "PROC_EXEC", INT2NUM(DISPATCH_PROC_EXEC)); rb_define_const(cSource, "PROC_SIGNAL", INT2NUM(DISPATCH_PROC_SIGNAL)); rb_define_const(cSource, "VNODE_DELETE", INT2NUM(DISPATCH_VNODE_DELETE)); rb_define_const(cSource, "VNODE_WRITE", INT2NUM(DISPATCH_VNODE_WRITE)); rb_define_const(cSource, "VNODE_EXTEND", INT2NUM(DISPATCH_VNODE_EXTEND)); rb_define_const(cSource, "VNODE_ATTRIB", INT2NUM(DISPATCH_VNODE_ATTRIB)); rb_define_const(cSource, "VNODE_LINK", INT2NUM(DISPATCH_VNODE_LINK)); rb_define_const(cSource, "VNODE_RENAME", INT2NUM(DISPATCH_VNODE_RENAME)); rb_define_const(cSource, "VNODE_REVOKE", INT2NUM(DISPATCH_VNODE_REVOKE)); rb_objc_define_method(*(VALUE *)cSource, "alloc", rb_source_alloc, 0); rb_objc_define_method(*(VALUE *)cSource, "timer", rb_source_timer, 4); rb_objc_define_method(cSource, "initialize", rb_source_init, 4); rb_objc_define_method(cSource, "initialize", rb_raise_init, 0); rb_objc_define_method(cSource, "cancelled?", rb_source_cancelled_p, 0); rb_objc_define_method(cSource, "cancel!", rb_source_cancel, 0); rb_objc_define_method(cSource, "handle", rb_source_get_handle, 0); rb_objc_define_method(cSource, "mask", rb_source_get_mask, 0); rb_objc_define_method(cSource, "data", rb_source_get_data, 0); rb_objc_define_method(cSource, "<<", rb_source_merge, 1); rb_source_finalize_super = rb_objc_install_method2((Class)cSource, "finalize", (IMP)rb_source_finalize); /* * Dispatch::Semaphore provides an efficient mechanism to synchronizes threads * via a combination of waiting and signalling. * This is especially useful for controlling access to limited resources. */ cSemaphore = rb_define_class_under(mDispatch, "Semaphore", cObject); rb_objc_define_method(*(VALUE *)cSemaphore, "alloc", rb_semaphore_alloc, 0); rb_objc_define_method(cSemaphore, "initialize", rb_semaphore_init, 1); rb_objc_define_method(cSemaphore, "initialize", rb_raise_init, 0); rb_objc_define_method(cSemaphore, "wait", rb_semaphore_wait, -1); rb_objc_define_method(cSemaphore, "signal", rb_semaphore_signal, 0); rb_semaphore_finalize_super = rb_objc_install_method2((Class)cSemaphore, "finalize", (IMP)rb_semaphore_finalize); /* * Constants for use with * dispatch_time(3)[http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man3/dispatch_time.3.html] */ rb_define_const(mDispatch, "TIME_NOW", ULL2NUM(DISPATCH_TIME_NOW)); rb_define_const(mDispatch, "TIME_FOREVER", ULL2NUM(DISPATCH_TIME_FOREVER)); /* Constants for future reference */ selClose = sel_registerName("close"); assert(selClose != NULL); }
void Init_ossl_ssl() { int i; VALUE ary; #if 0 /* let rdoc know about mOSSL */ mOSSL = rb_define_module("OpenSSL"); #endif ID_callback_state = rb_intern("@callback_state"); ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_vcb_idx",0,0,0); ossl_ssl_ex_store_p = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_store_p",0,0,0); ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_ptr_idx",0,0,0); ossl_ssl_ex_client_cert_cb_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_client_cert_cb_idx",0,0,0); ossl_ssl_ex_tmp_dh_callback_idx = SSL_get_ex_new_index(0,(void *)"ossl_ssl_ex_tmp_dh_callback_idx",0,0,0); mSSL = rb_define_module_under(mOSSL, "SSL"); eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError); Init_ossl_ssl_session(); /* class SSLContext * * The following attributes are available but don't show up in rdoc. * All attributes must be set before calling SSLSocket.new(io, ctx). * * ssl_version, cert, key, client_ca, ca_file, ca_path, timeout, * * verify_mode, verify_depth client_cert_cb, tmp_dh_callback, * * session_id_context, session_add_cb, session_new_cb, session_remove_cb */ cSSLContext = rb_define_class_under(mSSL, "SSLContext", rb_cObject); rb_objc_define_method(*(VALUE *)cSSLContext, "alloc", ossl_sslctx_s_alloc, 0); for(i = 0; i < numberof(ossl_sslctx_attrs); i++) rb_attr(cSSLContext, rb_intern(ossl_sslctx_attrs[i]), 1, 1, Qfalse); rb_define_alias(cSSLContext, "ssl_timeout", "timeout"); rb_define_alias(cSSLContext, "ssl_timeout=", "timeout="); rb_objc_define_method(cSSLContext, "initialize", ossl_sslctx_initialize, -1); rb_objc_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1); rb_objc_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0); rb_objc_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1); rb_objc_define_method(cSSLContext, "setup", ossl_sslctx_setup, 0); rb_define_const(cSSLContext, "SESSION_CACHE_OFF", LONG2FIX(SSL_SESS_CACHE_OFF)); rb_define_const(cSSLContext, "SESSION_CACHE_CLIENT", LONG2FIX(SSL_SESS_CACHE_CLIENT)); /* doesn't actually do anything in 0.9.8e */ rb_define_const(cSSLContext, "SESSION_CACHE_SERVER", LONG2FIX(SSL_SESS_CACHE_SERVER)); rb_define_const(cSSLContext, "SESSION_CACHE_BOTH", LONG2FIX(SSL_SESS_CACHE_BOTH)); /* no different than CACHE_SERVER in 0.9.8e */ rb_define_const(cSSLContext, "SESSION_CACHE_NO_AUTO_CLEAR", LONG2FIX(SSL_SESS_CACHE_NO_AUTO_CLEAR)); rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_LOOKUP", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)); rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL_STORE", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL_STORE)); rb_define_const(cSSLContext, "SESSION_CACHE_NO_INTERNAL", LONG2FIX(SSL_SESS_CACHE_NO_INTERNAL)); rb_objc_define_method(cSSLContext, "session_add", ossl_sslctx_session_add, 1); rb_objc_define_method(cSSLContext, "session_remove", ossl_sslctx_session_remove, 1); rb_objc_define_method(cSSLContext, "session_cache_mode", ossl_sslctx_get_session_cache_mode, 0); rb_objc_define_method(cSSLContext, "session_cache_mode=", ossl_sslctx_set_session_cache_mode, 1); rb_objc_define_method(cSSLContext, "session_cache_size", ossl_sslctx_get_session_cache_size, 0); rb_objc_define_method(cSSLContext, "session_cache_size=", ossl_sslctx_set_session_cache_size, 1); rb_objc_define_method(cSSLContext, "session_cache_stats", ossl_sslctx_get_session_cache_stats, 0); rb_objc_define_method(cSSLContext, "flush_sessions", ossl_sslctx_flush_sessions, -1); ary = rb_ary_new2(numberof(ossl_ssl_method_tab)); for (i = 0; i < numberof(ossl_ssl_method_tab); i++) { rb_ary_push(ary, ID2SYM(rb_intern(ossl_ssl_method_tab[i].name))); } rb_obj_freeze(ary); /* holds a list of available SSL/TLS methods */ rb_define_const(cSSLContext, "METHODS", ary); /* class SSLSocket * * The following attributes are available but don't show up in rdoc. * * io, context, sync_close * */ cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject); rb_objc_define_method(*(VALUE *)cSSLSocket, "alloc", ossl_ssl_s_alloc, 0); for(i = 0; i < numberof(ossl_ssl_attr_readers); i++) rb_attr(cSSLSocket, rb_intern(ossl_ssl_attr_readers[i]), 1, 0, Qfalse); for(i = 0; i < numberof(ossl_ssl_attrs); i++) rb_attr(cSSLSocket, rb_intern(ossl_ssl_attrs[i]), 1, 1, Qfalse); rb_define_alias(cSSLSocket, "to_io", "io"); rb_objc_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1); rb_objc_define_method(cSSLSocket, "connect", ossl_ssl_connect, 0); rb_objc_define_method(cSSLSocket, "connect_nonblock", ossl_ssl_connect_nonblock, 0); rb_objc_define_method(cSSLSocket, "accept", ossl_ssl_accept, 0); rb_objc_define_method(cSSLSocket, "accept_nonblock", ossl_ssl_accept_nonblock, 0); rb_objc_define_method(cSSLSocket, "sysread", ossl_ssl_read, -1); rb_objc_define_private_method(cSSLSocket, "sysread_nonblock", ossl_ssl_read_nonblock, -1); rb_objc_define_method(cSSLSocket, "syswrite", ossl_ssl_write, 1); rb_objc_define_private_method(cSSLSocket, "syswrite_nonblock", ossl_ssl_write_nonblock, 1); rb_objc_define_method(cSSLSocket, "sysclose", ossl_ssl_close, 0); rb_objc_define_method(cSSLSocket, "cert", ossl_ssl_get_cert, 0); rb_objc_define_method(cSSLSocket, "peer_cert", ossl_ssl_get_peer_cert, 0); rb_objc_define_method(cSSLSocket, "peer_cert_chain", ossl_ssl_get_peer_cert_chain, 0); rb_objc_define_method(cSSLSocket, "cipher", ossl_ssl_get_cipher, 0); rb_objc_define_method(cSSLSocket, "state", ossl_ssl_get_state, 0); rb_objc_define_method(cSSLSocket, "pending", ossl_ssl_pending, 0); rb_objc_define_method(cSSLSocket, "session_reused?", ossl_ssl_session_reused, 0); rb_objc_define_method(cSSLSocket, "session=", ossl_ssl_set_session, 1); rb_objc_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0); #define ossl_ssl_def_const(x) rb_define_const(mSSL, #x, INT2NUM(SSL_##x)) ossl_ssl_def_const(VERIFY_NONE); ossl_ssl_def_const(VERIFY_PEER); ossl_ssl_def_const(VERIFY_FAIL_IF_NO_PEER_CERT); ossl_ssl_def_const(VERIFY_CLIENT_ONCE); /* Introduce constants included in OP_ALL. These constants are mostly for * unset some bits in OP_ALL such as; * ctx.options = OP_ALL & ~OP_DONT_INSERT_EMPTY_FRAGMENTS */ ossl_ssl_def_const(OP_MICROSOFT_SESS_ID_BUG); ossl_ssl_def_const(OP_NETSCAPE_CHALLENGE_BUG); ossl_ssl_def_const(OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG); ossl_ssl_def_const(OP_SSLREF2_REUSE_CERT_TYPE_BUG); ossl_ssl_def_const(OP_MICROSOFT_BIG_SSLV3_BUFFER); ossl_ssl_def_const(OP_MSIE_SSLV2_RSA_PADDING); ossl_ssl_def_const(OP_SSLEAY_080_CLIENT_DH_BUG); ossl_ssl_def_const(OP_TLS_D5_BUG); ossl_ssl_def_const(OP_TLS_BLOCK_PADDING_BUG); ossl_ssl_def_const(OP_DONT_INSERT_EMPTY_FRAGMENTS); ossl_ssl_def_const(OP_ALL); #if defined(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION) ossl_ssl_def_const(OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); #endif #if defined(SSL_OP_SINGLE_ECDH_USE) ossl_ssl_def_const(OP_SINGLE_ECDH_USE); #endif ossl_ssl_def_const(OP_SINGLE_DH_USE); ossl_ssl_def_const(OP_EPHEMERAL_RSA); #if defined(SSL_OP_CIPHER_SERVER_PREFERENCE) ossl_ssl_def_const(OP_CIPHER_SERVER_PREFERENCE); #endif ossl_ssl_def_const(OP_TLS_ROLLBACK_BUG); ossl_ssl_def_const(OP_NO_SSLv2); ossl_ssl_def_const(OP_NO_SSLv3); ossl_ssl_def_const(OP_NO_TLSv1); #if defined(SSL_OP_NO_TICKET) ossl_ssl_def_const(OP_NO_TICKET); #endif ossl_ssl_def_const(OP_PKCS1_CHECK_1); ossl_ssl_def_const(OP_PKCS1_CHECK_2); ossl_ssl_def_const(OP_NETSCAPE_CA_DN_BUG); ossl_ssl_def_const(OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG); ossl_lock_init(); }
void Init_Set(void) { rb_cCFSet = (VALUE)objc_getClass("NSCFSet"); rb_cSet = rb_cNSSet = (VALUE)objc_getClass("NSSet"); rb_cNSMutableSet = (VALUE)objc_getClass("NSMutableSet"); rb_set_class_path(rb_cNSMutableSet, rb_cObject, "NSMutableSet"); rb_const_set(rb_cObject, rb_intern("Set"), rb_cNSMutableSet); rb_include_module(rb_cSet, rb_mEnumerable); rb_objc_define_method(*(VALUE *)rb_cSet, "[]", rb_set_s_create, -1); rb_objc_define_method(rb_cSet, "dup", rb_set_dup, 0); rb_objc_define_method(rb_cSet, "clone", rb_set_clone, 0); rb_objc_define_method(rb_cSet, "initialize", rb_set_initialize, -1); rb_objc_define_method(rb_cSet, "to_a", rb_set_to_a, 0); rb_objc_define_method(rb_cSet, "==", rb_set_equal, 1); rb_objc_define_method(rb_cSet, "size", rb_set_size, 0); rb_objc_define_method(rb_cSet, "empty?", rb_set_empty_q, 0); rb_define_alias(rb_cSet, "length", "size"); rb_objc_define_method(rb_cSet, "&", rb_set_intersect, 1); rb_define_alias(rb_cSet, "intersect", "&"); rb_objc_define_method(rb_cSet, "|", rb_set_union, 1); rb_define_alias(rb_cSet, "union", "|"); rb_define_alias(rb_cSet, "+", "|"); rb_objc_define_method(rb_cSet, "merge", rb_set_merge, 1); rb_objc_define_method(rb_cSet, "-", rb_set_subtract, 1); rb_objc_define_method(rb_cSet, "add", rb_set_add, 1); rb_define_alias(rb_cSet, "<<", "add"); rb_objc_define_method(rb_cSet, "add?", rb_set_add2, 1); rb_objc_define_method(rb_cSet, "clear", rb_set_clear, 0); rb_objc_define_method(rb_cSet, "delete", rb_set_delete, 1); rb_objc_define_method(rb_cSet, "delete?", rb_set_delete2, 1); rb_objc_define_method(rb_cSet, "delete_if", rb_set_delete_if, 0); rb_objc_define_method(rb_cSet, "reject!", rb_set_reject_bang, 0); rb_objc_define_method(rb_cSet, "each", rb_set_each, 0); rb_objc_define_method(rb_cSet, "include?", rb_set_include, 1); rb_define_alias(rb_cSet, "member?", "include?"); }
void Init_Thread(void) { rb_cThread = rb_define_class("Thread", rb_cObject); rb_objc_define_method(*(VALUE *)rb_cThread, "alloc", thread_s_alloc, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "start", thread_start, -1); rb_objc_define_method(*(VALUE *)rb_cThread, "fork", thread_start, -1); rb_objc_define_method(*(VALUE *)rb_cThread, "main", rb_thread_s_main, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "current", thread_s_current, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "stop", rb_thread_stop, 0); rb_define_singleton_method(rb_cThread, "kill", rb_thread_s_kill, 1); rb_define_singleton_method(rb_cThread, "exit", rb_thread_exit, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "pass", thread_s_pass, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "list", rb_thread_list, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "abort_on_exception", rb_thread_s_abort_exc, 0); rb_objc_define_method(*(VALUE *)rb_cThread, "abort_on_exception=", rb_thread_s_abort_exc_set, 1); rb_objc_define_method(rb_cThread, "initialize", thread_initialize, -1); rb_objc_define_method(rb_cThread, "raise", thread_raise_m, -1); rb_objc_define_method(rb_cThread, "join", thread_join_m, -1); rb_objc_define_method(rb_cThread, "value", thread_value, 0); rb_objc_define_method(rb_cThread, "kill", rb_thread_kill, 0); rb_objc_define_method(rb_cThread, "terminate", rb_thread_kill, 0); rb_objc_define_method(rb_cThread, "exit", rb_thread_kill, 0); rb_objc_define_method(rb_cThread, "run", rb_thread_run, 0); rb_objc_define_method(rb_cThread, "wakeup", rb_thread_wakeup, 0); rb_objc_define_method(rb_cThread, "[]", rb_thread_aref, 1); rb_objc_define_method(rb_cThread, "[]=", rb_thread_aset, 2); rb_objc_define_method(rb_cThread, "key?", rb_thread_key_p, 1); rb_objc_define_method(rb_cThread, "keys", rb_thread_keys, 0); rb_define_method(rb_cThread, "priority", rb_thread_priority, 0); rb_define_method(rb_cThread, "priority=", rb_thread_priority_set, 1); rb_objc_define_method(rb_cThread, "status", rb_thread_status, 0); rb_objc_define_method(rb_cThread, "alive?", rb_thread_alive_p, 0); rb_objc_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0); rb_define_method(rb_cThread, "abort_on_exception", rb_thread_abort_exc, 0); rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1); rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0); rb_objc_define_method(rb_cThread, "group", rb_thread_group, 0); rb_objc_define_method(rb_cThread, "inspect", rb_thread_inspect, 0); rb_cThGroup = rb_define_class("ThreadGroup", rb_cObject); rb_objc_define_method(*(VALUE *)rb_cThGroup, "alloc", thgroup_s_alloc, 0); rb_objc_define_method(rb_cThGroup, "list", thgroup_list, 0); rb_objc_define_method(rb_cThGroup, "enclose", thgroup_enclose, 0); rb_objc_define_method(rb_cThGroup, "enclosed?", thgroup_enclosed_p, 0); rb_objc_define_method(rb_cThGroup, "add", thgroup_add, 1); rb_cMutex = rb_define_class("Mutex", rb_cObject); rb_objc_define_method(*(VALUE *)rb_cMutex, "alloc", mutex_s_alloc, 0); rb_objc_define_method(rb_cMutex, "initialize", mutex_initialize, 0); rb_objc_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0); rb_objc_define_method(rb_cMutex, "try_lock", rb_mutex_trylock, 0); rb_objc_define_method(rb_cMutex, "lock", rb_mutex_lock, 0); rb_objc_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0); rb_objc_define_method(rb_cMutex, "sleep", mutex_sleep, -1); rb_objc_define_method(rb_cMutex, "synchronize", mutex_synchronize, 0); rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError); }
void Init_ossl_ssl_session(void) { #if 0 /* let rdoc know about mOSSL */ mOSSL = rb_define_module("OpenSSL"); mSSL = rb_define_module_under(mOSSL, "SSL"); #endif cSSLSession = rb_define_class_under(mSSL, "Session", rb_cObject); eSSLSession = rb_define_class_under(cSSLSession, "SessionError", eOSSLError); rb_objc_define_method(*(VALUE *)cSSLSession, "alloc", ossl_ssl_session_alloc, 0); rb_objc_define_method(cSSLSession, "initialize", ossl_ssl_session_initialize, 1); rb_objc_define_method(cSSLSession, "==", ossl_ssl_session_eq, 1); rb_objc_define_method(cSSLSession, "time", ossl_ssl_session_get_time, 0); rb_objc_define_method(cSSLSession, "time=", ossl_ssl_session_set_time, 1); rb_objc_define_method(cSSLSession, "timeout", ossl_ssl_session_get_timeout, 0); rb_objc_define_method(cSSLSession, "timeout=", ossl_ssl_session_set_timeout, 1); #ifdef HAVE_SSL_SESSION_GET_ID rb_objc_define_method(cSSLSession, "id", ossl_ssl_session_get_id, 0); #else rb_undef_method(cSSLSession, "id"); #endif rb_objc_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0); rb_objc_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0); rb_objc_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0); }
/* * INIT */ void Init_ossl_x509crl() { eX509CRLError = rb_define_class_under(mX509, "CRLError", eOSSLError); cX509CRL = rb_define_class_under(mX509, "CRL", rb_cObject); rb_objc_define_method(*(VALUE *)cX509CRL, "alloc", ossl_x509crl_alloc, 0); rb_objc_define_method(cX509CRL, "initialize", ossl_x509crl_initialize, -1); rb_define_copy_func(cX509CRL, ossl_x509crl_copy); rb_objc_define_method(cX509CRL, "version", ossl_x509crl_get_version, 0); rb_objc_define_method(cX509CRL, "version=", ossl_x509crl_set_version, 1); rb_objc_define_method(cX509CRL, "signature_algorithm", ossl_x509crl_get_signature_algorithm, 0); rb_objc_define_method(cX509CRL, "issuer", ossl_x509crl_get_issuer, 0); rb_objc_define_method(cX509CRL, "issuer=", ossl_x509crl_set_issuer, 1); rb_objc_define_method(cX509CRL, "last_update", ossl_x509crl_get_last_update, 0); rb_objc_define_method(cX509CRL, "last_update=", ossl_x509crl_set_last_update, 1); rb_objc_define_method(cX509CRL, "next_update", ossl_x509crl_get_next_update, 0); rb_objc_define_method(cX509CRL, "next_update=", ossl_x509crl_set_next_update, 1); rb_objc_define_method(cX509CRL, "revoked", ossl_x509crl_get_revoked, 0); rb_objc_define_method(cX509CRL, "revoked=", ossl_x509crl_set_revoked, 1); rb_objc_define_method(cX509CRL, "add_revoked", ossl_x509crl_add_revoked, 1); rb_objc_define_method(cX509CRL, "sign", ossl_x509crl_sign, 2); rb_objc_define_method(cX509CRL, "verify", ossl_x509crl_verify, 1); rb_objc_define_method(cX509CRL, "to_der", ossl_x509crl_to_der, 0); rb_objc_define_method(cX509CRL, "to_pem", ossl_x509crl_to_pem, 0); rb_define_alias(cX509CRL, "to_s", "to_pem"); rb_objc_define_method(cX509CRL, "to_text", ossl_x509crl_to_text, 0); rb_objc_define_method(cX509CRL, "extensions", ossl_x509crl_get_extensions, 0); rb_objc_define_method(cX509CRL, "extensions=", ossl_x509crl_set_extensions, 1); rb_objc_define_method(cX509CRL, "add_extension", ossl_x509crl_add_extension, 1); }
void Init_Hash(void) { Init_NSDictionary(); selFlattenBang = sel_registerName("flatten!:"); selDefault = sel_registerName("default:"); selHash = sel_registerName("hash"); id_yield = rb_intern("yield"); rb_cRubyHash = rb_define_class("Hash", rb_cNSMutableHash); rb_objc_install_NSObject_special_methods((Class)rb_cRubyHash); rb_objc_define_method(*(VALUE *)rb_cRubyHash, "new", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)rb_cRubyHash, "alloc", rhash_alloc, 0); rb_objc_define_method(*(VALUE *)rb_cRubyHash, "[]", rhash_create, -1); rb_objc_define_method(*(VALUE *)rb_cRubyHash, "try_convert", rhash_try_convert, 1); rb_objc_define_method(rb_cRubyHash, "initialize", rhash_initialize, -1); rb_objc_define_method(rb_cRubyHash, "initialize_copy", rhash_replace, 1); rb_objc_define_method(rb_cRubyHash, "dup", rhash_dup, 0); rb_objc_define_method(rb_cRubyHash, "rehash", rhash_rehash, 0); rb_objc_define_method(rb_cRubyHash, "to_hash", rhash_to_hash, 0); rb_objc_define_method(rb_cRubyHash, "to_a", rhash_to_a, 0); rb_objc_define_method(rb_cRubyHash, "to_s", rhash_inspect, 0); rb_objc_define_method(rb_cRubyHash, "inspect", rhash_inspect, 0); rb_objc_define_method(rb_cRubyHash, "==", rhash_equal, 1); rb_objc_define_method(rb_cRubyHash, "[]", rhash_aref, 1); rb_objc_define_method(rb_cRubyHash, "eql?", rhash_eql, 1); rb_objc_define_method(rb_cRubyHash, "fetch", rhash_fetch, -1); rb_objc_define_method(rb_cRubyHash, "[]=", rhash_aset, 2); rb_objc_define_method(rb_cRubyHash, "store", rhash_aset, 2); rb_objc_define_method(rb_cRubyHash, "default", rhash_default, -1); rb_objc_define_method(rb_cRubyHash, "default=", rhash_set_default, 1); rb_objc_define_method(rb_cRubyHash, "default_proc", rhash_default_proc, 0); rb_objc_define_method(rb_cRubyHash, "default_proc=", rhash_set_default_proc, 1); rb_objc_define_method(rb_cRubyHash, "key", rhash_key, 1); rb_objc_define_method(rb_cRubyHash, "index", rhash_index, 1); rb_objc_define_method(rb_cRubyHash, "size", rhash_size, 0); rb_objc_define_method(rb_cRubyHash, "length", rhash_size, 0); rb_objc_define_method(rb_cRubyHash, "empty?", rhash_empty, 0); rb_objc_define_method(rb_cRubyHash, "each_value", rhash_each_value, 0); rb_objc_define_method(rb_cRubyHash, "each_key", rhash_each_key, 0); rb_objc_define_method(rb_cRubyHash, "each_pair", rhash_each_pair, 0); rb_objc_define_method(rb_cRubyHash, "each", rhash_each_pair, 0); rb_objc_define_method(rb_cRubyHash, "keys", rhash_keys, 0); rb_objc_define_method(rb_cRubyHash, "values", rhash_values, 0); rb_objc_define_method(rb_cRubyHash, "values_at", rhash_values_at, -1); rb_objc_define_method(rb_cRubyHash, "shift", rhash_shift, 0); rb_objc_define_method(rb_cRubyHash, "delete", rhash_delete, 1); rb_objc_define_method(rb_cRubyHash, "delete_if", rhash_delete_if, 0); rb_objc_define_method(rb_cRubyHash, "keep_if", rhash_keep_if, 0); rb_objc_define_method(rb_cRubyHash, "select", rhash_select, 0); rb_objc_define_method(rb_cRubyHash, "select!", rhash_select_bang, 0); rb_objc_define_method(rb_cRubyHash, "reject", rhash_reject, 0); rb_objc_define_method(rb_cRubyHash, "reject!", rhash_reject_bang, 0); rb_objc_define_method(rb_cRubyHash, "clear", rhash_clear, 0); rb_objc_define_method(rb_cRubyHash, "invert", rhash_invert, 0); rb_objc_define_method(rb_cRubyHash, "update", rhash_update, 1); rb_objc_define_method(rb_cRubyHash, "replace", rhash_replace, 1); rb_objc_define_method(rb_cRubyHash, "merge!", rhash_update, 1); rb_objc_define_method(rb_cRubyHash, "merge", rhash_merge, 1); rb_objc_define_method(rb_cRubyHash, "assoc", rhash_assoc, 1); rb_objc_define_method(rb_cRubyHash, "rassoc", rhash_rassoc, 1); rb_objc_define_method(rb_cRubyHash, "flatten", rhash_flatten, -1); rb_objc_define_method(rb_cRubyHash, "include?", rhash_has_key, 1); rb_objc_define_method(rb_cRubyHash, "member?", rhash_has_key, 1); rb_objc_define_method(rb_cRubyHash, "has_key?", rhash_has_key, 1); rb_objc_define_method(rb_cRubyHash, "has_value?", rhash_has_value, 1); rb_objc_define_method(rb_cRubyHash, "key?", rhash_has_key, 1); rb_objc_define_method(rb_cRubyHash, "value?", rhash_has_value, 1); rb_objc_define_method(rb_cRubyHash, "compare_by_identity", rhash_compare_by_id, 0); rb_objc_define_method(rb_cRubyHash, "compare_by_identity?", rhash_compare_by_id_p, 0); rb_objc_install_method2((Class)rb_cRubyHash, "count", (IMP)imp_rhash_count); rb_objc_install_method2((Class)rb_cRubyHash, "objectForKey:", (IMP)imp_rhash_objectForKey); rb_objc_install_method2((Class)rb_cRubyHash, "keyEnumerator", (IMP)imp_rhash_keyEnumerator); rb_objc_install_method2((Class)rb_cRubyHash, "setObject:forKey:", (IMP)imp_rhash_setObjectForKey); rb_objc_install_method2((Class)rb_cRubyHash, "removeObjectForKey:", (IMP)imp_rhash_removeObjectForKey); VALUE NSEnumerator = (VALUE)objc_getClass("NSEnumerator"); assert(NSEnumerator != 0); rb_cRubyHashKeyEnumerator = rb_define_class("RubyHashKeyEnumerator", NSEnumerator); rb_objc_install_method2((Class)rb_cRubyHashKeyEnumerator, "allObjects", (IMP)imp_rhash_keyenum_allObjects); rb_objc_install_method2((Class)rb_cRubyHashKeyEnumerator, "nextObject", (IMP)imp_rhash_keyenum_nextObject); }
void Init_Exception(void) { rb_eException = rb_define_class("Exception", rb_cObject); rb_objc_define_method(*(VALUE *)rb_eException, "exception", rb_class_new_instance_imp, -1); rb_objc_define_method(rb_eException, "exception", exc_exception, -1); rb_objc_define_method(rb_eException, "initialize", exc_initialize, -1); rb_objc_define_method(rb_eException, "==", exc_equal, 1); rb_objc_define_method(rb_eException, "to_s", exc_to_s, 0); rb_objc_define_method(rb_eException, "message", exc_message, 0); rb_objc_define_method(rb_eException, "inspect", exc_inspect, 0); rb_objc_define_method(rb_eException, "backtrace", exc_backtrace, 0); rb_objc_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1); rb_eSystemExit = rb_define_class("SystemExit", rb_eException); rb_objc_define_method(rb_eSystemExit, "initialize", exit_initialize, -1); rb_objc_define_method(rb_eSystemExit, "status", exit_status, 0); rb_objc_define_method(rb_eSystemExit, "success?", exit_success_p, 0); rb_eFatal = rb_define_class("fatal", rb_eException); rb_eSignal = rb_define_class("SignalException", rb_eException); rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal); rb_eStandardError = rb_define_class("StandardError", rb_eException); rb_eTypeError = rb_define_class("TypeError", rb_eStandardError); rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError); rb_eIndexError = rb_define_class("IndexError", rb_eStandardError); rb_eKeyError = rb_define_class("KeyError", rb_eIndexError); rb_eRangeError = rb_define_class("RangeError", rb_eStandardError); rb_eScriptError = rb_define_class("ScriptError", rb_eException); rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError); rb_eLoadError = rb_define_class("LoadError", rb_eScriptError); rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError); rb_eNameError = rb_define_class("NameError", rb_eStandardError); rb_objc_define_method(rb_eNameError, "initialize", name_err_initialize, -1); rb_objc_define_method(rb_eNameError, "name", name_err_name, 0); rb_objc_define_method(rb_eNameError, "to_s", name_err_to_s, 0); rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData); rb_objc_define_method(*(VALUE *)rb_cNameErrorMesg, "!", name_err_mesg_new, 3); rb_objc_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1); rb_objc_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0); rb_objc_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_to_str, 1); rb_objc_define_method(*(VALUE *)rb_cNameErrorMesg, "_load", name_err_mesg_load, 1); rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError); rb_objc_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1); rb_objc_define_method(rb_eNoMethodError, "args", nometh_err_args, 0); rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError); rb_eSecurityError = rb_define_class("SecurityError", rb_eException); rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException); rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError); rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError); rb_eUndefinedConversionError = rb_define_class_under(rb_cEncoding, "UndefinedConversionError", rb_eEncodingError); rb_eInvalidByteSequenceError = rb_define_class_under(rb_cEncoding, "InvalidByteSequenceError", rb_eEncodingError); rb_eConverterNotFoundError = rb_define_class_under(rb_cEncoding, "ConverterNotFoundError", rb_eEncodingError); syserr_tbl = st_init_numtable(); GC_RETAIN(syserr_tbl); rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError); rb_objc_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1); rb_objc_define_method(rb_eSystemCallError, "errno", syserr_errno, 0); rb_objc_define_method(*(VALUE *)rb_eSystemCallError, "===", syserr_eqq, 1); rb_mErrno = rb_define_module("Errno"); rb_objc_define_method(*(VALUE *)rb_mErrno, "const_missing", errno_missing, 1); rb_objc_define_method(*(VALUE *)rb_mErrno, "code", errno_code, 0); rb_objc_define_module_function(rb_mKernel, "warn", rb_warn_m, 1); }
void Init_Range(void) { rb_cRange = rb_struct_define_without_accessor( "Range", rb_cObject, range_alloc, "begin", "end", "excl", NULL); rb_include_module(rb_cRange, rb_mEnumerable); //rb_marshal_define_compat(rb_cRange, rb_cObject, range_dumper, range_loader); rb_objc_define_method(rb_cRange, "initialize", range_initialize, -1); rb_objc_define_method(rb_cRange, "initialize_copy", range_initialize_copy, 1); rb_objc_define_method(rb_cRange, "==", range_eq, 1); rb_objc_define_method(rb_cRange, "===", range_eqq, 1); rb_objc_define_method(rb_cRange, "eql?", range_eql, 1); rb_objc_define_method(rb_cRange, "hash", range_hash, 0); rb_objc_define_method(rb_cRange, "each", range_each, 0); rb_objc_define_method(rb_cRange, "step", range_step, -1); rb_objc_define_method(rb_cRange, "begin", range_begin, 0); rb_objc_define_method(rb_cRange, "end", range_end, 0); rb_objc_define_method(rb_cRange, "first", range_first, -1); rb_objc_define_method(rb_cRange, "last", range_last, -1); rb_objc_define_method(rb_cRange, "min", range_min, 0); rb_objc_define_method(rb_cRange, "max", range_max, 0); rb_objc_define_method(rb_cRange, "to_s", range_to_s, 0); rb_objc_define_method(rb_cRange, "inspect", range_inspect, 0); rb_objc_define_method(rb_cRange, "exclude_end?", range_exclude_end_p, 0); rb_objc_define_method(rb_cRange, "member?", range_include, 1); rb_objc_define_method(rb_cRange, "include?", range_include, 1); rb_objc_define_method(rb_cRange, "cover?", range_cover, 1); // NOTE: This is a MacRuby specific extension. rb_objc_define_method(rb_cRange, "relative_to", range_relative_to, 1); selUpto = sel_registerName("upto:"); selBeg = sel_registerName("begin"); selEnd = sel_registerName("end"); selExcludeEnd = sel_registerName("exclude_end?"); selInclude = sel_registerName("include?:"); }
void Init_ossl_engine() { cEngine = rb_define_class_under(mOSSL, "Engine", rb_cObject); eEngineError = rb_define_class_under(cEngine, "EngineError", eOSSLError); rb_objc_define_method(*(VALUE *)cEngine, "alloc", ossl_engine_s_alloc, 0); rb_objc_define_method(*(VALUE *)cEngine, "load", ossl_engine_s_load, -1); rb_objc_define_method(*(VALUE *)cEngine, "cleanup", ossl_engine_s_cleanup, 0); rb_objc_define_method(*(VALUE *)cEngine, "engines", ossl_engine_s_engines, 0); rb_objc_define_method(*(VALUE *)cEngine, "by_id", ossl_engine_s_by_id, 1); rb_undef_method(CLASS_OF(cEngine), "new"); rb_objc_define_method(cEngine, "id", ossl_engine_get_id, 0); rb_objc_define_method(cEngine, "name", ossl_engine_get_name, 0); rb_objc_define_method(cEngine, "finish", ossl_engine_finish, 0); rb_objc_define_method(cEngine, "cipher", ossl_engine_get_cipher, 1); rb_objc_define_method(cEngine, "digest", ossl_engine_get_digest, 1); rb_objc_define_method(cEngine, "load_private_key", ossl_engine_load_privkey, -1); rb_objc_define_method(cEngine, "load_public_key", ossl_engine_load_pubkey, -1); rb_objc_define_method(cEngine, "set_default", ossl_engine_set_default, 1); rb_objc_define_method(cEngine, "ctrl_cmd", ossl_engine_ctrl_cmd, -1); rb_objc_define_method(cEngine, "cmds", ossl_engine_get_cmds, 0); rb_objc_define_method(cEngine, "inspect", ossl_engine_inspect, 0); DefEngineConst(METHOD_RSA); DefEngineConst(METHOD_DSA); DefEngineConst(METHOD_DH); DefEngineConst(METHOD_RAND); #ifdef ENGINE_METHOD_BN_MOD_EXP DefEngineConst(METHOD_BN_MOD_EXP); #endif #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT DefEngineConst(METHOD_BN_MOD_EXP_CRT); #endif #ifdef ENGINE_METHOD_CIPHERS DefEngineConst(METHOD_CIPHERS); #endif #ifdef ENGINE_METHOD_DIGESTS DefEngineConst(METHOD_DIGESTS); #endif DefEngineConst(METHOD_ALL); DefEngineConst(METHOD_NONE); }
/* * A rational number can be represented as a paired integer number; * a/b (b>0). Where a is numerator and b is denominator. Integer a * equals rational a/1 mathematically. * * In ruby, you can create rational object with Rational or to_r * method. The return values will be irreducible. * * Rational(1) #=> (1/1) * Rational(2, 3) #=> (2/3) * Rational(4, -6) #=> (-2/3) * 3.to_r #=> (3/1) * * You can also create ratioanl object from floating-point numbers or * strings. * * Rational(0.3) #=> (5404319552844595/18014398509481984) * Rational('0.3') #=> (3/10) * Rational('2/3') #=> (2/3) * * 0.3.to_r #=> (5404319552844595/18014398509481984) * '0.3'.to_r #=> (3/10) * '2/3'.to_r #=> (2/3) * * A rational object is an exact number, which helps you to write * program without any rounding errors. * * 10.times.inject(0){|t,| t + 0.1} #=> 0.9999999999999999 * 10.times.inject(0){|t,| t + Rational('0.1')} #=> (1/1) * * However, when an expression has inexact factor (numerical value or * operation), will produce an inexact result. * * Rational(10) / 3 #=> (10/3) * Rational(10) / 3.0 #=> 3.3333333333333335 * * Rational(-8) ** Rational(1, 3) * #=> (1.0000000000000002+1.7320508075688772i) */ void Init_Rational(void) { assert(fprintf(stderr, "assert() is now active\n")); id_abs = rb_intern("abs"); id_cmp = rb_intern("<=>"); id_convert = rb_intern("convert"); id_eqeq_p = rb_intern("=="); id_expt = rb_intern("**"); id_fdiv = rb_intern("fdiv"); id_floor = rb_intern("floor"); id_idiv = rb_intern("div"); id_inspect = rb_intern("inspect"); id_integer_p = rb_intern("integer?"); id_negate = rb_intern("-@"); id_to_f = rb_intern("to_f"); id_to_i = rb_intern("to_i"); id_to_s = rb_intern("to_s"); id_truncate = rb_intern("truncate"); rb_cRational = rb_define_class("Rational", rb_cNumeric); rb_objc_define_method(rb_cRational, "alloc", nurat_s_alloc, 0); rb_undef_method(CLASS_OF(rb_cRational), "allocate"); #if 0 rb_define_private_method(CLASS_OF(rb_cRational), "new!", nurat_s_new_bang, -1); rb_define_private_method(CLASS_OF(rb_cRational), "new", nurat_s_new, -1); #else rb_undef_method(CLASS_OF(rb_cRational), "new"); #endif rb_objc_define_method(rb_mKernel, "Rational", nurat_f_rational, -1); rb_objc_define_method(rb_cRational, "numerator", nurat_numerator, 0); rb_objc_define_method(rb_cRational, "denominator", nurat_denominator, 0); rb_objc_define_method(rb_cRational, "+", nurat_add, 1); rb_objc_define_method(rb_cRational, "-", nurat_sub, 1); rb_objc_define_method(rb_cRational, "*", nurat_mul, 1); rb_objc_define_method(rb_cRational, "/", nurat_div, 1); rb_objc_define_method(rb_cRational, "quo", nurat_div, 1); rb_objc_define_method(rb_cRational, "fdiv", nurat_fdiv, 1); rb_objc_define_method(rb_cRational, "**", nurat_expt, 1); rb_objc_define_method(rb_cRational, "<=>", nurat_cmp, 1); rb_objc_define_method(rb_cRational, "==", nurat_eqeq_p, 1); rb_objc_define_method(rb_cRational, "coerce", nurat_coerce, 1); #if 0 /* NUBY */ rb_define_method(rb_cRational, "//", nurat_idiv, 1); #endif #if 0 rb_define_method(rb_cRational, "quot", nurat_quot, 1); rb_define_method(rb_cRational, "quotrem", nurat_quotrem, 1); #endif #if 0 rb_define_method(rb_cRational, "rational?", nurat_true, 0); rb_define_method(rb_cRational, "exact?", nurat_true, 0); #endif rb_objc_define_method(rb_cRational, "floor", nurat_floor_n, -1); rb_objc_define_method(rb_cRational, "ceil", nurat_ceil_n, -1); rb_objc_define_method(rb_cRational, "truncate", nurat_truncate_n, -1); rb_objc_define_method(rb_cRational, "round", nurat_round_n, -1); rb_objc_define_method(rb_cRational, "to_i", nurat_truncate, 0); rb_objc_define_method(rb_cRational, "to_f", nurat_to_f, 0); rb_objc_define_method(rb_cRational, "to_r", nurat_to_r, 0); rb_objc_define_method(rb_cRational, "hash", nurat_hash, 0); rb_objc_define_method(rb_cRational, "to_s", nurat_to_s, 0); rb_objc_define_method(rb_cRational, "inspect", nurat_inspect, 0); rb_objc_define_method(rb_cRational, "marshal_dump", nurat_marshal_dump, 0); rb_objc_define_method(rb_cRational, "marshal_load", nurat_marshal_load, 1); /* --- */ rb_objc_define_method(rb_cInteger, "gcd", rb_gcd, 1); rb_objc_define_method(rb_cInteger, "lcm", rb_lcm, 1); rb_objc_define_method(rb_cInteger, "gcdlcm", rb_gcdlcm, 1); rb_objc_define_method(rb_cNumeric, "numerator", numeric_numerator, 0); rb_objc_define_method(rb_cNumeric, "denominator", numeric_denominator, 0); rb_objc_define_method(rb_cInteger, "numerator", integer_numerator, 0); rb_objc_define_method(rb_cInteger, "denominator", integer_denominator, 0); rb_objc_define_method(rb_cFloat, "numerator", float_numerator, 0); rb_objc_define_method(rb_cFloat, "denominator", float_denominator, 0); rb_objc_define_method(rb_cNilClass, "to_r", nilclass_to_r, 0); rb_objc_define_method(rb_cInteger, "to_r", integer_to_r, 0); rb_objc_define_method(rb_cFloat, "to_r", float_to_r, 0); make_patterns(); rb_objc_define_method(rb_cString, "to_r", string_to_r, 0); rb_objc_define_method(*(VALUE *)rb_cRational, "convert", nurat_s_convert, -1); // rb_define_private_method(CLASS_OF(rb_cRational), "convert", nurat_s_convert, -1); // TODO: insert NSNumber primitives }
void Init_GC(void) { VALUE rb_mObSpace; rb_mGC = rb_define_module("GC"); rb_objc_define_method(*(VALUE *)rb_mGC, "start", rb_gc_start, 0); rb_objc_define_method(*(VALUE *)rb_mGC, "enable", rb_gc_enable, 0); rb_objc_define_method(*(VALUE *)rb_mGC, "disable", rb_gc_disable, 0); rb_objc_define_method(*(VALUE *)rb_mGC, "stress", gc_stress_get, 0); rb_objc_define_method(*(VALUE *)rb_mGC, "stress=", gc_stress_set, 1); rb_objc_define_method(*(VALUE *)rb_mGC, "count", gc_count, 0); rb_objc_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0); rb_mObSpace = rb_define_module("ObjectSpace"); rb_objc_define_method(*(VALUE *)rb_mObSpace, "each_object", os_each_obj, -1); rb_objc_define_method(*(VALUE *)rb_mObSpace, "garbage_collect", rb_gc_start, 0); rb_objc_define_method(*(VALUE *)rb_mObSpace, "define_finalizer", define_final, -1); rb_objc_define_method(*(VALUE *)rb_mObSpace, "undefine_finalizer", undefine_final, 1); rb_objc_define_method(*(VALUE *)rb_mObSpace, "_id2ref", id2ref, 1); rb_global_variable(&nomem_error); nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); rb_objc_define_method(rb_mKernel, "hash", rb_obj_id, 0); rb_objc_define_method(rb_mKernel, "__id__", rb_obj_id, 0); rb_objc_define_method(rb_mKernel, "object_id", rb_obj_id, 0); rb_objc_define_method(*(VALUE *)rb_mObSpace, "count_objects", count_objects, -1); }
void Init_Encoding(void) { // rb_cEncoding is defined earlier in Init_PreVM(). rb_set_class_path(rb_cEncoding, rb_cObject, "Encoding"); rb_const_set(rb_cObject, rb_intern("Encoding"), rb_cEncoding); rb_undef_alloc_func(rb_cEncoding); rb_objc_define_method(rb_cEncoding, "to_s", mr_enc_name, 0); rb_objc_define_method(rb_cEncoding, "inspect", mr_enc_inspect, 0); rb_objc_define_method(rb_cEncoding, "name", mr_enc_name, 0); rb_objc_define_method(rb_cEncoding, "names", mr_enc_names, 0); rb_objc_define_method(rb_cEncoding, "dummy?", mr_enc_dummy_p, 0); rb_objc_define_method(rb_cEncoding, "ascii_compatible?", mr_enc_ascii_compatible_p, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "list", mr_enc_s_list, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "name_list", mr_enc_s_name_list, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "aliases", mr_enc_s_aliases, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "find", mr_enc_s_find, 1); rb_objc_define_method(*(VALUE *)rb_cEncoding, "compatible?", mr_enc_s_is_compatible, 2); // in string.c //rb_define_method(rb_cEncoding, "_dump", enc_dump, -1); //rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1); rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external", mr_enc_s_default_external, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external=", mr_enc_set_default_external, 1); rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal", mr_enc_s_default_internal, 0); rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal=", mr_enc_set_default_internal, 1); //rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0); // Create constants. for (unsigned int i = 0; i < ENCODINGS_COUNT; i++) { rb_encoding_t *enc = rb_encodings[i]; define_encoding_constant(enc->public_name, enc); for (unsigned int j = 0; j < enc->aliases_count; j++) { define_encoding_constant(enc->aliases[j], enc); } } }
void Init_Symbol(void) { // rb_cSymbol is defined earlier in Init_PreVM(). rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol"); rb_const_set(rb_cObject, rb_intern("Symbol"), rb_cSymbol); rb_undef_alloc_func(rb_cSymbol); rb_undef_method(*(VALUE *)rb_cSymbol, "new"); rb_objc_define_method(*(VALUE *)rb_cSymbol, "all_symbols", rsym_all_symbols, 0); // Undefine methods defined on NSString. rb_undef_method(rb_cSymbol, "to_i"); rb_undef_method(rb_cSymbol, "to_f"); rb_undef_method(rb_cSymbol, "to_str"); rb_objc_define_method(rb_cSymbol, "==", rsym_equal, 1); rb_objc_define_method(rb_cSymbol, "<=>", rsym_cmp, 1); rb_objc_define_method(rb_cSymbol, "casecmp", rsym_casecmp, 1); rb_objc_define_method(rb_cSymbol, "eql?", rsym_equal, 1); rb_objc_define_method(rb_cSymbol, "inspect", rsym_inspect, 0); rb_objc_define_method(rb_cSymbol, "to_proc", rsym_to_proc, 0); rb_objc_define_method(rb_cSymbol, "to_s", rsym_to_s, 0); rb_objc_define_method(rb_cSymbol, "id2name", rsym_to_s, 0); rb_objc_define_method(rb_cSymbol, "description", rsym_to_s, 0); rb_objc_define_method(rb_cSymbol, "intern", rsym_to_sym, 0); rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0); rb_objc_define_method(rb_cSymbol, "empty?", rsym_empty, 0); rb_objc_define_method(rb_cSymbol, "[]", rsym_aref, -1); rb_objc_define_method(rb_cSymbol, "upcase", rsym_upcase, 0); rb_objc_define_method(rb_cSymbol, "downcase", rsym_downcase, 0); rb_objc_define_method(rb_cSymbol, "swapcase", rsym_swapcase, 0); rb_objc_define_method(rb_cSymbol, "capitalize", rsym_capitalize, 0); // Cocoa primitives. rb_objc_install_method2((Class)rb_cSymbol, "copy", (IMP)rsym_imp_copy); rb_objc_install_method2((Class)rb_cSymbol, "length", (IMP)rsym_imp_length); rb_objc_install_method2((Class)rb_cSymbol, "characterAtIndex:", (IMP)rsym_imp_characterAtIndex); rb_objc_install_method2((Class)rb_cSymbol, "encodeWithCoder:", (IMP)rsym_imp_encodeWithCoder); rb_objc_install_method2((Class)rb_cSymbol, "initWithCoder:", (IMP)rsym_imp_initWithCoder); rb_objc_install_method2((Class)rb_cSymbol, "classForKeyedArchiver", (IMP)rsym_imp_classForKeyedArchiver); }