/* Generated from "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod" by precompile.pike running Pike v8.0 release 1089
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 6

#undef PRECOMPILE_SUB_PIKEVARS
#define PRECOMPILE_SUB_PIKEVARS 1

#undef PRECOMPILE_DYNAMIC_TYPES
#define PRECOMPILE_DYNAMIC_TYPES 1



#undef cmod___CMOD__
#define cmod___CMOD__ 1
#line 1 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#line 3003 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"







#line 3010 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"
#line 1 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#include "global.h"
#include "interpret.h"
#include "svalue.h"
#include "stralloc.h"
#include "array.h"
#include "pike_macros.h"
#include "program.h"
#include "stralloc.h"
#include "object.h"
#include "pike_types.h"
#include "threads.h"
#include "dynamic_buffer.h"
#include "module_support.h"
#include "builtin_functions.h"

#ifdef HAVE_VCDIFF

#include "vcdiff_wrapper.h"



#ifndef PIKE_UNUSED_ATTRIBUTE
#define PIKE_UNUSED_ATTRIBUTE
#endif
#define CMOD_MAP_PROGRAM_IDS_DEFINED 1
static int ___cmod_map_program_ids(int id) PIKE_UNUSED_ATTRIBUTE;
#ifndef TYPEOF
/* Compat with older Pikes. */
#define TYPEOF(SVAL)	((SVAL).type)
#define SUBTYPEOF(SVAL)	((SVAL).subtype)
#define SET_SVAL_TYPE(SVAL, TYPE)	(TYPEOF(SVAL) = TYPE)
#define SET_SVAL_SUBTYPE(SVAL, TYPE)	(SUBTYPEOF(SVAL) = TYPE)
#define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {	\
    /* Set the type afterwards to avoid a clobbered	\
     * svalue in case EXPR throws. */			\
    (SVAL).u.FIELD = (EXPR);				\
    SET_SVAL_TYPE((SVAL), (TYPE));			\
    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));		\
  } while(0)
#endif /* !TYPEOF */
#ifndef PIKE_UNUSED
/* Compat with Pike 7.8 and earlier. */
/* NB: Not strictly correct; PIKE_UNUSED was added the
 *     day after set_program_id_to_id(), but good enough.
 */
#ifndef UNUSED
#define UNUSED(X)	X
#endif
#ifndef set_program_id_to_id
/* NB: Recent Pike 7.8 has a #define that conflicts with
 *     the following declaration.
 */
static void set_program_id_to_id(void*UNUSED(id)){}
#endif
#else /* */
PMOD_EXPORT void set_program_id_to_id( int (*to)(int) );
#endif /* !PIKE_UNUSED */


#ifndef DEFAULT_CMOD_STORAGE
#define CMOD_COND_USED
#define DEFAULT_CMOD_STORAGE static
#endif
#ifndef CMOD_COND_USED
# define VCDiff_Encoder_program_fun_num_used 1
#else
#undef VCDiff_Encoder_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Encoder_create_fun_num_used 1
#else
#undef f_VCDiff_Encoder_create_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Encoder_encode_fun_num_used 1
#else
#undef f_VCDiff_Encoder_encode_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Decoder_create_fun_num_used 1
#else
#undef f_VCDiff_Decoder_create_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Decoder_decode_fun_num_used 1
#else
#undef f_VCDiff_Decoder_decode_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define VCDiff_Decoder_program_fun_num_used 1
#else
#undef VCDiff_Decoder_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Encoder_encode_chunk_fun_num_used 1
#else
#undef f_VCDiff_Encoder_encode_chunk_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_VCDiff_Decoder_decode_chunk_fun_num_used 1
#else
#undef f_VCDiff_Decoder_decode_chunk_fun_num_used
#endif
#line 22 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
/* NB: Usually pulled in from crtbeginS.o, but we compile with -nostartfiles...
 *
 *     cf http://wiki.osdev.org/C%2B%2B#GCC
 *     and http://www.linuxquestions.org/questions/programming-9/fyi-shared-libs-and-iostream-c-331113/#post1681605
 *
 *     It is needed due to vcdiff_wrapper.cc pulling in iostream.
 */
void *__dso_handle = NULL;

