コード例 #1
0
ファイル: signal.c プロジェクト: WildHunter/libevent
/*
 * Create and add signal to specified event base with handler block
 *
 * @note method allocates memory for <b>struct event </b>
 *   that will be freed when object will be freed by ruby' GC
 *
 * @param [Base] base event base instance
 * @param [String] name a name of signal
 * @param [Object] handler object that perform signal handling. Any object that responds to :call method
 *
 */
static VALUE t_initialize(VALUE self, VALUE base, VALUE name, VALUE handler) {
  Libevent_Signal *le_signal;
  Libevent_Base *le_base;
  VALUE signal_list;
  VALUE signal_number;

  Data_Get_Struct(self, Libevent_Signal, le_signal);
  Data_Get_Struct(base, Libevent_Base, le_base);

  // check name
  signal_list = rb_funcall( rb_const_get(rb_cObject, rb_intern("Signal")), rb_intern("list"), 0);
  signal_number = rb_hash_aref(signal_list, name);
  if ( signal_number == Qnil )
    rb_raise(rb_eArgError, "unknown signal name given");
  rb_iv_set(self, "@name", name);

  // check handler
  if ( !rb_respond_to(handler, rb_intern("call")))
    rb_raise(rb_eArgError, "handler does not response to call method");
  rb_iv_set(self, "@handler", handler);

  // create signal event
  le_signal->ev_event = evsignal_new(le_base->ev_base, FIX2INT(signal_number), t_handler, (void *)handler);
  if ( !le_signal->ev_event )
    rb_fatal("Could not create a signal event");
  if ( event_add(le_signal->ev_event, NULL) < 0 )
    rb_fatal("Could not add a signal event");

  return self;
}
コード例 #2
0
ファイル: dir.c プロジェクト: cygwin-fork/ruby186
static int
CompareImpl(const char *p1, const char *p2, int nocase)
{
    const int len1 = Next(p1) - p1;
    const int len2 = Next(p2) - p2;
#ifdef _WIN32
    char buf1[10], buf2[10]; /* large enough? */
#endif

    if (len1 < 0 || len2 < 0) {
	rb_fatal("CompareImpl: negative len");
    }

    if (len1 == 0) return  len2;
    if (len2 == 0) return -len1;

#ifdef _WIN32
    if (nocase && rb_w32_iswinnt()) {
	if (len1 > 1) {
	    if (len1 >= sizeof(buf1)) {
		rb_fatal("CompareImpl: too large len");
	    }
	    memcpy(buf1, p1, len1);
	    buf1[len1] = '\0';
	    CharLower(buf1);
	    p1 = buf1; /* trick */
	}
	if (len2 > 1) {
	    if (len2 >= sizeof(buf2)) {
		rb_fatal("CompareImpl: too large len");
	    }
	    memcpy(buf2, p2, len2);
	    buf2[len2] = '\0';
	    CharLower(buf2);
	    p2 = buf2; /* trick */
	}
    }
#endif
    if (len1 == 1)
	if (len2 == 1)
	    return compare(downcase(*p1), downcase(*p2));
	else {
	    const int ret = compare(downcase(*p1), *p2);
	    return ret ? ret : -1;
	}
    else
	if (len2 == 1) {
	    const int ret = compare(*p1, downcase(*p2));
	    return ret ? ret : 1;
	}
	else {
	    const int ret = memcmp(p1, p2, len1 < len2 ? len1 : len2);
	    return ret ? ret : len1 - len2;
	}
}
コード例 #3
0
ファイル: coremidi.c プロジェクト: elektronaut/livecode
// Create a new source endpoint
static VALUE t_create_source(VALUE self, VALUE client_instance, VALUE source_name)
{
    MIDIEndpointRef source;
    
    RbMIDIClient* client;
    Data_Get_Struct(client_instance, RbMIDIClient, client);
    
    CFStringRef source_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(source_name)->ptr, kCFStringEncodingASCII);

    MIDISourceCreate(client->client, source_str, &source);

    VALUE source_instance = rb_class_new_instance(0, 0, cEndpoint);
    if( source_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of Endpoint!");
    }
    
    RbEndpoint* endpoint_struct;
    Data_Get_Struct(source_instance, RbEndpoint, endpoint_struct);
    
    endpoint_struct->endpoint = source;
    
    return source_instance;
}
コード例 #4
0
ファイル: coremidi.c プロジェクト: elektronaut/livecode
// Create a new destination endpoint
static VALUE t_create_destination(VALUE self, VALUE client_instance, VALUE destination_name)
{
    MIDIEndpointRef destination;
    
    RbMIDIClient* client;
    Data_Get_Struct(client_instance, RbMIDIClient, client);
    
    CFStringRef destination_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(destination_name)->ptr, kCFStringEncodingASCII);

    MIDIDestinationCreate(client->client, destination_str, RbMIDIReadProc, NULL, &destination);

    VALUE destination_instance = rb_class_new_instance(0, 0, cEndpoint);
    if( destination_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of Endpoint!");
    }
    
    RbEndpoint* endpoint_struct;
    Data_Get_Struct(destination_instance, RbEndpoint, endpoint_struct);
    
    endpoint_struct->endpoint = destination;
    
    return destination_instance;
}
コード例 #5
0
ファイル: coremidi.c プロジェクト: elektronaut/livecode
// Create a new Output Port and saves the Ruby Callback proc.
static VALUE t_create_output_port(VALUE self, VALUE client_instance, VALUE port_name)
{
    MIDIPortRef out_port;
    
    RbMIDIClient* client;
    Data_Get_Struct(client_instance, RbMIDIClient, client);
    
    CFStringRef port_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(port_name)->ptr, kCFStringEncodingASCII);

    MIDIOutputPortCreate(client->client, port_str, &out_port);

    CFRelease(port_str);
    
    VALUE outputport_instance = rb_class_new_instance(0, 0, cOutputPort);
    if( outputport_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of OutputPort!");
    }
    
    RbOutputPort* port_struct;
    Data_Get_Struct(outputport_instance, RbOutputPort, port_struct);
    
    port_struct->output_port = out_port;
    
    return outputport_instance;
}
コード例 #6
0
/*
 * call-seq:
 *    parser.parse -> (true|false)
 *
 * Parse the input XML, generating callbacks to the object
 * registered via the +callbacks+ attributesibute.
 */
