Пример #1
0
void
Init_perftools()
{
  cPerfTools = rb_define_class("PerfTools", rb_cObject);
  eError = rb_define_class_under(cPerfTools, "Error", rb_eStandardError);
  cCpuProfiler = rb_define_class_under(cPerfTools, "CpuProfiler", rb_cObject);

  Iallocate = rb_intern("allocate");
  I__send__ = rb_intern("__send__");
  Isend = rb_intern("send");

  bMethProfilerRunning = bObjProfilerRunning = bProfilerRunning = Qfalse;

  rb_define_singleton_method(cCpuProfiler, "running?", cpuprofiler_running_p, 0);
  rb_define_singleton_method(cCpuProfiler, "start", cpuprofiler_start, 1);
  rb_define_singleton_method(cCpuProfiler, "stop", cpuprofiler_stop, 0);

  gc_hook = Data_Wrap_Struct(cCpuProfiler, cpuprofiler_gc_mark, NULL, NULL);
  rb_global_variable(&gc_hook);

  if (ProfilingIsEnabledForAllThreads()) { // profiler is already running?
    bProfilerRunning = Qtrue;

    if (getenv("CPUPROFILE_OBJECTS")) {    // want to profile objects
      objprofiler_setup();
    } else if (getenv("CPUPROFILE_METHODS")) {
      methprofiler_setup();
    }

    rb_set_end_proc(profiler_at_exit, 0);  // make sure to cleanup before the VM shuts down
  }
}
Пример #2
0
static void
init_rclosure(void)
{
    id_call = rb_intern("call");
    id_closures = rb_intern("closures");
    rclosure_initialized = TRUE;
    rb_set_end_proc(rclosure_end_proc, Qnil);
}
Пример #3
0
void
Init_cairo_device (void)
{
#if CAIRO_CHECK_VERSION(1, 10, 0)
  rb_cCairo_Device =
    rb_define_class_under (rb_mCairo, "Device", rb_cObject);
  rb_define_alloc_func (rb_cCairo_Device, cr_device_allocate);

  rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Device);
  rb_set_end_proc(cr_finish_all_guarded_devices_at_end, Qnil);


  rb_define_method (rb_cCairo_Device, "destroy", cr_device_destroy, 0);
  rb_define_method (rb_cCairo_Device, "finish", cr_device_finish, 0);
  rb_define_method (rb_cCairo_Device, "flush", cr_device_flush, 0);
  rb_define_method (rb_cCairo_Device, "acquire", cr_device_acquire, 0);
  rb_define_method (rb_cCairo_Device, "release", cr_device_release, 0);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_Device);

#  ifdef CAIRO_HAS_SCRIPT_SURFACE
  rb_cCairo_ScriptDevice =
    rb_define_class_under (rb_mCairo, "ScriptDevice", rb_cCairo_Device);

  rb_define_method (rb_cCairo_ScriptDevice, "initialize",
                    cr_script_device_initialize, 1);

  rb_define_method (rb_cCairo_ScriptDevice, "write_comment",
                    cr_script_device_write_comment, 1);

  rb_define_method (rb_cCairo_ScriptDevice, "set_mode",
                    cr_script_device_set_mode, 1);
  rb_define_method (rb_cCairo_ScriptDevice, "mode",
                    cr_script_device_get_mode, 0);

  rb_define_method (rb_cCairo_ScriptDevice, "reply",
                    cr_script_device_reply, 1);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_ScriptDevice);
#  endif

#  ifdef CAIRO_HAS_XML_SURFACE
  rb_cCairo_XMLDevice =
    rb_define_class_under (rb_mCairo, "XMLDevice", rb_cCairo_Device);

  rb_define_method (rb_cCairo_XMLDevice, "initialize",
                    cr_xml_device_initialize, 1);

  rb_define_method (rb_cCairo_XMLDevice, "reply",
                    cr_xml_device_reply, 1);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_XMLDevice);
#  endif