/*! @module VCDiff
 *!
 *! Pike glue for the open-vcdiff differential compression library. 
 *! http://code.google.com/p/open-vcdiff/
 *!
 *! Encoding and decoding relies on a common string that the differences are
 *! computed against - this string is called the dictionary.
 *!
 *! Basic usage:
 *! @code
 *!   string dict = "abcdef";
 *!   VCDiff.Encoder encoder = VCDiff.Encoder (dict);
 *!   string encoded = encoder->encode ("abcdefghijklmnopqrstuvwxyz");
 *!   VCDiff.Decoder decoder = VCDiff.Decoder (dict);
 *!   string decoded = decoder->decode (encoded);
 *! @endcode
 */


#undef class_VCDiff_Encoder_defined
#define class_VCDiff_Encoder_defined
DEFAULT_CMOD_STORAGE struct program *VCDiff_Encoder_program=NULL;

#ifdef VCDiff_Encoder_program_fun_num_used
DEFAULT_CMOD_STORAGE int VCDiff_Encoder_program_fun_num=-1;
#endif /* VCDiff_Encoder_program_fun_num_used */

#undef var_dict_VCDiff_Encoder_defined
#define var_dict_VCDiff_Encoder_defined

#undef var_vcencoder_VCDiff_Encoder_defined
#define var_vcencoder_VCDiff_Encoder_defined

#undef var_test_VCDiff_Encoder_defined
#define var_test_VCDiff_Encoder_defined

#undef var_encoder_state_VCDiff_Encoder_defined
#define var_encoder_state_VCDiff_Encoder_defined

#undef THIS
#define THIS ((struct VCDiff_Encoder_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_VCDIFF_ENCODER
#define THIS_VCDIFF_ENCODER ((struct VCDiff_Encoder_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_VCDIFF_ENCODER
#define OBJ2_VCDIFF_ENCODER(o) ((struct VCDiff_Encoder_struct *)(o->storage+VCDiff_Encoder_storage_offset))

#undef GET_VCDIFF_ENCODER_STORAGE
#define GET_VCDIFF_ENCODER_STORAGE(o) ((struct VCDiff_Encoder_struct *)(o->storage+VCDiff_Encoder_storage_offset)
static ptrdiff_t VCDiff_Encoder_storage_offset;
struct VCDiff_Encoder_struct {

#ifdef var_dict_VCDiff_Encoder_defined
#line 50 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
void *dict;
#endif /* var_dict_VCDiff_Encoder_defined */

#ifdef var_vcencoder_VCDiff_Encoder_defined
#line 51 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
void *vcencoder;
#endif /* var_vcencoder_VCDiff_Encoder_defined */

#ifdef var_test_VCDiff_Encoder_defined
#line 52 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
int test;
#endif /* var_test_VCDiff_Encoder_defined */

#ifdef var_encoder_state_VCDiff_Encoder_defined
#line 53 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
int encoder_state;
#endif /* var_encoder_state_VCDiff_Encoder_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct VCDiff_Encoder_struct *VCDiff_Encoder_gdb_dummy_ptr;
#endif
#define f_VCDiff_Encoder_create_defined

#ifdef f_VCDiff_Encoder_create_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Encoder_create_fun_num = 0;

#endif /* f_VCDiff_Encoder_create_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Encoder_create(INT32 args) {
#line 55 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * dictionary;
#line 55 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args != 1) wrong_number_of_args_error("create",args,1);
#line 55 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 55 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(dictionary=Pike_sp[0-1].u.string);
{
void *_dict;
void *_vcencoder;
int dict_len;
char *dict_str;

if (dictionary->size_shift)
Pike_error("Wide strings not supported.\n");

if (THIS->dict != NULL)
vcdiff_free_dictionary (THIS->dict);
if (THIS->vcencoder != NULL)
vcdiff_free_encoder (THIS->vcencoder);

THREADS_ALLOW();
_dict = vcdiff_init_dictionary (dictionary->str, dictionary->len);
THREADS_DISALLOW();

if (_dict != NULL) {
_vcencoder = vcdiff_init_encoder (_dict);
THIS->dict = _dict;
THIS->vcencoder = _vcencoder;
THIS->encoder_state = 1;
} else {
Pike_error ("Initializing dictionary failed.\n");
}
pop_n_elems (args);
}

}
#define f_VCDiff_Encoder_encode_defined