static VALUE rxml_sax_parser_parse(VALUE self)
{
  int status;
  VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
  xmlParserCtxtPtr ctxt;
  Data_Get_Struct(context, xmlParserCtxt, ctxt);

  ctxt->sax2 = 1;
	ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);

  if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
    xmlFree(ctxt->sax);
    
  ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(rxml_sax_handler));
  if (ctxt->sax == NULL)
    rb_fatal("Not enough memory.");
  memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler));
    
  status = xmlParseDocument(ctxt);

  /* Now check the parsing result*/
  if (status == -1 || !ctxt->wellFormed)
  {
    if (ctxt->myDoc)
      xmlFreeDoc(ctxt->myDoc);

    rxml_raise(&ctxt->lastError);
  }
  return Qtrue;
}
コード例 #7
0
ファイル: rbcoremidi.c プロジェクト: jimm/rbcoremidi
// Create a new Input Port and saves the Ruby Callback proc.
static VALUE t_create_input_port(VALUE self, VALUE client_instance, VALUE port_name)
{
    MIDIPortRef in_port;
    
    RbMIDIClient* client;
    Data_Get_Struct(client_instance, RbMIDIClient, client);
    
    CFStringRef port_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(port_name)->as.heap.ptr, kCFStringEncodingASCII);
    MIDIInputPortCreate(client->client, port_str, RbMIDIReadProc, NULL, &in_port);
    CFRelease(port_str);
    
    VALUE inputport_instance = rb_class_new_instance(0, 0, cInputPort);
    if( inputport_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of InputPort!");
    }
    
    RbInputPort* port_struct;
    Data_Get_Struct(inputport_instance, RbInputPort, port_struct);
    
    port_struct->input_port = in_port;
    
    return inputport_instance;
}
コード例 #8
0
VALUE
vector_layer_alloc(VALUE klass){
  simplet_vector_layer_t *layer;
  if(!(layer = simplet_vector_layer_new("")))
    rb_fatal("Could not allocate space for a new SimplerTiles::Layer in memory.");

  return Data_Wrap_Struct(klass, mark_layer, layer_free, layer);
}
コード例 #9
0
ファイル: graph.c プロジェクト: ged/redleaf
/*
 * Fetch the data pointer and check it for sanity.
 */
