Beispiel #1
0
/*
 * Sets the rotate threshold size that is used by the default query
 * logger. If you're using custom query logger by {.register}, the
 * rotate threshold size isn't used. Because it is for the default
 * query logger.
 *
 * If you specify `0` as size, log rotation by the default query
 * logger is disabled.
 *
 * The default rotate threshold size is 0. It means that log rotation
 * is disabled by default.
 *
 * @example Changes the rotate threshold size for the default query logger
 *   Groonga::QueryLogger.rotate_threshold_size = 1 * 1024 * 1024 # 1MiB
 *
 * @example Disables log ration by the default query logger
 *   Groonga::QueryLogger.rotate_threshold_size = 0
 *
 * @overload rotate_threshold_size=(size)
 *   @param size [Integer] The log path for the default query logger.
 *     If nil is specified, log rotate by the default query logger is
 *     disabled.
 *   @return void
 *
 * @since 5.0.2
 */
static VALUE
rb_grn_query_logger_s_set_rotate_threshold_size (VALUE klass, VALUE rb_size)
{
    grn_default_query_logger_set_rotate_threshold_size(NUM2OFFT(rb_size));

    return Qnil;
}
Beispiel #2
0
static VALUE rb_smbfile_seek(int argc, VALUE *argv, VALUE self)
{
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
  RB_SMBFILE_DATA_CLOSED(data);

  VALUE whence_num;
  rb_scan_args(argc, argv, "11", NULL, &whence_num);
  off_t offset = NUM2OFFT(argv[0]);
  int whence = NIL_P(whence_num) ? SEEK_SET : NUM2INT(whence_num);

  switch (whence) {
  case SEEK_SET:
    data->pos = offset;
    break;
  case SEEK_CUR:
    if (offset < 0 && offset < -data->pos) {
      errno = EINVAL;
      rb_sys_fail(data->url);
    }
    data->pos += offset;
    break;
  case SEEK_END:
    /* FIXME */
    rb_raise(rb_eNotImpError, "SEEK_END");
    break;
  default:
    errno = EINVAL;
    rb_sys_fail(data->url);
    break;
  }

  rb_smbfile_seek_by_data(data);

  return self;
}
Beispiel #3
0
static sf_count_t ra_vir_write(const void *ptr, sf_count_t count, void *user_data) {
    VALUE io = (VALUE)user_data;
    if(count <= 0) return 0;

    // It would be nice if we could create a fake string with ptr as the source
    VALUE str = rb_str_new(ptr, count);
    VALUE wrote = rb_funcall(io, id_write, 1, str);
    return NUM2OFFT(wrote);
}
Beispiel #4
0
/*
 * call-seq:
 *   snd.seek(frames, whence) => 0
 *
 * Seeks to a given offset <i>anInteger</i> in the sound according to the value
 * of <i>whence</i>:
 *
 *   IO::SEEK_CUR  | Seeks to _frames_ plus current position
 *   --------------+----------------------------------------------------
 *   IO::SEEK_END  | Seeks to _frames_ plus end of stream (you probably
 *                 | want a negative value for _frames_)
 *   --------------+----------------------------------------------------
 *   IO::SEEK_SET  | Seeks to the absolute location given by _frames_
 */
static VALUE ra_sound_seek(VALUE self, VALUE frames, VALUE whence) {
    RA_SOUND *snd;
    Data_Get_Struct(self, RA_SOUND, snd);
    if(snd->closed) rb_raise(eRubyAudioError, "closed sound");

    if(sf_seek(snd->snd, (sf_count_t)NUM2OFFT(frames), FIX2INT(whence)) == -1) {
        rb_raise(eRubyAudioError, "invalid seek");
    }

    return INT2FIX(0);
}
Beispiel #5
0
/*
 * IO.pread_ptr(fd, length, offset)
 *
 * This is identical to IO.pread, except that it returns the pointer address
 * of the string, instead of the actual buffer.
 *--
 * This was added because, in some cases, the IO.pread buffer might return
 * an empty string. In such situations we are unable to get the actual pointer
 * address with pure Ruby.
 */
static VALUE s_io_pread_ptr(VALUE klass, VALUE v_fd, VALUE v_nbyte, VALUE v_offset){
  int fd = NUM2INT(v_fd);
  size_t nbyte = NUM2ULONG(v_nbyte);
  off_t offset = NUM2OFFT(v_offset);
  uintptr_t* vector = malloc(nbyte + 1);

  if(pread(fd, vector, nbyte, offset) == -1){
    free(vector);
    rb_sys_fail("pread");
  }

  return ULL2NUM(vector[0]);
}
Beispiel #6
0
/*
 *  call-seq:
 *     dir.seek( integer ) => dir
 *
 *  Seeks to a particular location in <em>dir</em>. <i>integer</i>
 *  must be a value returned by <code>Dir#tell</code>.
 *
 *     d = Dir.new("testdir")   #=> #<Dir:0x401b3c40>
 *     d.read                   #=> "."
 *     i = d.tell               #=> 12
 *     d.read                   #=> ".."
 *     d.seek(i)                #=> #<Dir:0x401b3c40>
 *     d.read                   #=> ".."
 */
