Sha256: 7b261b3396ed0e50655880089c85fb063a069856ed75d1a89f8ed89bc056f3a2

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

/* $Id$ */

#include "ruby_libxml.h"

VALUE cXMLState;
VALUE LIBXML_STATE = Qnil;

static int dummy = 0;

void
ruby_xml_state_free(int dummy) {
  xmlCleanupParser();
  LIBXML_STATE = Qnil;
}

VALUE
ruby_xml_state_alloc(VALUE klass) {
  #ifdef DEBUG
  fprintf(stderr, "Allocating state");
  #endif
  
  xmlInitParser();
  
  return Data_Wrap_Struct(cXMLState,
			  NULL, ruby_xml_state_free,
			  &dummy);
}

// Rdoc needs to know 
#ifdef RDOC_NEVER_DEFINED
  mLibXML = rb_define_module("LibXML");
  mXML = rb_define_module_under(mLibXML, "XML");
#endif

void
ruby_init_state(void) {	
  VALUE rb_mSingleton;
  cXMLState = rb_define_class_under(mXML, "State", rb_cObject);
  
  /* Mixin singleton so only one xml state object can be created. */
  rb_require("singleton");
  rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
  rb_include_module(cXMLState, rb_mSingleton);

  rb_define_alloc_func(cXMLState, ruby_xml_state_alloc);

  /* Create one instance of the state object that is used
     to initalize and cleanup libxml. Then register it with
     the garbage collector so its not freed until the process
     exists.*/
  LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
  rb_global_variable(&LIBXML_STATE);  
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
libxml-ruby-0.8.2-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.8.2 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.1-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.8.3 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.0 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.0-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.1 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.2 ext/libxml/ruby_xml_state.c
libxml-ruby-0.9.2-x86-mswin32-60 ext/libxml/ruby_xml_state.c
libxml-ruby-0.8.3-x86-mswin32-60 ext/libxml/ruby_xml_state.c