Пример #1
0
void* unwrapTypedPtr(const VALUE &obj, rb_data_type_t* rbdata)
{
	if(NIL_P(obj))
		return NULL;

	if(!rbdata) {
		rb_raise(rb_eTypeError,"%" PRIsVALUE " unknown datatype", RB_OBJ_CLASSNAME(obj));
		return NULL;
	}

	const rb_data_type_t* rbdata_obj = RTYPEDDATA_TYPE(obj);

	if(rbdata_obj != rbdata) {
		if(!rb_typeddata_inherited_p(rbdata_obj, rbdata)) {
			rb_warn("%s is not a %s but inherit from %s",
				rbdata_obj->wrap_struct_name, rbdata->wrap_struct_name,
				rbdata_obj->parent->wrap_struct_name
			);
		}
	}

	void* data = Check_TypedStruct(obj, rbdata);
	if(!data) {
		rb_raise(
			rb_eRuntimeError, "destroyed object of %" PRIsVALUE, RB_OBJ_CLASSNAME(obj)
		);
		return NULL;
	}
	return data;

}
Пример #2
0
static VALUE
ossl_engine_inspect(VALUE self)
{
    ENGINE *e;

    GetEngine(self, e);
    return rb_sprintf("#<%"PRIsVALUE" id=\"%s\" name=\"%s\">",
		      RB_OBJ_CLASSNAME(self), ENGINE_get_id(e), ENGINE_get_name(e));
}
Пример #3
0
bool check_class(VALUE obj, VALUE klass)
{
	bool result = rb_obj_is_kind_of(obj, klass);
	if(!result)
		rb_raise(rb_eTypeError,
			"Expected %" PRIsVALUE " got %" PRIsVALUE "!",
			RB_CLASSNAME(klass),
			RB_OBJ_CLASSNAME(obj)
		);
	return result;
}
Пример #4
0
/* call-seq:
 *   log(priority, format_string, *format_args)
 *
 * Log a message with the specified priority. Example:
 *
 *   Syslog.log(Syslog::LOG_CRIT, "Out of disk space")
 *   Syslog.log(Syslog::LOG_CRIT, "User %s logged in", ENV['USER'])
 *
 * The priority levels, in descending order, are:
 *
 * LOG_EMERG::   System is unusable
 * LOG_ALERT::   Action needs to be taken immediately
 * LOG_CRIT::    A critical condition has occurred
 * LOG_ERR::     An error occurred
 * LOG_WARNING:: Warning of a possible problem
 * LOG_NOTICE::  A normal but significant condition occurred
 * LOG_INFO::    Informational message
 * LOG_DEBUG::   Debugging information
 *
 * Each priority level also has a shortcut method that logs with it's named priority.
 * As an example, the two following statements would produce the same result:
 *
 *   Syslog.log(Syslog::LOG_ALERT, "Out of memory")
 *   Syslog.alert("Out of memory")
 *
 * Format strings are as for printf/sprintf, except that in addition %m is
 * replaced with the error message string that would be returned by
 * strerror(errno).
 *
 */
static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self)
{
    VALUE pri;

    if (argc < 2) {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
    }

    argc--;
    pri = *argv++;

    if (!FIXNUM_P(pri)) {
	rb_raise(rb_eTypeError, "type mismatch: %"PRIsVALUE" given", RB_OBJ_CLASSNAME(pri));
    }

    syslog_write(FIX2INT(pri), argc, argv);

    return self;
}