#endif
}
Пример #4
0
void Init_wkhtml_native() {
  //Global initialization of library and when Ruby shuts down
  wkhtmltopdf_init(USE_GRAPHICS_INT);
  wkhtmltoimage_init(USE_GRAPHICS_INT);
  rb_set_end_proc(Deinit_wkhtml_native, Qnil);

  idReady = rb_intern("ready");

  mWkHtml = rb_define_module("WkHtml");
  rb_define_const(mWkHtml, "LIBRARY_VERSION", rb_obj_freeze(rb_str_new_cstr(wkhtmltopdf_version())));
  rb_define_const(mWkHtml, "USE_GRAPHICS", INT2BOOL(USE_GRAPHICS_INT));

  mWkHtmlToPdf = rb_define_module_under(mWkHtml, "ToPdf");

  cWkHtmlToPdfGlobalSettings = rb_define_class_under(mWkHtmlToPdf, "GlobalSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToPdfGlobalSettings, wkhtml_topdf_globalsettings_alloc);
  rb_define_method(cWkHtmlToPdfGlobalSettings, "[]=", wkhtml_topdf_globalsettings_aset, 2);
  rb_define_method(cWkHtmlToPdfGlobalSettings, "[]", wkhtml_topdf_globalsettings_aref, 1);

  cWkHtmlToPdfObjectSettings = rb_define_class_under(mWkHtmlToPdf, "ObjectSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToPdfObjectSettings, wkhtml_topdf_objectsettings_alloc);
  rb_define_method(cWkHtmlToPdfObjectSettings, "[]=", wkhtml_topdf_objectsettings_aset, 2);
  rb_define_method(cWkHtmlToPdfObjectSettings, "[]", wkhtml_topdf_objectsettings_aref, 1);

  cWkHtmlToPdfConverter = rb_define_class_under(mWkHtmlToPdf, "Converter", rb_cObject);
  /*
  TODO
  rb_define_singleton_method(klass, "new", constructor, 1); //Uses Data_Wrap_Struct -> rb_obj_call_init(t_data, 1, argv);
  rb_define_method(klass, "initialize", initialize, 1);
  */
  rb_define_singleton_method(cWkHtmlToPdfConverter, "create", wkhtml_topdf_converter_create, 1);
  rb_define_method(cWkHtmlToPdfConverter, "add_object", wkhtml_topdf_converter_add_object, 2);
  rb_define_method(cWkHtmlToPdfConverter, "convert", wkhtml_topdf_converter_convert, 0);
  rb_define_method(cWkHtmlToPdfConverter, "http_error_code", wkhtml_topdf_converter_http_error_code, 0);
  rb_define_method(cWkHtmlToPdfConverter, "get_output", wkhtml_topdf_converter_get_output, 0);
  //Force use of factory method
  rb_undef_alloc_func(cWkHtmlToPdfConverter);
  rb_undef_method(rb_singleton_class(cWkHtmlToPdfConverter), "new");

  mWkHtmlToImage = rb_define_module_under(mWkHtml, "ToImage");

  cWkHtmlToImageGlobalSettings = rb_define_class_under(mWkHtmlToImage, "GlobalSettings", rb_cObject);
  rb_define_alloc_func(cWkHtmlToImageGlobalSettings, wkhtml_toimage_globalsettings_alloc);
  rb_define_method(cWkHtmlToImageGlobalSettings, "[]=", wkhtml_toimage_globalsettings_aset, 2);
  rb_define_method(cWkHtmlToImageGlobalSettings, "[]", wkhtml_toimage_globalsettings_aref, 1);

  cWkHtmlToImageConverter = rb_define_class_under(mWkHtmlToImage, "Converter", rb_cObject);
  rb_define_singleton_method(cWkHtmlToImageConverter, "create", wkhtml_toimage_converter_create, 2);
  rb_define_method(cWkHtmlToImageConverter, "convert", wkhtml_toimage_converter_convert, 0);
  rb_define_method(cWkHtmlToImageConverter, "http_error_code", wkhtml_toimage_converter_http_error_code, 0);
  rb_define_method(cWkHtmlToImageConverter, "get_output", wkhtml_toimage_converter_get_output, 0);
  //Force use of factory method
  rb_undef_alloc_func(cWkHtmlToImageConverter);
  rb_undef_method(rb_singleton_class(cWkHtmlToImageConverter), "new");
}
Пример #5
0
void Init_c_tokenizer_ext(void)
{
  rb_mStringEater = rb_define_module("StringEater");
  rb_cCTokenizer = rb_define_class_under(rb_mStringEater, 
      "CTokenizer", rb_cObject);

  rb_define_method(rb_cCTokenizer, "ctokenize!", tokenize_string, 5);

  /* set the callback for when the extension is unloaded */
  rb_set_end_proc(finalize_c_tokenizer_ext, 0);
}
Пример #6
0
void Init_session_ext() {
  curl_global_init(CURL_GLOBAL_ALL);
  rb_require("patron/error");

  rb_set_end_proc(&cs_list_interrupt, Qnil);

  mPatron = rb_define_module("Patron");

  ePatronError = rb_const_get(mPatron, rb_intern("Error"));

  eUnsupportedProtocol = rb_const_get(mPatron, rb_intern("UnsupportedProtocol"));
  eUnsupportedSSLVersion = rb_const_get(mPatron, rb_intern("UnsupportedSSLVersion"));
  eURLFormatError = rb_const_get(mPatron, rb_intern("URLFormatError"));
  eHostResolutionError = rb_const_get(mPatron, rb_intern("HostResolutionError"));
  eConnectionFailed = rb_const_get(mPatron, rb_intern("ConnectionFailed"));
  ePartialFileError = rb_const_get(mPatron, rb_intern("PartialFileError"));
  eTimeoutError = rb_const_get(mPatron, rb_intern("TimeoutError"));
  eTooManyRedirects = rb_const_get(mPatron, rb_intern("TooManyRedirects"));

  rb_define_module_function(mPatron, "libcurl_version", libcurl_version, 0);

  cSession = rb_define_class_under(mPatron, "Session", rb_cObject);
  cRequest = rb_define_class_under(mPatron, "Request", rb_cObject);
  rb_define_alloc_func(cSession, session_alloc);

  // Make "escape" available both as a class method and as an instance method,
  // to make it usable to the Util module which does not have access to
  // the Session object internally
  rb_define_singleton_method(cSession, "escape",   session_escape,         1);
  rb_define_method(cSession, "escape",         session_escape,         1);
  rb_define_singleton_method(cSession, "unescape",   session_unescape,         1);
  rb_define_method(cSession, "unescape",       session_unescape,       1);

  rb_define_method(cSession, "handle_request", session_handle_request, 1);
  rb_define_method(cSession, "reset",          session_reset,          0);
  rb_define_method(cSession, "interrupt",      session_interrupt,      0);
  rb_define_method(cSession, "add_cookie_file", add_cookie_file, 1);
  rb_define_method(cSession, "set_debug_file", set_debug_file, 1);
  rb_define_alias(cSession, "urlencode", "escape");
  rb_define_alias(cSession, "urldecode", "unescape");

  rb_define_const(cRequest, "AuthBasic",  LONG2NUM(CURLAUTH_BASIC));
  rb_define_const(cRequest, "AuthDigest", LONG2NUM(CURLAUTH_DIGEST));
  rb_define_const(cRequest, "AuthAny",    LONG2NUM(CURLAUTH_ANY));

  mProxyType = rb_define_module_under(mPatron, "ProxyType");
  rb_define_const(mProxyType, "HTTP", LONG2NUM(CURLPROXY_HTTP));
  rb_define_const(mProxyType, "HTTP_1_0", LONG2NUM(CURLPROXY_HTTP_1_0));
  rb_define_const(mProxyType, "SOCKS4", LONG2NUM(CURLPROXY_SOCKS4));
  rb_define_const(mProxyType, "SOCKS5", LONG2NUM(CURLPROXY_SOCKS5));
  rb_define_const(mProxyType, "SOCKS4A", LONG2NUM(CURLPROXY_SOCKS4A));
  rb_define_const(mProxyType, "SOCKS5_HOSTNAME", LONG2NUM(CURLPROXY_SOCKS5_HOSTNAME));
}
Пример #7
0
static VALUE
rb_f_at_exit(void)
{
    VALUE proc;

    if (!rb_block_given_p()) {
	rb_raise(rb_eArgError, "called without a block");
    }
    proc = rb_block_proc();
    rb_set_end_proc(rb_call_end_proc, proc);
    return proc;
}
Пример #8
0
void
Init_groonga (void)
{
    VALUE mGrn;

    mGrn = rb_define_module("Groonga");

    rb_grn_init_exception(mGrn);

    rb_grn_rc_check(grn_init(), Qnil);
    rb_set_end_proc(finish_groonga, Qnil);

    rb_grn_init_version(mGrn);
    rb_grn_init_lock_timeout(mGrn);

    rb_grn_init_utils(mGrn);
    rb_grn_init_encoding(mGrn);
    rb_grn_init_encoding_support(mGrn);
    rb_grn_init_context(mGrn);
    rb_grn_init_object(mGrn);
    rb_grn_init_database(mGrn);
    rb_grn_init_table(mGrn);
    rb_grn_init_table_cursor(mGrn);
    rb_grn_init_index_cursor(mGrn);
    rb_grn_init_posting(mGrn);
    rb_grn_init_type(mGrn);
    rb_grn_init_procedure(mGrn);
    rb_grn_init_procedure_type(mGrn);
    rb_grn_init_column(mGrn);
    rb_grn_init_accessor(mGrn);
    rb_grn_init_geo_point(mGrn);
    rb_grn_init_record(mGrn);
    rb_grn_init_variable(mGrn);
    rb_grn_init_operator(mGrn);
    rb_grn_init_expression(mGrn);
    rb_grn_init_expression_builder(mGrn);
    rb_grn_init_logger(mGrn);
    rb_grn_init_query_logger(mGrn);
    rb_grn_init_snippet(mGrn);
    rb_grn_init_plugin(mGrn);
    rb_grn_init_normalizer(mGrn);
}
Пример #9
0
void
Init_cairo_context (void)
{
  cr_id_surface = rb_intern ("surface");
  cr_id_source = rb_intern ("source");

  cr_id_plus = rb_intern ("+");
  cr_id_minus = rb_intern ("-");
  cr_id_multi = rb_intern ("*");
  cr_id_div = rb_intern ("/");

#if CAIRO_CHECK_VERSION(1, 3, 0)
  rb_cCairo_Rectangle =
    rb_define_class_under (rb_mCairo, "Rectangle", rb_cObject);
  at_x = rb_intern ("@x");
  at_y = rb_intern ("@y");
  at_width = rb_intern ("@width");
  at_height = rb_intern ("@height");

  rb_define_attr (rb_cCairo_Rectangle, "x", CR_TRUE, CR_TRUE);
  rb_define_attr (rb_cCairo_Rectangle, "y", CR_TRUE, CR_TRUE);
  rb_define_attr (rb_cCairo_Rectangle, "width", CR_TRUE, CR_TRUE);
  rb_define_attr (rb_cCairo_Rectangle, "height", CR_TRUE, CR_TRUE);

  rb_define_method (rb_cCairo_Rectangle, "initialize",
                    cr_rectangle_initialize, 4);
#endif

  rb_cCairo_Context =
    rb_define_class_under (rb_mCairo, "Context", rb_cObject);

  rb_define_alloc_func (rb_cCairo_Context, cr_allocate);

  rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Context);
  rb_set_end_proc(cr_destroy_all_guarded_contexts_at_end, Qnil);

  /* Functions for manipulating state objects */
  rb_define_method (rb_cCairo_Context, "initialize", cr_initialize, 1);
  rb_define_method (rb_cCairo_Context, "destroy", cr_destroy, 0);

  rb_define_method (rb_cCairo_Context, "save", cr_save, 0);
  rb_define_method (rb_cCairo_Context, "restore", cr_restore, 0);
  rb_define_method (rb_cCairo_Context, "push_group", cr_push_group, -1);
  rb_define_method (rb_cCairo_Context, "pop_group", cr_pop_group_generic, -1);
  rb_define_method (rb_cCairo_Context, "pop_group_to_source",
                    cr_pop_group_to_source, 0);

  /* Modify state */
  rb_define_method (rb_cCairo_Context, "set_operator", cr_set_operator, 1);
  rb_define_method (rb_cCairo_Context, "set_source", cr_set_source_generic, -1);
  rb_define_method (rb_cCairo_Context, "set_source_rgb",
                    cr_set_source_rgb, -1);
  rb_define_method (rb_cCairo_Context, "set_source_rgba",
                    cr_set_source_rgba, -1);
  rb_define_method (rb_cCairo_Context, "set_tolerance", cr_set_tolerance, 1);
  rb_define_method (rb_cCairo_Context, "set_antialias", cr_set_antialias, 1);
  rb_define_method (rb_cCairo_Context, "set_fill_rule", cr_set_fill_rule, 1);
  rb_define_method (rb_cCairo_Context, "set_line_width", cr_set_line_width, 1);
  rb_define_method (rb_cCairo_Context, "set_line_cap", cr_set_line_cap, 1);
  rb_define_method (rb_cCairo_Context, "set_line_join", cr_set_line_join, 1);
  rb_define_method (rb_cCairo_Context, "set_dash", cr_set_dash, -1);
  rb_define_method (rb_cCairo_Context, "set_miter_limit",
                    cr_set_miter_limit, 1);

  rb_define_method (rb_cCairo_Context, "translate", cr_translate, 2);
  rb_define_method (rb_cCairo_Context, "scale", cr_scale, 2);
  rb_define_method (rb_cCairo_Context, "rotate", cr_rotate, 1);
  rb_define_method (rb_cCairo_Context, "transform", cr_transform, 1);

  rb_define_method (rb_cCairo_Context, "set_matrix", cr_set_matrix, 1);
  rb_define_method (rb_cCairo_Context, "identity_matrix",
                    cr_identity_matrix, 0);
  rb_define_method (rb_cCairo_Context, "user_to_device", cr_user_to_device, 2);
  rb_define_method (rb_cCairo_Context, "user_to_device_distance",
                    cr_user_to_device_distance, 2);
  rb_define_method (rb_cCairo_Context, "device_to_user", cr_device_to_user, 2);
  rb_define_method (rb_cCairo_Context, "device_to_user_distance",
                    cr_device_to_user_distance, 2);

  /* Path creation functions */
  rb_define_method (rb_cCairo_Context, "new_path", cr_new_path, 0);
  rb_define_method (rb_cCairo_Context, "move_to", cr_move_to, 2);
  rb_define_method (rb_cCairo_Context, "new_sub_path", cr_new_sub_path, 0);
  rb_define_method (rb_cCairo_Context, "line_to", cr_line_to, 2);
  rb_define_method (rb_cCairo_Context, "curve_to", cr_curve_to_generic, -1);
  rb_define_method (rb_cCairo_Context, "arc", cr_arc, 5);
  rb_define_method (rb_cCairo_Context, "arc_negative", cr_arc_negative, 5);
  rb_define_method (rb_cCairo_Context, "rel_move_to", cr_rel_move_to, 2);
  rb_define_method (rb_cCairo_Context, "rel_line_to", cr_rel_line_to, 2);
  rb_define_method (rb_cCairo_Context, "rel_curve_to",
                    cr_rel_curve_to_generic, -1);
  rb_define_method (rb_cCairo_Context, "rectangle", cr_rectangle, 4);
  rb_define_method (rb_cCairo_Context, "close_path", cr_close_path, 0);
#if CAIRO_CHECK_VERSION(1, 5, 8)
  rb_define_method (rb_cCairo_Context, "path_extents", cr_path_extents, 0);
#endif

  /* Painting functions */
  rb_define_method (rb_cCairo_Context, "paint", cr_paint_generic, -1);
  rb_define_method (rb_cCairo_Context, "mask", cr_mask_generic, -1);
  rb_define_method (rb_cCairo_Context, "stroke", cr_stroke, -1);
  rb_define_method (rb_cCairo_Context, "fill", cr_fill, -1);
  rb_define_method (rb_cCairo_Context, "copy_page", cr_copy_page, 0);
  rb_define_method (rb_cCairo_Context, "show_page", cr_show_page, 0);

  /* Insideness testing */
  rb_define_method (rb_cCairo_Context, "in_stroke?", cr_in_stroke, 2);
  rb_define_method (rb_cCairo_Context, "in_fill?", cr_in_fill, 2);

  /* Rectangular extents */
  rb_define_method (rb_cCairo_Context, "stroke_extents", cr_stroke_extents, 0);
  rb_define_method (rb_cCairo_Context, "fill_extents", cr_fill_extents, 0);

  /* Clipping */
  rb_define_method (rb_cCairo_Context, "reset_clip", cr_reset_clip, 0);
  rb_define_method (rb_cCairo_Context, "clip", cr_clip, -1);
#if CAIRO_CHECK_VERSION(1, 3, 0)
  rb_define_method (rb_cCairo_Context, "clip_extents", cr_clip_extents, 0);
  rb_define_method (rb_cCairo_Context, "clip_rectangle_list",
                    cr_clip_rectangle_list, 0);
#endif

  /* Font/Text functions */
  rb_define_method (rb_cCairo_Context, "select_font_face",
                    cr_select_font_face, -1);
  rb_define_method (rb_cCairo_Context, "set_font_size", cr_set_font_size, 1);
  rb_define_method (rb_cCairo_Context, "set_font_matrix",
                    cr_set_font_matrix, 1);
  rb_define_method (rb_cCairo_Context, "font_matrix", cr_get_font_matrix, 0);
  rb_define_method (rb_cCairo_Context, "set_font_options",
                    cr_set_font_options, 1);
  rb_define_method (rb_cCairo_Context, "font_options", cr_get_font_options, 0);
  rb_define_method (rb_cCairo_Context, "set_font_face", cr_set_font_face, 1);
  rb_define_method (rb_cCairo_Context, "font_face", cr_get_font_face, 0);
  rb_define_method (rb_cCairo_Context, "set_scaled_font",
                    cr_set_scaled_font, 1);
#if CAIRO_CHECK_VERSION(1, 3, 16)
  rb_define_method (rb_cCairo_Context, "scaled_font", cr_get_scaled_font, 0);
#endif
  rb_define_method (rb_cCairo_Context, "show_text", cr_show_text, 1);
  rb_define_method (rb_cCairo_Context, "show_glyphs", cr_show_glyphs, 1);
#if CAIRO_CHECK_VERSION(1, 8, 0)
  rb_define_method (rb_cCairo_Context, "show_text_glyphs",
                    cr_show_text_glyphs, 4);
#endif
  rb_define_method (rb_cCairo_Context, "text_path", cr_text_path, 1);
  rb_define_method (rb_cCairo_Context, "glyph_path", cr_glyph_path, 1);
  rb_define_method (rb_cCairo_Context, "text_extents", cr_text_extents, 1);
  rb_define_method (rb_cCairo_Context, "glyph_extents", cr_glyph_extents, 1);
  rb_define_method (rb_cCairo_Context, "font_extents", cr_font_extents, 0);

  /* Query functions */
  rb_define_method (rb_cCairo_Context, "operator", cr_get_operator, 0);
  rb_define_method (rb_cCairo_Context, "source", cr_get_source, 0);
  rb_define_method (rb_cCairo_Context, "tolerance", cr_get_tolerance, 0);
  rb_define_method (rb_cCairo_Context, "antialias", cr_get_antialias, 0);
#if CAIRO_CHECK_VERSION(1, 5, 10)
  rb_define_method (rb_cCairo_Context, "have_current_point?",
                    cr_has_current_point, 0);
  rb_define_alias (rb_cCairo_Context,
                   "has_current_point?", "have_current_point?");
#endif
  rb_define_method (rb_cCairo_Context, "current_point",
                    cr_get_current_point, 0);
  rb_define_method (rb_cCairo_Context, "fill_rule", cr_get_fill_rule, 0);
  rb_define_method (rb_cCairo_Context, "line_width", cr_get_line_width, 0);
  rb_define_method (rb_cCairo_Context, "line_cap", cr_get_line_cap, 0);
  rb_define_method (rb_cCairo_Context, "line_join", cr_get_line_join, 0);
  rb_define_method (rb_cCairo_Context, "miter_limit", cr_get_miter_limit, 0);
#if CAIRO_CHECK_VERSION(1, 3, 0)
  rb_define_method (rb_cCairo_Context, "dash_count", cr_get_dash_count, 0);
  rb_define_method (rb_cCairo_Context, "dash", cr_get_dash, 0);
#endif
  rb_define_method (rb_cCairo_Context, "matrix", cr_get_matrix, 0);
  rb_define_method (rb_cCairo_Context, "target", cr_get_target, 0);
  rb_define_method (rb_cCairo_Context, "group_target", cr_get_group_target, 0);

  /* Paths */
  rb_define_method (rb_cCairo_Context, "copy_path", cr_copy_path, 0);
  rb_define_method (rb_cCairo_Context, "copy_path_flat", cr_copy_path_flat, 0);
  rb_define_method (rb_cCairo_Context, "append_path", cr_copy_append_path, 1);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_Context);
}
Пример #10
0
void
rb_grn_init_logger (VALUE mGrn)
{
    id_caller_locations = rb_intern("caller_locations");
    id_path             = rb_intern("path");
    id_lineno           = rb_intern("lineno");
    id_label            = rb_intern("label");

    id_new    = rb_intern("new");
    id_parse  = rb_intern("parse");
    id_log    = rb_intern("log");
    id_reopen = rb_intern("reopen");
    id_fin    = rb_intern("fin");

    rb_grn_logger.log    = rb_grn_logger_log;
    rb_grn_logger.reopen = rb_grn_logger_reopen;
    rb_grn_logger.fin    = rb_grn_logger_fin;

    rb_grn_logger.user_data = (void *)Qnil;

    rb_cGrnLogger = rb_define_class_under(mGrn, "Logger", rb_cObject);

    rb_cv_set(rb_cGrnLogger, "@@current_logger", Qnil);
    rb_define_singleton_method(rb_cGrnLogger, "log",
                               rb_grn_logger_s_log, -1);
    rb_define_singleton_method(rb_cGrnLogger, "register",
                               rb_grn_logger_s_register, -1);
    rb_define_singleton_method(rb_cGrnLogger, "unregister",
                               rb_grn_logger_s_unregister, 0);
    rb_define_singleton_method(rb_cGrnLogger, "reopen",
                               rb_grn_logger_s_reopen, 0);
    rb_define_singleton_method(rb_cGrnLogger, "max_level",
                               rb_grn_logger_s_get_max_level, 0);
    rb_define_singleton_method(rb_cGrnLogger, "max_level=",
                               rb_grn_logger_s_set_max_level, 1);
    rb_define_singleton_method(rb_cGrnLogger, "path",
                               rb_grn_logger_s_get_path, 0);
    rb_define_singleton_method(rb_cGrnLogger, "path=",
                               rb_grn_logger_s_set_path, 1);
    rb_define_singleton_method(rb_cGrnLogger, "flags",
                               rb_grn_logger_s_get_flags, 0);
    rb_define_singleton_method(rb_cGrnLogger, "flags=",
                               rb_grn_logger_s_set_flags, 1);
    rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size",
                               rb_grn_logger_s_get_rotate_threshold_size, 0);
    rb_define_singleton_method(rb_cGrnLogger, "rotate_threshold_size=",
                               rb_grn_logger_s_set_rotate_threshold_size, 1);
    rb_set_end_proc(rb_grn_logger_reset, rb_cGrnLogger);

    rb_mGrnLoggerFlags = rb_define_module_under(rb_cGrnLogger, "Flags");