#ifdef f_VCDiff_Encoder_encode_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Encoder_encode_fun_num = 0;

#endif /* f_VCDiff_Encoder_encode_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Encoder_encode(INT32 args) {
#line 85 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * data;
#line 85 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args != 1) wrong_number_of_args_error("encode",args,1);
#line 85 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("encode",1,"string");
#line 85 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
{
push_int (1);
apply (Pike_fp->current_object, "encode_chunk", 2);
}

}
#define f_VCDiff_Encoder_encode_chunk_defined

#ifdef f_VCDiff_Encoder_encode_chunk_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Encoder_encode_chunk_fun_num = 0;

#endif /* f_VCDiff_Encoder_encode_chunk_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Encoder_encode_chunk(INT32 args) {
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * data;
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct svalue * flush;
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args > 2) wrong_number_of_args_error("encode_chunk",args,2);
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if (args > 0 &&
    (TYPEOF(Pike_sp[0-args]) != PIKE_T_INT ||
     Pike_sp[0-args].u.integer)) {
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("encode_chunk",1,"void|string");
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(data=Pike_sp[0-args].u.string);
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
} else data = NULL;
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if ((args > 1) &&
    ((TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[1-args]) != NUMBER_UNDEFINED))) {
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("encode_chunk",2,"void|int(0..1)");
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
flush=Pike_sp+1-args; dmalloc_touch_svalue(Pike_sp+1-args);
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
} else flush = NULL;
{
char *in_buf = NULL;
int in_buf_len = 0;

char *out_buf = NULL;
int out_buf_len = 0;

char *trailer = NULL;
int trailer_len = 0;

void *vcenc = THIS->vcencoder;
int *enc_state_ptr = &THIS->encoder_state;

struct pike_string *s;
struct string_builder sb;

if (THIS->encoder_state == 0) {
Pike_error ("Calling encode_chunk in un-initialized object.\n");
}

if (data) {
if (data->size_shift)
Pike_error("Wide strings not supported.\n");
in_buf_len = data->len;
in_buf = data->str;
} else if (THIS->encoder_state == 3) {
do { struct pike_string * ret_=(make_shared_binary_string ("", 0)); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 119 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
}

THREADS_ALLOW();
vcdiff_encode_chunk (vcenc, in_buf, in_buf_len,
&out_buf, &out_buf_len, enc_state_ptr);
THREADS_DISALLOW();

if (flush) {
/* Flush internal buffers. */
vcdiff_encode_chunk (vcenc, NULL, 0, 
&trailer, &trailer_len, enc_state_ptr);
}

init_string_builder (&sb, 0);
string_builder_binary_strcat (&sb, out_buf, out_buf_len);
free (out_buf);

if (trailer) {
string_builder_binary_strcat (&sb, trailer, trailer_len);
free (trailer);
}

s = finish_string_builder (&sb);
do { struct pike_string * ret_=(s); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 143 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
}

}

#undef internal_init_VCDiff_Encoder_defined
#define internal_init_VCDiff_Encoder_defined

#undef VCDiff_Encoder_event_handler_defined
#define VCDiff_Encoder_event_handler_defined
static void init_VCDiff_Encoder_struct(void)
#line 145 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
{
THIS->dict = NULL;
THIS->vcencoder = NULL;
THIS->encoder_state = 0;
}


#undef VCDiff_Encoder_gc_live_obj
#define VCDiff_Encoder_gc_live_obj

#undef internal_exit_VCDiff_Encoder_defined
#define internal_exit_VCDiff_Encoder_defined

#undef VCDiff_Encoder_event_handler_defined
#define VCDiff_Encoder_event_handler_defined
static void exit_VCDiff_Encoder_struct(void)
#line 151 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
{
if (THIS->dict != NULL)
vcdiff_free_dictionary (THIS->dict);
if (THIS->vcencoder != NULL)
vcdiff_free_encoder (THIS->vcencoder);
}

#ifdef VCDiff_Encoder_event_handler_defined
static void VCDiff_Encoder_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_VCDiff_Encoder_defined
  case PROG_EVENT_INIT: init_VCDiff_Encoder_struct(); break;

#endif /* internal_init_VCDiff_Encoder_defined */

#ifdef internal_exit_VCDiff_Encoder_defined
  case PROG_EVENT_EXIT: exit_VCDiff_Encoder_struct(); break;

#endif /* internal_exit_VCDiff_Encoder_defined */
  default: break; 
  }
}