rleaf_GRAPH *
rleaf_get_graph( VALUE self ) {
	rleaf_GRAPH *graph = check_graph( self );

	if ( !graph )
		rb_fatal( "Use of uninitialized Graph." );

	return graph;
}
コード例 #10
0
AVFormatContext * get_format_context(VALUE self)
{
    AVFormatContext * format_context = NULL;
    Data_Get_Struct(self, AVFormatContext, format_context);
    if (NULL == format_context) {
        rb_fatal("FFMPEG internal error\n");
    }
    return format_context;
}
コード例 #11
0
AVFrame * get_frame(VALUE self)
{
    AVFrame * frame = NULL;
    Data_Get_Struct(self, AVFrame, frame);
    if (NULL == frame) {
        rb_fatal("FFMPEG internal error\n");
    }
    return frame;
}
コード例 #12
0
ファイル: style.c プロジェクト: milafrerichs/simpler-tiles
static VALUE
alloc_style(VALUE klass){
  simplet_style_t *style;

  if(!(style = simplet_style_new(NULL, NULL)))
    rb_fatal("Could not allocate space for a new SimplerTiles::Style in memory.");

  return Data_Wrap_Struct(klass, mark_style, style_free, style);
}
コード例 #13
0
AVStream * get_stream(VALUE self)
{
    AVStream * stream = NULL;
    Data_Get_Struct(self, AVStream, stream);
    if (NULL == stream) {
        rb_fatal("FFMPEG internal error\n");
    }
    return stream;
}
コード例 #14
0
ファイル: bluecloth.c プロジェクト: invalidusrname/hubbub
/*
 * Fetch the data pointer and check it for sanity.
 */
static MMIOT *
bluecloth_get_ptr( VALUE self ) {
    MMIOT *ptr = bluecloth_check_ptr( self );

    if ( !ptr )
        rb_fatal( "Use of uninitialized BlueCloth object" );

    return ptr;
}
コード例 #15
0
AVCodecContext * get_codec_context(VALUE self)
{
    AVCodecContext * codec_context = NULL;
    Data_Get_Struct(self, AVCodecContext, codec_context);
    if (NULL == codec_context) {
        rb_fatal("FFMPEG internal error\n");
    }
    return codec_context;
}
コード例 #16
0
ファイル: node.c プロジェクト: ged/redleaf
/*
 * Convert the given librdf_node to a Ruby object and return it as a VALUE.
 */
