Sha256: 1b8b088145db78324dbcb49b2ccb4a3544441e37910e7d9da31707433e734d52

Contents?: true

Size: 1.23 KB

Versions: 148

Compression:

Stored size: 1.23 KB

Contents

#include <xml_io.h>

static ID id_read, id_write;

VALUE read_check(VALUE *args) {
  return rb_funcall(args[0], id_read, 1, args[1]);
}

VALUE read_failed(void) {
	return Qundef;
}

int io_read_callback(void * ctx, char * buffer, int len) {
  VALUE string, args[2];
  size_t str_len, safe_len;

  args[0] = (VALUE)ctx;
  args[1] = INT2NUM(len);

  string = rb_rescue(read_check, (VALUE)args, read_failed, 0);

  if (NIL_P(string)) return 0;
  if (string == Qundef) return -1;
  if (TYPE(string) != T_STRING) return -1;

  str_len = (size_t)RSTRING_LEN(string);
  safe_len = str_len > (size_t)len ? (size_t)len : str_len;
  memcpy(buffer, StringValuePtr(string), safe_len);

  return (int)safe_len;
}

VALUE write_check(VALUE *args) {
  return rb_funcall(args[0], id_write, 1, args[1]);
}

VALUE write_failed(void) {
	return Qundef;
}

int io_write_callback(void * ctx, char * buffer, int len) {
  VALUE args[2], size;

  args[0] = (VALUE)ctx;
  args[1] = rb_str_new(buffer, (long)len);

  size = rb_rescue(write_check, (VALUE)args, write_failed, 0);

  if (size == Qundef) return -1;

  return NUM2INT(size);
}

int io_close_callback(void * ctx) {
  return 0;
}

void init_nokogiri_io() {
  id_read = rb_intern("read");
  id_write = rb_intern("write");
}

Version data entries

148 entries across 126 versions & 12 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
video_chat_get-0.1.9 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
video_chat_get-0.1.6 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io 2.c
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io 3.c
video_chat_get-0.1.4 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/nokogiri-1.10.10/ext/nokogiri/xml_io.c
video_chat_get-0.1.3 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
video_chat_get-0.1.2 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
video_chat_get-0.1.1 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
video_chat_get-0.1.0 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.c
nokogiri-1.10.10 ext/nokogiri/xml_io.c