static VALUE
dir_seek(VALUE dir, VALUE pos)
{
    struct dir_data *dirp;
    off_t p = NUM2OFFT(pos);

    GetDIR(dir, dirp);
#ifdef HAVE_SEEKDIR
    seekdir(dirp->dir, p);
    return dir;
#else
    rb_notimplement();
#endif
}
Beispiel #7
0
/*
 * IO.pwrite(fd, buf, offset)
 *
 * This method writes the +buf+, starting at +offset+, to the given +fd+,
 * which must be opened with write permissions.
 *
 * This is similar to a seek & write in standard Ruby but the difference,
 * beyond being a singleton method, is that the file pointer is never moved.
 *
 * Returns the number of bytes written.
 */
static VALUE s_io_pwrite(VALUE klass, VALUE fd, VALUE buf, VALUE offset){
   ssize_t result;
   struct pwrite_args args;

   args.fd = NUM2INT(fd);
   args.buf = RSTRING_PTR(buf);
   args.nbyte = RSTRING_LEN(buf);
   args.offset = NUM2OFFT(offset);

#ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
   result = (ssize_t)rb_thread_call_without_gvl((void*)nogvl_pwrite, &args, RUBY_UBF_IO, 0);
#else
   result = (ssize_t)rb_thread_blocking_region(nogvl_pwrite, &args, RUBY_UBF_IO, 0);
#endif

   if(result == -1)
      rb_sys_fail("pwrite");

   return ULL2NUM(result);
}
Beispiel #8
0
/*
 * call-seq:
 *   snd.read(buf, frames) => integer
 *
 * Tries to read the given number of frames into the buffer and returns the
 * number of frames actually read.
 */
static VALUE ra_sound_read(VALUE self, VALUE buf, VALUE frames) {
    RA_SOUND *snd;
    Data_Get_Struct(self, RA_SOUND, snd);
    if(snd->closed) rb_raise(eRubyAudioError, "closed sound");

    // Get buffer struct
    RA_BUFFER *b;
    Data_Get_Struct(buf, RA_BUFFER, b);

    // Double-check frame count against buffer size
    sf_count_t f = (sf_count_t)NUM2OFFT(frames);
    if(f < 0 || f > b->size) {
        rb_raise(eRubyAudioError, "frame count invalid");
    }

    // Shortcut for 0 frame reads
    if(f == 0) {
        b->real_size = 0;
        return INT2FIX(b->real_size);;
    }

    // Read based on type
    switch(b->type) {
        case RA_BUFFER_TYPE_SHORT:
            ra_sound_read_short(snd, b, f);
            break;
        case RA_BUFFER_TYPE_INT:
            ra_sound_read_int(snd, b, f);
            break;
        case RA_BUFFER_TYPE_FLOAT:
            ra_sound_read_float(snd, b, f);
            break;
        case RA_BUFFER_TYPE_DOUBLE:
            ra_sound_read_double(snd, b, f);
            break;
    }

    // Return read
    return INT2FIX(b->real_size);
}
Beispiel #9
0
/*
 * IO.pread(fd, length, offset)
 *
 * This is similar to the IO.read method, except that it reads from a given
 * position in the file without changing the file pointer. And unlike IO.read,
 * the +fd+, +length+ and +offset+ arguments are all mandatory.
 */
static VALUE s_io_pread(VALUE klass, VALUE fd, VALUE nbyte, VALUE offset){
   struct pread_args args;
   VALUE str;
   ssize_t nread;

   args.fd = NUM2INT(fd);
   args.nbyte = NUM2ULONG(nbyte);
   args.offset = NUM2OFFT(offset);
   str = rb_str_new(NULL, args.nbyte);
   args.buf = RSTRING_PTR(str);

#ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
   nread = (ssize_t)rb_thread_call_without_gvl((void*)nogvl_pread, &args, RUBY_UBF_IO, 0);
#else
   nread = (ssize_t)rb_thread_blocking_region(nogvl_pread, &args, RUBY_UBF_IO, 0);
#endif

   if (nread == -1)
      rb_sys_fail("pread");
   if ((size_t)nread != args.nbyte)
      rb_str_set_len(str, nread);

   return str;
}
Beispiel #10
0
static sf_count_t ra_vir_seek(sf_count_t offset, int whence, void *user_data) {
    VALUE io = (VALUE)user_data;
    rb_funcall(io, id_seek, 2, OFFT2NUM(offset), INT2FIX(whence));
    return NUM2OFFT(rb_funcall(io, id_tell, 0));
}
Beispiel #11
0
static sf_count_t ra_vir_size(void *user_data) {
    VALUE io = (VALUE)user_data;
    return NUM2OFFT(rb_funcall(io, id_size, 0));
}