#define DEFINE_FLAG(NAME)                                       \
    rb_define_const(rb_mGrnLoggerFlags,                         \
                    #NAME, INT2NUM(GRN_LOG_ ## NAME))
    DEFINE_FLAG(TIME);
    DEFINE_FLAG(TITLE);
    DEFINE_FLAG(MESSAGE);
    DEFINE_FLAG(LOCATION);
    DEFINE_FLAG(PID);
#undef DEFINE_FLAG

    rb_cGrnCallbackLogger =
        rb_define_class_under(mGrn, "CallbackLogger", rb_cGrnLogger);
}
Пример #11
0
void
Init_cairo_surface (void)
{
  cr_id_target = rb_intern ("target");
  cr_id_read = rb_intern ("read");
  cr_id_write = rb_intern ("write");
  cr_id_inspect = rb_intern ("inspect");
  cr_id_parse = rb_intern ("parse");
  cr_id_size = rb_intern ("size");
  cr_id_set_unit = rb_intern ("unit=");

  rb_cCairo_Surface =
    rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
  rb_define_alloc_func (rb_cCairo_Surface, cr_surface_allocate);

  rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Surface);
  rb_set_end_proc(cr_finish_all_guarded_surfaces_at_end, Qnil);


  rb_define_method (rb_cCairo_Surface, "create_similar",
                    cr_surface_create_similar, 3);
  rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0);
  rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0);
  rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0);

  rb_define_method (rb_cCairo_Surface, "font_options",
                    cr_surface_get_font_options, 0);
  rb_define_method (rb_cCairo_Surface, "flush", cr_surface_flush, 0);
  rb_define_method (rb_cCairo_Surface, "mark_dirty", cr_surface_mark_dirty, -1);
  rb_define_method (rb_cCairo_Surface, "set_device_offset",
                    cr_surface_set_device_offset, 2);
  rb_define_method (rb_cCairo_Surface, "device_offset",
                    cr_surface_get_device_offset, 0);
  rb_define_method (rb_cCairo_Surface, "set_fallback_resolution",
                    cr_surface_set_fallback_resolution, 2);