#endif /* VCDiff_Encoder_event_handler_defined */

#undef class_VCDiff_Decoder_defined
#define class_VCDiff_Decoder_defined
DEFAULT_CMOD_STORAGE struct program *VCDiff_Decoder_program=NULL;

#ifdef VCDiff_Decoder_program_fun_num_used
DEFAULT_CMOD_STORAGE int VCDiff_Decoder_program_fun_num=-1;
#endif /* VCDiff_Decoder_program_fun_num_used */

#undef var_dictionary_VCDiff_Decoder_defined
#define var_dictionary_VCDiff_Decoder_defined

#undef var_vcdecoder_VCDiff_Decoder_defined
#define var_vcdecoder_VCDiff_Decoder_defined

#undef var_decoder_state_VCDiff_Decoder_defined
#define var_decoder_state_VCDiff_Decoder_defined

#undef var_dict_str_VCDiff_Decoder_defined
#define var_dict_str_VCDiff_Decoder_defined

#undef var_dict_len_VCDiff_Decoder_defined
#define var_dict_len_VCDiff_Decoder_defined

#undef THIS
#define THIS ((struct VCDiff_Decoder_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_VCDIFF_DECODER
#define THIS_VCDIFF_DECODER ((struct VCDiff_Decoder_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_VCDIFF_DECODER
#define OBJ2_VCDIFF_DECODER(o) ((struct VCDiff_Decoder_struct *)(o->storage+VCDiff_Decoder_storage_offset))

#undef GET_VCDIFF_DECODER_STORAGE
#define GET_VCDIFF_DECODER_STORAGE(o) ((struct VCDiff_Decoder_struct *)(o->storage+VCDiff_Decoder_storage_offset)
static ptrdiff_t VCDiff_Decoder_storage_offset;
struct VCDiff_Decoder_struct {

#ifdef var_dictionary_VCDiff_Decoder_defined
  struct pike_string * dictionary;

#endif /* var_dictionary_VCDiff_Decoder_defined */

#ifdef var_vcdecoder_VCDiff_Decoder_defined
#line 161 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
void *vcdecoder;
#endif /* var_vcdecoder_VCDiff_Decoder_defined */

#ifdef var_decoder_state_VCDiff_Decoder_defined
#line 162 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
int decoder_state;
#endif /* var_decoder_state_VCDiff_Decoder_defined */

#ifdef var_dict_str_VCDiff_Decoder_defined
#line 163 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
char *dict_str;
#endif /* var_dict_str_VCDiff_Decoder_defined */

#ifdef var_dict_len_VCDiff_Decoder_defined
#line 164 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
int dict_len;
#endif /* var_dict_len_VCDiff_Decoder_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct VCDiff_Decoder_struct *VCDiff_Decoder_gdb_dummy_ptr;
#endif
#define f_VCDiff_Decoder_create_defined

#ifdef f_VCDiff_Decoder_create_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Decoder_create_fun_num = 0;

#endif /* f_VCDiff_Decoder_create_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Decoder_create(INT32 args) {
#line 166 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * dictionary;
#line 166 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args != 1) wrong_number_of_args_error("create",args,1);
#line 166 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 166 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(dictionary=Pike_sp[0-1].u.string);
{
if (dictionary->size_shift)
Pike_error("Wide strings not supported.\n");

if (THIS->vcdecoder != NULL)
vcdiff_free_decoder (THIS->vcdecoder);

THIS->dict_len = dictionary->len;
THIS->dict_str = (char *)malloc (dictionary->len);
memcpy (THIS->dict_str, dictionary->str, dictionary->len);

THIS->vcdecoder = vcdiff_init_decoder (THIS->dict_str, THIS->dict_len);

THIS->decoder_state = 2;
pop_n_elems (args);
}

}
#define f_VCDiff_Decoder_decode_defined