VALUE
rleaf_librdf_node_to_value( librdf_node *node ) {
	VALUE node_object = Qnil, node_string = Qnil;
	librdf_node_type nodetype = LIBRDF_NODE_TYPE_UNKNOWN;
	unsigned char *bnode_idname = NULL;
	ID bnode_id;

	if ( !node ) rb_fatal( "NULL pointer given to rleaf_librdf_node_to_value()" );
	nodetype = librdf_node_get_type( node );

	node_string = rleaf_librdf_node_to_string( node );
	rleaf_log( "debug", "Converting node %s to a Ruby VALUE", RSTRING_PTR(node_string) );

	switch( nodetype ) {

		/* URI node => URI */
		case LIBRDF_NODE_TYPE_RESOURCE:
		node_object = rleaf_librdf_uri_node_to_object( node );
		break;

		/* Blank node => Symbol */
		case LIBRDF_NODE_TYPE_BLANK:
		bnode_idname = librdf_node_get_blank_identifier( node );
		if ( bnode_idname ) {
			rleaf_log( "debug", "Converted a bnode to %s", bnode_idname );
			bnode_id = rb_intern( (char *)bnode_idname );
			node_object = ID2SYM( bnode_id );
		} else {
			rleaf_log( "error", "Failed to get a blank identifier!" );
			node_object = Qnil;
		}
		break;

		/* Literal => <ruby object> */
		case LIBRDF_NODE_TYPE_LITERAL:
		node_object = rleaf_librdf_literal_node_to_object( node );
		break;

		default:
		rb_fatal( "Unknown node type %d encountered when converting a node.", nodetype );
	}

	return node_object;
}
コード例 #17
0
ファイル: rbosa.c プロジェクト: bmorton/rubyosa
static VALUE
rbosa_element_data (int argc, VALUE *argv, VALUE self)
{
    VALUE       coerce_type;
    AEDesc      coerced_desc;
    AEDesc *    desc;
    OSErr       error;
    void *      data;
    Size        datasize;
    VALUE       retval;
    bool        to_4cc;

    rb_scan_args (argc, argv, "01", &coerce_type);
    to_4cc = false;

    desc  = rbosa_element_aedesc (self);
    
    if (!NIL_P (coerce_type)) {
        FourCharCode code;

        code = RVAL2FOURCHAR (coerce_type);
        error = AECoerceDesc (desc, code, &coerced_desc);
        if (error != noErr)
            rb_raise (rb_eRuntimeError, "Cannot coerce desc to type %s : %s (%d)", 
                      RVAL2CSTR (coerce_type), error_code_to_string (error), error);
        
        desc = &coerced_desc;
        to_4cc = code == 'type';
    }

    datasize = AEGetDescDataSize (desc);
    data = (void *)malloc (datasize);
    if (data == NULL) 
        rb_fatal ("cannot allocate memory");
 
    error = AEGetDescData (desc, data, datasize);
    if (error == noErr) {
        if (to_4cc)
            *(DescType*)data = CFSwapInt32HostToBig (*(DescType*)data);
        retval = rb_str_new (data, datasize);
    }
    else {
        retval = Qnil;
    }

    if (!NIL_P (coerce_type))
        AEDisposeDesc (&coerced_desc); 
    free (data);

    if (error != noErr)
        rb_raise (rb_eRuntimeError, "Cannot get desc data : %s (%d)", 
                  error_code_to_string (error), error);
    
    return retval; 
}
コード例 #18
0
ファイル: main.cpp プロジェクト: Hanmac/rwx
VALUE wrapTypedPtr(void *arg,VALUE klass, bool allowNull)
{
	if(arg || allowNull){
		rb_data_type_t* datatype = unwrapDataType(klass);
		if(!datatype)
			rb_fatal("%" PRIsVALUE " unknown datatype", RB_CLASSNAME(klass));

		return TypedData_Wrap_Struct(klass, datatype, arg);
	}
	return Qnil;
}
コード例 #19
0
ファイル: wxError.cpp プロジェクト: Hanmac/rwx
NORETURN(void wxrubyAssert(const wxString& file,
                                  int line,
                                  const wxString& func,
                                  const wxString& cond,
                                  const wxString& msg)
{
	rb_fatal("(%s) in %s \n %s",
		cond.GetData().AsChar(),
		func.GetData().AsChar(),
		msg.GetData().AsChar()
		);
})
コード例 #20
0
ファイル: base.c プロジェクト: WildHunter/libevent
/*
 * Allocate memmory
 */