#if CAIRO_CHECK_VERSION(1, 7, 2)
  rb_define_method (rb_cCairo_Surface, "fallback_resolution",
                    cr_surface_get_fallback_resolution, 0);
#endif
#if CAIRO_CHECK_VERSION(1, 5, 2)
  rb_define_method (rb_cCairo_Surface, "copy_page",
                    cr_surface_copy_page, 2);
  rb_define_method (rb_cCairo_Surface, "show_page",
                    cr_surface_show_page, 2);
#endif

#ifdef CAIRO_HAS_PNG_FUNCTIONS
  rb_define_method (rb_cCairo_Surface, "write_to_png",
                    cr_surface_write_to_png_generic, 1);
#endif

  RB_CAIRO_DEF_SETTERS (rb_cCairo_Surface);

  /* Image-surface */
  rb_cCairo_ImageSurface =
    rb_define_class_under (rb_mCairo, "ImageSurface", rb_cCairo_Surface);
  
#ifdef CAIRO_HAS_PNG_FUNCTIONS
  rb_define_singleton_method (rb_cCairo_ImageSurface, "from_png",
                              cr_image_surface_create_from_png_generic, 1);
#endif
  
  rb_define_method (rb_cCairo_ImageSurface, "initialize",
                    cr_image_surface_initialize, -1);

  rb_define_method (rb_cCairo_ImageSurface, "data",
                    cr_image_surface_get_data, 0);
  rb_define_method (rb_cCairo_ImageSurface, "format",
                    cr_image_surface_get_format, 0);
  rb_define_method (rb_cCairo_ImageSurface, "width",
                    cr_image_surface_get_width, 0);
  rb_define_method (rb_cCairo_ImageSurface, "height",
                    cr_image_surface_get_height, 0);
  rb_define_method (rb_cCairo_ImageSurface, "stride",
                    cr_image_surface_get_stride, 0);