#ifdef f_VCDiff_Decoder_decode_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Decoder_decode_fun_num = 0;

#endif /* f_VCDiff_Decoder_decode_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Decoder_decode(INT32 args) {
#line 184 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * data;
#line 184 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args != 1) wrong_number_of_args_error("decode",args,1);
#line 184 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("decode",1,"string");
#line 184 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
{
push_int (1);
apply (Pike_fp->current_object, "decode_chunk", 2);
}

}
#define f_VCDiff_Decoder_decode_chunk_defined

#ifdef f_VCDiff_Decoder_decode_chunk_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_VCDiff_Decoder_decode_chunk_fun_num = 0;

#endif /* f_VCDiff_Decoder_decode_chunk_fun_num_used */
DEFAULT_CMOD_STORAGE void f_VCDiff_Decoder_decode_chunk(INT32 args) {
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct pike_string * data;
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
struct svalue * flush;
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(args > 2) wrong_number_of_args_error("decode_chunk",args,2);
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if (args > 0 &&
    (TYPEOF(Pike_sp[0-args]) != PIKE_T_INT ||
     Pike_sp[0-args].u.integer)) {
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("decode_chunk",1,"void|string");
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
debug_malloc_pass(data=Pike_sp[0-args].u.string);
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
} else data = NULL;
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if ((args > 1) &&
    ((TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[1-args]) != NUMBER_UNDEFINED))) {
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("decode_chunk",2,"void|int(0..1)");
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
flush=Pike_sp+1-args; dmalloc_touch_svalue(Pike_sp+1-args);
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
} else flush = NULL;
{
char *in_buf = NULL;
int in_buf_len = 0;

char *out_buf = NULL;
int out_buf_len = 0;

char *trailer = NULL;
int trailer_len = 0;

void *vcdec = THIS->vcdecoder;
int *dec_state_ptr = &THIS->decoder_state;

struct pike_string *s;
struct string_builder sb;
int res = 0;

if (THIS->decoder_state == 0) {
Pike_error ("Calling decode_chunk in un-initialized object.\n");
}

if (data) {
if (data->size_shift)
Pike_error("Wide strings not supported.\n");
in_buf_len = data->len;
in_buf = data->str;
} else if (THIS->decoder_state == 3) {
do { struct pike_string * ret_=(make_shared_binary_string ("", 0)); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 219 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
}

THREADS_ALLOW();
res = vcdiff_decode_chunk (vcdec, in_buf, in_buf_len,
&out_buf, &out_buf_len, dec_state_ptr);
THREADS_DISALLOW();
if (!res)
Pike_error ("vcdiff_decode_chunk failed\n");

if (flush) {
/* Flush internal buffers. */
vcdiff_decode_chunk (vcdec, NULL, 0, 
&trailer, &trailer_len, dec_state_ptr);
}

init_string_builder (&sb, 0);
string_builder_binary_strcat (&sb, out_buf, out_buf_len);
free (out_buf);

if (trailer) {
string_builder_binary_strcat (&sb, trailer, trailer_len);
free (trailer);
}

s = finish_string_builder (&sb);

do { struct pike_string * ret_=(s); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 246 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
}

}

#undef internal_init_VCDiff_Decoder_defined
#define internal_init_VCDiff_Decoder_defined

#undef VCDiff_Decoder_event_handler_defined
#define VCDiff_Decoder_event_handler_defined
static void init_VCDiff_Decoder_struct(void)
#line 248 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
{
THIS->vcdecoder = NULL;
THIS->decoder_state = 0;
}


#undef VCDiff_Decoder_gc_live_obj
#define VCDiff_Decoder_gc_live_obj

#undef internal_exit_VCDiff_Decoder_defined
#define internal_exit_VCDiff_Decoder_defined

#undef VCDiff_Decoder_event_handler_defined
#define VCDiff_Decoder_event_handler_defined
static void exit_VCDiff_Decoder_struct(void)
#line 253 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
{
if (THIS->vcdecoder != NULL)
vcdiff_free_decoder (THIS->vcdecoder);
if (THIS->dict_str != NULL) 
free (THIS->dict_str);
}

#ifdef VCDiff_Decoder_event_handler_defined
static void VCDiff_Decoder_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_VCDiff_Decoder_defined
  case PROG_EVENT_INIT: init_VCDiff_Decoder_struct(); break;

#endif /* internal_init_VCDiff_Decoder_defined */

#ifdef internal_exit_VCDiff_Decoder_defined
  case PROG_EVENT_EXIT: exit_VCDiff_Decoder_struct(); break;

#endif /* internal_exit_VCDiff_Decoder_defined */
  default: break; 
  }
}