static VALUE t_allocate(VALUE klass) {
  Libevent_Base *base;

  base = ALLOC(Libevent_Base);
  base->ev_base = event_base_new();

  if ( !base->ev_base ) {
    rb_fatal("Couldn't get an event base");
  }

  return Data_Wrap_Struct(klass, 0, t_free, base); 
}
コード例 #21
0
ファイル: rbosa.c プロジェクト: bmorton/rubyosa
static VALUE
rbosa_element_eql (VALUE self, VALUE other)
{
    AEDesc *    self_desc;
    AEDesc *    other_desc; 
    Size        data_size;
    void *      self_data;
    void *      other_data;
    OSErr       error;
    Boolean     ok;

    if (!rb_obj_is_kind_of (other, rb_class_real (rb_class_of (self))))
        return Qfalse;

    self_desc = rbosa_element_aedesc (self);
    other_desc = rbosa_element_aedesc (other);

    if (self_desc == other_desc)
        return Qtrue;

    if (self_desc->descriptorType != other_desc->descriptorType)
        return Qfalse;

    data_size = AEGetDescDataSize (self_desc);
    if (data_size != AEGetDescDataSize (other_desc))
        return Qfalse;
  
    self_data = (void *)malloc (data_size);
    other_data = (void *)malloc (data_size);  
    ok = 0;

    if (self_data == NULL || other_data == NULL)
        rb_fatal ("cannot allocate memory");

    error = AEGetDescData (self_desc, self_data, data_size);
    if (error != noErr)
        goto bails;

    error = AEGetDescData (other_desc, other_data, data_size);
    if (error != noErr)
        goto bails;
    
    ok = memcmp (self_data, other_data, data_size) == 0;

bails:
    free (self_data);
    free (other_data);

    return CBOOL2RVAL (ok);
}
コード例 #22
0
ファイル: poker_eval.c プロジェクト: cubesystems/poker_eval
static int rbList2CardMask(VALUE object, CardMask* cardsp)
{
  CardMask cards;
  int cards_size = 0;
  int valid_cards_size = 0;

  if (TYPE(object) != T_ARRAY)
  {
    rb_fatal("expected a list of cards");
  }

  valid_cards_size = cards_size = RARRAY_LENINT(object);
  CardMask_RESET(cards);

  int card;
  int i;
  for(i = 0; i < cards_size; i++) {
    card = -1;
    char* card_string = RSTRING_PTR(rb_ary_entry(object, i));

    if(!strcmp(card_string, "__"))
        card = 255;
    else
        if(Deck_stringToCard(card_string, &card) == 0)
            rb_fatal("card %s is not a valid card name", card_string);

    if(card == NOCARD)
      valid_cards_size--;
    else
      CardMask_SET(cards, card);
  }

  *cardsp = cards;

  return valid_cards_size;
}
コード例 #23
0
ファイル: error.c プロジェクト: evan/ruby
void
rb_check_type(VALUE x, int t)
{
    const struct types *type = builtin_types;
    const struct types *const typeend = builtin_types +
	sizeof(builtin_types) / sizeof(builtin_types[0]);
    int xt;

    if (x == Qundef) {
	rb_bug("undef leaked to the Ruby space");
    }

    xt = TYPE(x);
    if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
	while (type < typeend) {
	    if (type->type == t) {
		const char *etype;

		if (NIL_P(x)) {
		    etype = "nil";
		}
		else if (FIXNUM_P(x)) {
		    etype = "Fixnum";
		}
		else if (SYMBOL_P(x)) {
		    etype = "Symbol";
		}
		else if (rb_special_const_p(x)) {
		    x = rb_obj_as_string(x);
		    etype = StringValuePtr(x);
		}
		else {
		    etype = rb_obj_classname(x);
		}
		rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
			 etype, type->name);
	    }
	    type++;
	}
	if (xt > T_MASK && xt <= 0x3f) {
	    rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
	}
	rb_bug("unknown type 0x%x (0x%x given)", t, xt);
    }
}
コード例 #24
0
ファイル: femme_fatale.c プロジェクト: nagachika/femme_fatale
static VALUE
femme_fatale(int argc, VALUE *argv, VALUE obj)
{
    VALUE msg = Qnil;
    const char *cmsg = NULL;

    (void)obj;

    rb_scan_args(argc, argv, "01", &msg);
    if (RTEST(msg)) {
	cmsg = RSTRING_PTR(msg);
    }
    else {
	cmsg = "femme fatale!";
    }
    rb_fatal(cmsg);
    return 0; /* never reached */
}
コード例 #25
0
ファイル: rbosa.c プロジェクト: bmorton/rubyosa
static VALUE
rbosa_element_make (VALUE klass, AEDesc *desc, VALUE app)
{
    AEDesc *    newDesc;
    VALUE       new_klass, obj;

    newDesc = (AEDesc *)malloc (sizeof (AEDesc));
    if (newDesc == NULL)
        rb_fatal ("cannot allocate memory");
    memcpy (newDesc, desc, sizeof (AEDesc));
    new_klass = Qnil;

    /* Let's replace the klass here according to the type of the descriptor,
     * if the basic class OSA::Element was given.
     */
    if (klass == cOSAElement) {
        if (newDesc->descriptorType == 'list') {
            klass = cOSAElementList;
        }
        else if (newDesc->descriptorType == 'reco') {
            klass = cOSAElementRecord;
        }
        else if (newDesc->descriptorType == 'type') {
            new_klass = __rbosa_class_from_desc_data (app, *newDesc);
        }
        else if (newDesc->descriptorType == 'obj ' && !NIL_P (app)) {
            AEDesc  res;
            OSErr   err;

            if ((err = AEGetParamDesc ((AppleEvent *)newDesc, 'want', '****', &res)) == noErr)
                new_klass = __rbosa_class_from_desc_data (app, res);
        }
    }

    if (!NIL_P (new_klass))
        klass = new_klass; 
    
    obj = Data_Wrap_Struct (klass, NULL, rbosa_element_free, newDesc);

    rb_ivar_set (obj, sApp, NIL_P (app) ? obj : app);

    return obj;
}
コード例 #26
0
ファイル: node.c プロジェクト: ged/redleaf
/*
 * Return the specified +node+ as an NTriples string.
 */