#define INIT_SURFACE(type, name)                                        \
  rb_cCairo_ ## name ## Surface =                                       \
    rb_define_class_under (rb_mCairo, # name "Surface",                 \
                           rb_cCairo_Surface);                          \
                                                                        \
  rb_define_method (rb_cCairo_ ## name ## Surface, "initialize",        \
                    cr_ ## type ## _surface_initialize, -1);

#ifdef CAIRO_HAS_PS_SURFACE
  /* PS-surface */
  INIT_SURFACE(ps, PS)

  rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, -1);
  rb_define_method (rb_cCairo_PSSurface, "dsc_comment",
                    cr_ps_surface_dsc_comment, 1);
  rb_define_method (rb_cCairo_PSSurface, "dsc_begin_setup",
                    cr_ps_surface_dsc_begin_setup, 0);
  rb_define_method (rb_cCairo_PSSurface, "dsc_begin_page_setup",
                    cr_ps_surface_dsc_begin_page_setup, 0);

#  if CAIRO_CHECK_VERSION(1, 5, 2)
  rb_define_method (rb_cCairo_PSSurface, "restrict_to_level",
                    cr_ps_surface_restrict_to_level, 1);
  rb_define_method (rb_cCairo_PSSurface, "eps?", cr_ps_surface_get_eps, 0);
  rb_define_method (rb_cCairo_PSSurface, "set_eps", cr_ps_surface_set_eps, 1);
