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
nokogiri-1.8.4-java ext/nokogiri/xml_io.c
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.8.3/ext/nokogiri/xml_io.c
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/nokogiri-1.8.3/ext/nokogiri/xml_io.c
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.3/ext/nokogiri/xml_io.c
nokogiri-1.8.3 ext/nokogiri/xml_io.c
nokogiri-1.8.3-x86-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.8.3-x64-mingw32 ext/nokogiri/xml_io.c
nokogiri-1.8.3-java ext/nokogiri/xml_io.c