#endif /* VCDiff_Decoder_event_handler_defined */
/*! @endmodule */

#line 263 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#endif /* HAVE_VCDIFF */

PIKE_MODULE_INIT
{
#ifdef HAVE_VCDIFF
 
#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( ___cmod_map_program_ids );

#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */

#ifdef class_VCDiff_Encoder_defined

#ifdef PROG_VCDIFF_ENCODER_ID
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  START_NEW_PROGRAM_ID(VCDIFF_ENCODER);
#else
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  start_new_program();

#endif /* PROG_VCDIFF_ENCODER_ID */
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  VCDiff_Encoder_program = Pike_compiler->new_program;

#ifndef tObjImpl_VCDIFF_ENCODER

#undef tObjIs_VCDIFF_ENCODER
#define tObjIs_VCDIFF_ENCODER "\3\1\177\0\0\2"

#undef tObjImpl_VCDIFF_ENCODER
#define tObjImpl_VCDIFF_ENCODER "\3\0\177\0\0\2"

#endif /* tObjImpl_VCDIFF_ENCODER */

#ifdef THIS_VCDIFF_ENCODER
  VCDiff_Encoder_storage_offset = ADD_STORAGE(struct VCDiff_Encoder_struct);
#endif /* THIS_VCDIFF_ENCODER */

#ifdef VCDiff_Encoder_event_handler_defined
  pike_set_prog_event_callback(VCDiff_Encoder_event_handler);

#ifndef VCDiff_Encoder_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* VCDiff_Encoder_gc_live_obj */

#endif /* VCDiff_Encoder_event_handler_defined */

#ifdef f_VCDiff_Encoder_create_defined

#ifdef f_VCDiff_Encoder_create_fun_num_used
  f_VCDiff_Encoder_create_fun_num =
#endif /* f_VCDiff_Encoder_create_fun_num_used */
#line 55 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("create", f_VCDiff_Encoder_create, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Encoder_create_defined */

#ifdef f_VCDiff_Encoder_encode_defined

#ifdef f_VCDiff_Encoder_encode_fun_num_used
  f_VCDiff_Encoder_encode_fun_num =
#endif /* f_VCDiff_Encoder_encode_fun_num_used */
#line 85 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("encode", f_VCDiff_Encoder_encode, tFunc(tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Encoder_encode_defined */

#ifdef f_VCDiff_Encoder_encode_chunk_defined

#ifdef f_VCDiff_Encoder_encode_chunk_fun_num_used
  f_VCDiff_Encoder_encode_chunk_fun_num =
#endif /* f_VCDiff_Encoder_encode_chunk_fun_num_used */
#line 91 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("encode_chunk", f_VCDiff_Encoder_encode_chunk, tFunc(tOr(tVoid,tStr) tOr(tVoid,"\10\0\0\0\0\0\0\0\1"),tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Encoder_encode_chunk_defined */
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  VCDiff_Encoder_program=end_program();
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#ifdef VCDiff_Encoder_program_fun_num_used
VCDiff_Encoder_program_fun_num=
#endif
 add_program_constant("Encoder",VCDiff_Encoder_program,0);

#endif /* class_VCDiff_Encoder_defined */

#ifdef class_VCDiff_Decoder_defined

#ifdef PROG_VCDIFF_DECODER_ID
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  START_NEW_PROGRAM_ID(VCDIFF_DECODER);
#else
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  start_new_program();

#endif /* PROG_VCDIFF_DECODER_ID */
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  VCDiff_Decoder_program = Pike_compiler->new_program;

#ifndef tObjImpl_VCDIFF_DECODER

#undef tObjIs_VCDIFF_DECODER
#define tObjIs_VCDIFF_DECODER "\3\1\177\0\0\3"

#undef tObjImpl_VCDIFF_DECODER
#define tObjImpl_VCDIFF_DECODER "\3\0\177\0\0\3"

#endif /* tObjImpl_VCDIFF_DECODER */

#ifdef THIS_VCDIFF_DECODER
  VCDiff_Decoder_storage_offset = ADD_STORAGE(struct VCDiff_Decoder_struct);
#endif /* THIS_VCDIFF_DECODER */

#ifdef var_dictionary_VCDiff_Decoder_defined
  PIKE_MAP_VARIABLE("dictionary", VCDiff_Decoder_storage_offset + OFFSETOF(VCDiff_Decoder_struct, dictionary),
                    tStr, PIKE_T_STRING, 0);
#endif /* var_dictionary_VCDiff_Decoder_defined */

#ifdef VCDiff_Decoder_event_handler_defined
  pike_set_prog_event_callback(VCDiff_Decoder_event_handler);

#ifndef VCDiff_Decoder_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* VCDiff_Decoder_gc_live_obj */

#endif /* VCDiff_Decoder_event_handler_defined */

#ifdef f_VCDiff_Decoder_create_defined

#ifdef f_VCDiff_Decoder_create_fun_num_used
  f_VCDiff_Decoder_create_fun_num =
#endif /* f_VCDiff_Decoder_create_fun_num_used */
#line 166 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("create", f_VCDiff_Decoder_create, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Decoder_create_defined */

#ifdef f_VCDiff_Decoder_decode_defined

#ifdef f_VCDiff_Decoder_decode_fun_num_used
  f_VCDiff_Decoder_decode_fun_num =
#endif /* f_VCDiff_Decoder_decode_fun_num_used */
#line 184 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("decode", f_VCDiff_Decoder_decode, tFunc(tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Decoder_decode_defined */

#ifdef f_VCDiff_Decoder_decode_chunk_defined

#ifdef f_VCDiff_Decoder_decode_chunk_fun_num_used
  f_VCDiff_Decoder_decode_chunk_fun_num =
#endif /* f_VCDiff_Decoder_decode_chunk_fun_num_used */
#line 190 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    ADD_FUNCTION2("decode_chunk", f_VCDiff_Decoder_decode_chunk, tFunc(tOr(tVoid,tStr) tOr(tVoid,"\10\0\0\0\0\0\0\0\1"),tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_VCDiff_Decoder_decode_chunk_defined */
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
  VCDiff_Decoder_program=end_program();
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#ifdef VCDiff_Decoder_program_fun_num_used
VCDiff_Decoder_program_fun_num=
#endif
 add_program_constant("Decoder",VCDiff_Decoder_program,0);

#endif /* class_VCDiff_Decoder_defined */

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( 0 );
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
#line 269 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#endif
}

PIKE_MODULE_EXIT
{
#ifdef HAVE_VCDIFF
 
#ifdef class_VCDiff_Encoder_defined
  if(VCDiff_Encoder_program) {
#line 49 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    free_program(VCDiff_Encoder_program);
    VCDiff_Encoder_program=0;
  }

#endif /* class_VCDiff_Encoder_defined */

#ifdef class_VCDiff_Decoder_defined
  if(VCDiff_Decoder_program) {
#line 159 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
    free_program(VCDiff_Decoder_program);
    VCDiff_Decoder_program=0;
  }

#endif /* class_VCDiff_Decoder_defined */
#line 276 "/Users/hww3/devel/pike/src/post_modules/VCDiff/vcdiff.cmod"
#endif
}



#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
static int ___cmod_map_program_ids(int id)
{
  int i = 0;
  if( (id&0x7f000000) != 0x7f000000 ) return id;
  id = id&0x00ffffff;
#ifdef class_VCDiff_Encoder_defined
if(id==2) return VCDiff_Encoder_program->id;
#endif
#ifdef class_VCDiff_Decoder_defined
if(id==3) return VCDiff_Decoder_program->id;
#endif
  return 0;
}
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