#  endif

  RB_CAIRO_DEF_SETTERS (rb_cCairo_PSSurface);
#endif

#ifdef CAIRO_HAS_PDF_SURFACE
  /* PDF-surface */
  INIT_SURFACE(pdf, PDF)

  rb_define_method (rb_cCairo_PDFSurface, "set_size",
                    cr_pdf_surface_set_size, -1);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
#endif

#ifdef CAIRO_HAS_SVG_SURFACE
  /* SVG-surface */
  INIT_SURFACE(svg, SVG)

  rb_define_method (rb_cCairo_SVGSurface, "restrict_to_version",
                    cr_svg_surface_restrict_to_version, 1);

  RB_CAIRO_DEF_SETTERS (rb_cCairo_SVGSurface);
#endif

#ifdef CAIRO_HAS_WIN32_SURFACE
  /* Win32-surface */
  rb_cCairo_Win32Surface =
    rb_define_class_under (rb_mCairo, "Win32Surface", rb_cCairo_Surface);

  rb_define_method (rb_cCairo_Win32Surface, "initialize",
                    cr_win32_surface_initialize, -1);
  rb_define_method (rb_cCairo_Win32Surface, "hdc",
                    cr_win32_surface_get_hdc, 0);
#  if CAIRO_CHECK_VERSION(1, 4, 0)
  rb_define_method (rb_cCairo_Win32Surface, "image",
                    cr_win32_surface_get_image, 0);
#  endif

#  if CAIRO_CHECK_VERSION(1, 5, 2)
  rb_cCairo_Win32PrintingSurface =
    rb_define_class_under (rb_mCairo, "Win32PrintingSurface", rb_cCairo_Surface);

  rb_define_method (rb_cCairo_Win32PrintingSurface, "initialize",
                    cr_win32_printing_surface_initialize, -1);
  rb_define_method (rb_cCairo_Win32PrintingSurface, "hdc",
                    cr_win32_surface_get_hdc, 0);
#  endif

#endif