VALUE
rleaf_librdf_node_to_string( librdf_node *node )
{
	raptor_iostream *stream = NULL;
	void *dumped_node = NULL;
	int ret;

	stream = raptor_new_iostream_to_string( node->world, &dumped_node, NULL, NULL );
	if ( !stream ) {
		rb_sys_fail( "raptor_new_iostream_to_string" );
	}

	ret = librdf_node_write( node, stream );
	raptor_free_iostream( stream );

	if ( ret != 0 )
		rb_fatal( "librdf_node_write failed." );

	return rb_str_new2( (char *)dumped_node );
}
コード例 #27
0
ファイル: ruby.c プロジェクト: Netfart/rhodes
static VALUE
rubylib_mangled_path(const char *s, unsigned int l)
{
    static char *newp, *oldp;
    static int newl, oldl, notfound;
    char *ptr;
    VALUE ret;

    if (!newp && !notfound) {
	newp = getenv("RUBYLIB_PREFIX");
	if (newp) {
	    oldp = newp = strdup(newp);
	    while (*newp && !ISSPACE(*newp) && *newp != ';') {
		newp = CharNext(newp);	/* Skip digits. */
	    }
	    oldl = newp - oldp;
	    while (*newp && (ISSPACE(*newp) || *newp == ';')) {
		newp = CharNext(newp);	/* Skip whitespace. */
	    }
	    newl = strlen(newp);
	    if (newl == 0 || oldl == 0) {
		rb_fatal("malformed RUBYLIB_PREFIX");
	    }
	    translate_char(newp, '\\', '/');
	}
	else {
	    notfound = 1;
	}
    }
    if (!newp || l < oldl || STRNCASECMP(oldp, s, oldl) != 0) {
	return rb_str_new(s, l);
    }
    ret = rb_str_new(0, l + newl - oldl);
    ptr = RSTRING_PTR(ret);
    memcpy(ptr, newp, newl);
    memcpy(ptr + newl, s + oldl, l - oldl);
    ptr[l + newl - oldl] = 0;
    return ret;
}
コード例 #28
0
ファイル: error.c プロジェクト: knugie/ruby
void
rb_check_type(VALUE x, int t)
{
    int xt;

    if (x == Qundef) {
	rb_bug("undef leaked to the Ruby space");
    }

    xt = TYPE(x);
    if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
	const char *tname = rb_builtin_type_name(t);
	if (tname) {
	    rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
		     builtin_class_name(x), tname);
	}
	if (xt > T_MASK && xt <= 0x3f) {
	    rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
	}
	rb_bug("unknown type 0x%x (0x%x given)", t, xt);
    }
}
コード例 #29
0
ファイル: ruby_xml_node.c プロジェクト: nikitug/libxml-ruby
/*
 * call-seq:
 *    node.xlink_type_name -> "string"
 *
 * Obtain the type name for this xlink, if applicable.
 * If this is not an xlink node (see +xlink?+), will return
 * nil.
 */
static VALUE rxml_node_xlink_type_name(VALUE self)
{
  xmlNodePtr xnode;
  xlinkType xlt;

  xnode = rxml_get_xnode(self);
  xlt = xlinkIsLink(xnode->doc, xnode);

  switch (xlt)
  {
  case XLINK_TYPE_NONE:
    return (Qnil);
  case XLINK_TYPE_SIMPLE:
    return (rxml_new_cstr("simple", NULL));
  case XLINK_TYPE_EXTENDED:
    return (rxml_new_cstr("extended", NULL));
  case XLINK_TYPE_EXTENDED_SET:
    return (rxml_new_cstr("extended_set", NULL));
  default:
    rb_fatal("Unknowng xlink type, %d", xlt);
  }
}
コード例 #30
0
ファイル: rbcoremidi.c プロジェクト: jimm/rbcoremidi
static VALUE t_create_client(VALUE self, VALUE client_name)
{    
    VALUE midiclient_instance = rb_class_new_instance(0, 0, cMIDIClient);
    if( midiclient_instance == Qnil )
    {
        free_objects();
        rb_fatal("Couldn't create an instance of MIDIClient!");
    }
    
    MIDIClientRef midi_client;
    
    CFStringRef client_str = CFStringCreateWithCString(kCFAllocatorDefault, RSTRING(client_name)->as.heap.ptr, kCFStringEncodingASCII);
    MIDIClientCreate(client_str, NULL, NULL, &midi_client);
    CFRelease(client_str);
    
    RbMIDIClient* client_struct;
    Data_Get_Struct(midiclient_instance, RbMIDIClient, client_struct);
    
    client_struct->client = midi_client;
    
    return midiclient_instance;
}