#if defined(CAIRO_HAS_QUARTZ_SURFACE) && defined(HAVE_RUBY_COCOA)
  /* Quartz-surface */

  rb_cCairo_QuartzSurface =
    rb_define_class_under (rb_mCairo, "QuartzSurface", rb_cCairo_Surface);

  rb_define_method (rb_cCairo_QuartzSurface, "initialize",
                    cr_quartz_surface_initialize, -1);
  rb_define_method (rb_cCairo_QuartzSurface, "cg_context",
                    cr_quartz_surface_get_cg_context, 0);

#  if CAIRO_CHECK_VERSION(1, 5, 12)
  rb_cCairo_QuartzImageSurface =
    rb_define_class_under (rb_mCairo, "QuartzImageSurface", rb_cCairo_Surface);

  rb_define_method (rb_cCairo_QuartzImageSurface, "initialize",
                    cr_quartz_image_surface_initialize, 1);
  rb_define_method (rb_cCairo_QuartzImageSurface, "image",
                    cr_quartz_image_surface_get_image, 0);
#  endif

#endif
}
Пример #12
0
void
Init_oci8lib()
{
    VALUE cOCI8;
    OCIEnv *envhp;
    OCIError *errhp;
    sword rv;

#ifdef RUNTIME_API_CHECK
    Init_oci8_apiwrap();
    if (oracle_client_version < ORAVER_9_0) {
        rb_raise(rb_eLoadError, "Oracle 8 (8.0) and Oracle 8i (8.1) is not supported anymore!");
    }

    if (have_OCIClientVersion) {
        sword major, minor, update, patch, port_update;
        OCIClientVersion(&major, &minor, &update, &patch, &port_update);
        oracle_client_version = ORAVERNUM(major, minor, update, patch, port_update);
    }
#endif

    oci8_id_at_last_error = rb_intern("@last_error");
    oci8_id_new = rb_intern("new");
    oci8_id_get = rb_intern("get");
    oci8_id_set = rb_intern("set");
    oci8_id_oci8_vtable = rb_intern("__oci8_vtable__");
#ifdef CHAR_IS_NOT_A_SHORTCUT_TO_ID
    oci8_id_add_op = rb_intern("+");
    oci8_id_sub_op = rb_intern("-");
    oci8_id_mul_op = rb_intern("*");
    oci8_id_div_op = rb_intern("/");
#endif
#ifdef HAVE_RB_SET_END_PROC
    rb_set_end_proc(at_exit_func, Qnil);
#endif

    Init_oci8_thread_util();
    Init_oci8_error();
    Init_oci8_env();

    /* OCIHandle class */
    Init_oci8_handle();

    /* OCI8 class */
    Init_oci8(&cOCI8);

    /* OCI8::ConnectionPool class */
    Init_oci8_connection_pool(cOCI8);

    /* OCI8::BindType module */
    mOCI8BindType = rb_define_module_under(cOCI8, "BindType");
    /* OCI8::BindType::Base class */
    cOCI8BindTypeBase = rb_define_class_under(mOCI8BindType, "Base", oci8_cOCIHandle);

    /* Handle */
    Init_oci8_bind(cOCI8BindTypeBase);
    Init_oci8_stmt(cOCI8);

    /* Encoding */
    Init_oci8_encoding(cOCI8);

    /* register allocators */
    Init_oci8_metadata(cOCI8);
    Init_oci8_lob(cOCI8);

    /* allocate a temporary errhp to pass Init_oci_number() */
    rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL);
    if (rv != OCI_SUCCESS) {
        oci8_raise_init_error();
    }
    rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL);
    if (rv != OCI_SUCCESS)
        oci8_env_raise(envhp, rv);
    Init_oci_number(cOCI8, errhp);
    OCIHandleFree(errhp, OCI_HTYPE_ERROR);
    OCIHandleFree(envhp, OCI_HTYPE_ENV);

    Init_ora_date();
    Init_oci_datetime();
    Init_oci_object(cOCI8);

#ifdef USE_WIN32_C
    Init_oci8_win32(cOCI8);
#endif
}
Пример #13
0
void
Init_oci8lib()
{
    VALUE cOCI8;
    OCIEnv *envhp;
    OCIError *errhp;
    sword rv;

#ifdef RUNTIME_API_CHECK
    Init_oci8_apiwrap();
    if (oracle_client_version < ORAVER_10_1) {
        const char *oraver;
        const char *ruby_oci8_ver;
        if (oracle_client_version >= ORAVER_9_2) {
            oraver = "9iR2";
            ruby_oci8_ver = "2.1.x";
        } else if (oracle_client_version >= ORAVER_9_0) {
            oraver = "9iR1";
            ruby_oci8_ver = "2.1.x";
        } else if (oracle_client_version >= ORAVER_8_2) {
            oraver = "8i";
            ruby_oci8_ver = "2.0.x";
        } else {
            oraver = "8";
            ruby_oci8_ver = "2.0.x";
        }
        rb_raise(rb_eLoadError, "Ruby-oci8 %s doesn't support Oracle %s. Use ruby-oci8 %s instead.",
                 OCI8LIB_VERSION, oraver, ruby_oci8_ver);
    }

    if (have_OCIClientVersion) {
        sword major, minor, update, patch, port_update;
        OCIClientVersion(&major, &minor, &update, &patch, &port_update);
        oracle_client_version = ORAVERNUM(major, minor, update, patch, port_update);
    }
#endif

    oci8_id_at_last_error = rb_intern("@last_error");
    oci8_id_get = rb_intern("get");
    oci8_id_set = rb_intern("set");
#ifdef CHAR_IS_NOT_A_SHORTCUT_TO_ID
    oci8_id_add_op = rb_intern("+");
    oci8_id_sub_op = rb_intern("-");
    oci8_id_mul_op = rb_intern("*");
    oci8_id_div_op = rb_intern("/");
#endif
#ifdef HAVE_RB_SET_END_PROC
    rb_set_end_proc(at_exit_func, Qnil);
#endif

    Init_oci8_thread_util();
    Init_oci8_error();
    Init_oci8_env();

    /* OCIHandle class */
    Init_oci8_handle();

    /* OCI8 class */
    Init_oci8(&cOCI8);

    /* OCI8::ConnectionPool class */
    Init_oci8_connection_pool(cOCI8);

    /* OCI8::BindType module */
    mOCI8BindType = rb_define_module_under(cOCI8, "BindType");
    /* OCI8::BindType::Base class */
    cOCI8BindTypeBase = oci8_define_class_under(mOCI8BindType, "Base", &oci8_bind_data_type, bind_base_alloc);

    /* Handle */
    Init_oci8_bind(cOCI8BindTypeBase);
    Init_oci8_stmt(cOCI8);

    /* Encoding */
    Init_oci8_encoding(cOCI8);

    /* register allocators */
    Init_oci8_metadata(cOCI8);
    Init_oci8_lob(cOCI8);

    /* allocate a temporary errhp to pass Init_oci_number() */
    rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL);
    if (rv != OCI_SUCCESS) {
        oci8_raise_init_error();
    }
    rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL);
    if (rv != OCI_SUCCESS)
        oci8_env_raise(envhp, rv);
    Init_oci_number(cOCI8, errhp);
    OCIHandleFree(errhp, OCI_HTYPE_ERROR);
    OCIHandleFree(envhp, OCI_HTYPE_ENV);

    Init_ora_date();
    Init_oci_datetime();
    Init_oci_object(cOCI8);

#ifdef USE_WIN32_C
    Init_oci8_win32(cOCI8);
#endif
}
Пример #14
0
static VALUE kernel_spec_rb_set_end_proc(VALUE self, VALUE io) {
  rb_set_end_proc(write_io, io);
  return Qnil;
}
void Init_ayame()
{
    HRESULT hr;
    HWND hWnd;
    WNDCLASSEX wcex;
    RECT rect;
    HINSTANCE hInstance;

    CoInitialize(NULL);

    /* インスタンスハンドル取得 */
    hInstance = (HINSTANCE)GetModuleHandle( NULL );

    /* ウインドウ・クラスの登録 */
    wcex.cbSize        = sizeof( WNDCLASSEX );
    wcex.style         = 0;
    wcex.lpfnWndProc   = DefWindowProc;
    wcex.cbClsExtra    = 0;
    wcex.cbWndExtra    = 0;
    wcex.hInstance     = hInstance;
    wcex.hIcon         = 0;
    wcex.hIconSm       = 0;
    wcex.hCursor       = 0;
    wcex.hbrBackground = 0;
    wcex.lpszMenuName  = NULL;
    wcex.lpszClassName = "Ayame";

    if( !RegisterClassEx( &wcex ) )
    {
        rb_raise( eAyameError, "ウィンドウの初期化に失敗しました - RegusterClassEx" );
    }

    hWnd = CreateWindow("Ayame", "", WS_POPUP, 0, 0, 0, 0, 0, NULL, hInstance, NULL);

    /* 例外定義 */
    eAyameError = rb_define_class( "AyameError", rb_eRuntimeError );

    if ( !CVoiceElementAyame::m_sAyameMgr.LoadDLL( hWnd, "Ayame.dll", 0 ) ) rb_raise( eAyameError, "Ayame.dllがロードできませんでした" );

    /* Ayameクラス定義 */
    cAyame = rb_define_class ( "Ayame", rb_cObject );

    /* Ayameクラスにメソッド登録*/
    rb_define_private_method( cAyame, "initialize", (VALUE(*)(...))Ayame_initialize, 1 );
    rb_define_singleton_method( cAyame, "load_from_memory", (VALUE(*)(...))Ayame_load_from_memory, 1 );
    rb_define_method( cAyame, "play", (VALUE(*)(...))Ayame_play, -1 );
    rb_define_method( cAyame, "stop", (VALUE(*)(...))Ayame_stop, -1 );
    rb_define_method( cAyame, "get_volume", (VALUE(*)(...))Ayame_get_volume, 0 );
    rb_define_method( cAyame, "set_volume", (VALUE(*)(...))Ayame_set_volume, -1 );
    rb_define_method( cAyame, "get_pan", (VALUE(*)(...))Ayame_get_pan, 0 );
    rb_define_method( cAyame, "set_pan", (VALUE(*)(...))Ayame_set_pan, -1 );
    rb_define_method( cAyame, "dispose", (VALUE(*)(...))Ayame_dispose, 0 );
    rb_define_method( cAyame, "pause", (VALUE(*)(...))Ayame_pause, 1 );
    rb_define_method( cAyame, "resume", (VALUE(*)(...))Ayame_resume, 1 );
    rb_define_method( cAyame, "prefetch", (VALUE(*)(...))Ayame_prefetch, 0 );
    rb_define_method( cAyame, "predecode", (VALUE(*)(...))Ayame_predecode, 0 );

    rb_define_method( cAyame, "fading?", (VALUE(*)(...))Ayame_IsFade, 0 );
    rb_define_method( cAyame, "playing?", (VALUE(*)(...))Ayame_IsPlay, 0 );
    rb_define_method( cAyame, "finished?", (VALUE(*)(...))Ayame_IsFinish, 0 );
    rb_define_method( cAyame, "pausing?", (VALUE(*)(...))Ayame_IsPause, 0 );

    rb_define_singleton_method( cAyame, "update", (VALUE(*)(...))Ayame_update, 0 );

    /* Ayameオブジェクトを生成した時にinitializeの前に呼ばれるメモリ割り当て関数登録 */
    rb_define_alloc_func( cAyame, Ayame_allocate );

    /* 終了時に実行する関数 */
    rb_set_end_proc( (void(*)(VALUE))Ayame_shutdown, Qnil );

    InitSync();

    /* Ayameオブジェクトの内部参照リスト */
    g_AyameList.pointer = (void**)malloc( sizeof(void*) * 16 );
    g_AyameList.count = 0;
    g_AyameList.allocate_size = 16;
}