You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ma...@apache.org on 2010/01/16 02:52:29 UTC

svn commit: r899870 [8/8] - in /hadoop/avro/trunk: ./ lang/c/ lang/c/datatypes/ lang/c/docs/ lang/c/io/ lang/c/jansson/ lang/c/jansson/doc/ lang/c/jansson/doc/ext/ lang/c/jansson/src/ lang/c/jansson/test/ lang/c/jansson/test/testdata/ lang/c/jansson/te...

Added: hadoop/avro/trunk/lang/c/src/st.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/st.c?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/st.c (added)
+++ hadoop/avro/trunk/lang/c/src/st.c Sat Jan 16 01:52:24 2010
@@ -0,0 +1,616 @@
+/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
+
+/* static	char	sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "st.h"
+
+typedef struct st_table_entry st_table_entry;
+
+struct st_table_entry
+{
+  unsigned int hash;
+  st_data_t key;
+  st_data_t record;
+  st_table_entry *next;
+};
+
+#define ST_DEFAULT_MAX_DENSITY 5
+#define ST_DEFAULT_INIT_TABLE_SIZE 11
+
+    /*
+     * DEFAULT_MAX_DENSITY is the default for the largest we allow the
+     * average number of items per bin before increasing the number of
+     * bins
+     *
+     * DEFAULT_INIT_TABLE_SIZE is the default for the number of bins
+     * allocated initially
+     *
+     */
+static int numcmp (long, long);
+static int numhash (long);
+static struct st_hash_type type_numhash = {
+  numcmp,
+  numhash,
+};
+
+/* extern int strcmp(const char *, const char *); */
+static int strhash (const char *);
+static struct st_hash_type type_strhash = {
+  strcmp,
+  strhash,
+};
+
+static void rehash (st_table *);
+
+#ifdef RUBY
+#define malloc xmalloc
+#define calloc xcalloc
+#endif
+
+#define alloc(type) (type*)malloc((unsigned)sizeof(type))
+#define Calloc(n,s) (char*)calloc((n),(s))
+
+#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
+
+#define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key))
+#define do_hash_bin(key,table) (do_hash(key, table)%(table)->num_bins)
+
+/*
+ * MINSIZE is the minimum size of a dictionary.
+ */
+
+#define MINSIZE 8
+
+/*
+Table of prime numbers 2^n+a, 2<=n<=30.
+*/
+static long primes[] = {
+  8 + 3,
+  16 + 3,
+  32 + 5,
+  64 + 3,
+  128 + 3,
+  256 + 27,
+  512 + 9,
+  1024 + 9,
+  2048 + 5,
+  4096 + 3,
+  8192 + 27,
+  16384 + 43,
+  32768 + 3,
+  65536 + 45,
+  131072 + 29,
+  262144 + 3,
+  524288 + 21,
+  1048576 + 7,
+  2097152 + 17,
+  4194304 + 15,
+  8388608 + 9,
+  16777216 + 43,
+  33554432 + 35,
+  67108864 + 15,
+  134217728 + 29,
+  268435456 + 3,
+  536870912 + 11,
+  1073741824 + 85,
+  0
+};
+
+static int
+new_size (size)
+     int size;
+{
+  int i;
+
+#if 0
+  for (i = 3; i < 31; i++)
+    {
+      if ((1 << i) > size)
+	return 1 << i;
+    }
+  return -1;
+#else
+  int newsize;
+
+  for (i = 0, newsize = MINSIZE;
+       i < sizeof (primes) / sizeof (primes[0]); i++, newsize <<= 1)
+    {
+      if (newsize > size)
+	return primes[i];
+    }
+  /* Ran out of polynomials */
+  return -1;			/* should raise exception */
+#endif
+}
+
+#ifdef HASH_LOG
+static int collision = 0;
+static int init_st = 0;
+
+static void
+stat_col ()
+{
+  FILE *f = fopen ("/tmp/col", "w");
+  fprintf (f, "collision: %d\n", collision);
+  fclose (f);
+}
+#endif
+
+st_table *
+st_init_table_with_size (type, size)
+     struct st_hash_type *type;
+     int size;
+{
+  st_table *tbl;
+
+#ifdef HASH_LOG
+  if (init_st == 0)
+    {
+      init_st = 1;
+      atexit (stat_col);
+    }
+#endif
+
+  size = new_size (size);	/* round up to prime number */
+
+  tbl = alloc (st_table);
+  tbl->type = type;
+  tbl->num_entries = 0;
+  tbl->num_bins = size;
+  tbl->bins = (st_table_entry **) Calloc (size, sizeof (st_table_entry *));
+
+  return tbl;
+}
+
+st_table *
+st_init_table (type)
+     struct st_hash_type *type;
+{
+  return st_init_table_with_size (type, 0);
+}
+
+st_table *
+st_init_numtable (void)
+{
+  return st_init_table (&type_numhash);
+}
+
+st_table *
+st_init_numtable_with_size (size)
+     int size;
+{
+  return st_init_table_with_size (&type_numhash, size);
+}
+
+st_table *
+st_init_strtable (void)
+{
+  return st_init_table (&type_strhash);
+}
+
+st_table *
+st_init_strtable_with_size (size)
+     int size;
+{
+  return st_init_table_with_size (&type_strhash, size);
+}
+
+void
+st_free_table (table)
+     st_table *table;
+{
+  register st_table_entry *ptr, *next;
+  int i;
+
+  for (i = 0; i < table->num_bins; i++)
+    {
+      ptr = table->bins[i];
+      while (ptr != 0)
+	{
+	  next = ptr->next;
+	  free (ptr);
+	  ptr = next;
+	}
+    }
+  free (table->bins);
+  free (table);
+}
+
+#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
+((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
+
+#ifdef HASH_LOG
+#define COLLISION collision++
+#else
+#define COLLISION
+#endif
+
+#define FIND_ENTRY(table, ptr, hash_val, bin_pos) do {\
+    bin_pos = hash_val%(table)->num_bins;\
+    ptr = (table)->bins[bin_pos];\
+    if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
+	COLLISION;\
+	while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
+	    ptr = ptr->next;\
+	}\
+	ptr = ptr->next;\
+    }\
+} while (0)
+
+int
+st_lookup (table, key, value)
+     st_table *table;
+     register st_data_t key;
+     st_data_t *value;
+{
+  unsigned int hash_val, bin_pos;
+  register st_table_entry *ptr;
+
+  hash_val = do_hash (key, table);
+  FIND_ENTRY (table, ptr, hash_val, bin_pos);
+
+  if (ptr == 0)
+    {
+      return 0;
+    }
+  else
+    {
+      if (value != 0)
+	*value = ptr->record;
+      return 1;
+    }
+}
+
+#define ADD_DIRECT(table, key, value, hash_val, bin_pos)\
+do {\
+    st_table_entry *entry;\
+    if (table->num_entries/(table->num_bins) > ST_DEFAULT_MAX_DENSITY) {\
+	rehash(table);\
+        bin_pos = hash_val % table->num_bins;\
+    }\
+    \
+    entry = alloc(st_table_entry);\
+    \
+    entry->hash = hash_val;\
+    entry->key = key;\
+    entry->record = value;\
+    entry->next = table->bins[bin_pos];\
+    table->bins[bin_pos] = entry;\
+    table->num_entries++;\
+} while (0)
+
+int
+st_insert (table, key, value)
+     register st_table *table;
+     register st_data_t key;
+     st_data_t value;
+{
+  unsigned int hash_val, bin_pos;
+  register st_table_entry *ptr;
+
+  hash_val = do_hash (key, table);
+  FIND_ENTRY (table, ptr, hash_val, bin_pos);
+
+  if (ptr == 0)
+    {
+      ADD_DIRECT (table, key, value, hash_val, bin_pos);
+      return 0;
+    }
+  else
+    {
+      ptr->record = value;
+      return 1;
+    }
+}
+
+void
+st_add_direct (table, key, value)
+     st_table *table;
+     st_data_t key;
+     st_data_t value;
+{
+  unsigned int hash_val, bin_pos;
+
+  hash_val = do_hash (key, table);
+  bin_pos = hash_val % table->num_bins;
+  ADD_DIRECT (table, key, value, hash_val, bin_pos);
+}
+
+static void
+rehash (table)
+     register st_table *table;
+{
+  register st_table_entry *ptr, *next, **new_bins;
+  int i, old_num_bins = table->num_bins, new_num_bins;
+  unsigned int hash_val;
+
+  new_num_bins = new_size (old_num_bins + 1);
+  new_bins =
+    (st_table_entry **) Calloc (new_num_bins, sizeof (st_table_entry *));
+
+  for (i = 0; i < old_num_bins; i++)
+    {
+      ptr = table->bins[i];
+      while (ptr != 0)
+	{
+	  next = ptr->next;
+	  hash_val = ptr->hash % new_num_bins;
+	  ptr->next = new_bins[hash_val];
+	  new_bins[hash_val] = ptr;
+	  ptr = next;
+	}
+    }
+  free (table->bins);
+  table->num_bins = new_num_bins;
+  table->bins = new_bins;
+}
+
+st_table *
+st_copy (old_table)
+     st_table *old_table;
+{
+  st_table *new_table;
+  st_table_entry *ptr, *entry;
+  int i, num_bins = old_table->num_bins;
+
+  new_table = alloc (st_table);
+  if (new_table == 0)
+    {
+      return 0;
+    }
+
+  *new_table = *old_table;
+  new_table->bins = (st_table_entry **)
+    Calloc ((unsigned) num_bins, sizeof (st_table_entry *));
+
+  if (new_table->bins == 0)
+    {
+      free (new_table);
+      return 0;
+    }
+
+  for (i = 0; i < num_bins; i++)
+    {
+      new_table->bins[i] = 0;
+      ptr = old_table->bins[i];
+      while (ptr != 0)
+	{
+	  entry = alloc (st_table_entry);
+	  if (entry == 0)
+	    {
+	      free (new_table->bins);
+	      free (new_table);
+	      return 0;
+	    }
+	  *entry = *ptr;
+	  entry->next = new_table->bins[i];
+	  new_table->bins[i] = entry;
+	  ptr = ptr->next;
+	}
+    }
+  return new_table;
+}
+
+int
+st_delete (table, key, value)
+     register st_table *table;
+     register st_data_t *key;
+     st_data_t *value;
+{
+  unsigned int hash_val;
+  st_table_entry *tmp;
+  register st_table_entry *ptr;
+
+  hash_val = do_hash_bin (*key, table);
+  ptr = table->bins[hash_val];
+
+  if (ptr == 0)
+    {
+      if (value != 0)
+	*value = 0;
+      return 0;
+    }
+
+  if (EQUAL (table, *key, ptr->key))
+    {
+      table->bins[hash_val] = ptr->next;
+      table->num_entries--;
+      if (value != 0)
+	*value = ptr->record;
+      *key = ptr->key;
+      free (ptr);
+      return 1;
+    }
+
+  for (; ptr->next != 0; ptr = ptr->next)
+    {
+      if (EQUAL (table, ptr->next->key, *key))
+	{
+	  tmp = ptr->next;
+	  ptr->next = ptr->next->next;
+	  table->num_entries--;
+	  if (value != 0)
+	    *value = tmp->record;
+	  *key = tmp->key;
+	  free (tmp);
+	  return 1;
+	}
+    }
+
+  return 0;
+}
+
+int
+st_delete_safe (table, key, value, never)
+     register st_table *table;
+     register st_data_t *key;
+     st_data_t *value;
+     st_data_t never;
+{
+  unsigned int hash_val;
+  register st_table_entry *ptr;
+
+  hash_val = do_hash_bin (*key, table);
+  ptr = table->bins[hash_val];
+
+  if (ptr == 0)
+    {
+      if (value != 0)
+	*value = 0;
+      return 0;
+    }
+
+  for (; ptr != 0; ptr = ptr->next)
+    {
+      if ((ptr->key != never) && EQUAL (table, ptr->key, *key))
+	{
+	  table->num_entries--;
+	  *key = ptr->key;
+	  if (value != 0)
+	    *value = ptr->record;
+	  ptr->key = ptr->record = never;
+	  return 1;
+	}
+    }
+
+  return 0;
+}
+
+static int
+delete_never (key, value, never)
+     st_data_t key, value, never;
+{
+  if (value == never)
+    return ST_DELETE;
+  return ST_CONTINUE;
+}
+
+void
+st_cleanup_safe (table, never)
+     st_table *table;
+     st_data_t never;
+{
+  int num_entries = table->num_entries;
+
+  st_foreach (table, delete_never, never);
+  table->num_entries = num_entries;
+}
+
+int
+st_foreach (table, func, arg)
+     st_table *table;
+     int (*func) ();
+     st_data_t arg;
+{
+  st_table_entry *ptr, *last, *tmp;
+  enum st_retval retval;
+  int i;
+
+  for (i = 0; i < table->num_bins; i++)
+    {
+      last = 0;
+      for (ptr = table->bins[i]; ptr != 0;)
+	{
+	  retval = (*func) (ptr->key, ptr->record, arg);
+	  switch (retval)
+	    {
+	    case ST_CHECK:	/* check if hash is modified during iteration */
+	      tmp = 0;
+	      if (i < table->num_bins)
+		{
+		  for (tmp = table->bins[i]; tmp; tmp = tmp->next)
+		    {
+		      if (tmp == ptr)
+			break;
+		    }
+		}
+	      if (!tmp)
+		{
+		  /* call func with error notice */
+		  return 1;
+		}
+	      /* fall through */
+	    case ST_CONTINUE:
+	      last = ptr;
+	      ptr = ptr->next;
+	      break;
+	    case ST_STOP:
+	      return 0;
+	    case ST_DELETE:
+	      tmp = ptr;
+	      if (last == 0)
+		{
+		  table->bins[i] = ptr->next;
+		}
+	      else
+		{
+		  last->next = ptr->next;
+		}
+	      ptr = ptr->next;
+	      free (tmp);
+	      table->num_entries--;
+	    }
+	}
+    }
+  return 0;
+}
+
+static int
+strhash (string)
+     register const char *string;
+{
+  register int c;
+
+#ifdef HASH_ELFHASH
+  register unsigned int h = 0, g;
+
+  while ((c = *string++) != '\0')
+    {
+      h = (h << 4) + c;
+      if (g = h & 0xF0000000)
+	h ^= g >> 24;
+      h &= ~g;
+    }
+  return h;
+#elif defined(HASH_PERL)
+  register int val = 0;
+
+  while ((c = *string++) != '\0')
+    {
+      val += c;
+      val += (val << 10);
+      val ^= (val >> 6);
+    }
+  val += (val << 3);
+  val ^= (val >> 11);
+
+  return val + (val << 15);
+#else
+  register int val = 0;
+
+  while ((c = *string++) != '\0')
+    {
+      val = val * 997 + c;
+    }
+
+  return val + (val >> 5);
+#endif
+}
+
+static int
+numcmp (x, y)
+     long x, y;
+{
+  return x != y;
+}
+
+static int
+numhash (n)
+     long n;
+{
+  return n;
+}

Added: hadoop/avro/trunk/lang/c/src/st.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/st.h?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/src/st.h (added)
+++ hadoop/avro/trunk/lang/c/src/st.h Sat Jan 16 01:52:24 2010
@@ -0,0 +1,73 @@
+/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
+
+/* @(#) st.h 5.1 89/12/14 */
+
+#ifndef ST_INCLUDED
+
+#define ST_INCLUDED
+
+#if SIZEOF_LONG == SIZEOF_VOID_P
+typedef unsigned long st_data_t;
+#elif SIZEOF_LONG_LONG == SIZEOF_VOID_P
+typedef unsigned LONG_LONG st_data_t;
+#else
+#error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<---
+#endif
+#define ST_DATA_T_DEFINED
+typedef struct st_table st_table;
+
+struct st_hash_type
+{
+  int (*compare) ();
+  int (*hash) ();
+};
+
+struct st_table
+{
+  struct st_hash_type *type;
+  int num_bins;
+  int num_entries;
+  struct st_table_entry **bins;
+};
+
+#define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
+
+enum st_retval
+{ ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK };
+
+#ifndef _
+# define _(args) args
+#endif
+#ifndef ANYARGS
+# ifdef __cplusplus
+#   define ANYARGS ...
+# else
+#   define ANYARGS
+# endif
+#endif
+
+st_table *st_init_table _((struct st_hash_type *));
+st_table *st_init_table_with_size _((struct st_hash_type *, int));
+st_table *st_init_numtable _((void));
+st_table *st_init_numtable_with_size _((int));
+st_table *st_init_strtable _((void));
+st_table *st_init_strtable_with_size _((int));
+int st_delete _((st_table *, st_data_t *, st_data_t *));
+int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t));
+int st_insert _((st_table *, st_data_t, st_data_t));
+int st_lookup _((st_table *, st_data_t, st_data_t *));
+int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t));
+void st_add_direct _((st_table *, st_data_t, st_data_t));
+void st_free_table _((st_table *));
+void st_cleanup_safe _((st_table *, st_data_t));
+st_table *st_copy _((st_table *));
+
+#define ST_NUMCMP	((int (*)()) 0)
+#define ST_NUMHASH	((int (*)()) -2)
+
+#define st_numcmp	ST_NUMCMP
+#define st_numhash	ST_NUMHASH
+
+int st_strhash ();
+
+#endif /* ST_INCLUDED */

Added: hadoop/avro/trunk/lang/c/tests/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/Makefile.am?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/Makefile.am (added)
+++ hadoop/avro/trunk/lang/c/tests/Makefile.am Sat Jan 16 01:52:24 2010
@@ -0,0 +1,21 @@
+# -pedantic
+AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/jansson/src
+AM_CFLAGS=-Wall 
+ACLOCAL_AMFLAGS=-I m4
+
+EXTRA_DIST=schema_tests
+
+check_PROGRAMS=test_avro_schema
+
+test_LDADD=$(top_builddir)/src/libavro.la
+
+test_avro_schema_SOURCES=test_avro_schema.c
+test_avro_schema_LDADD=$(test_LDADD)
+
+test_avro_data_SOURCES=test_avro_data.c
+test_avro_data_LDADD=$(test_LDADD)
+
+test_avro_interop_SOURCES=test_avro_interop.c
+test_avro_interop_LDADD=$(test_LDADD)
+
+TESTS=$(check_PROGRAMS)

Added: hadoop/avro/trunk/lang/c/tests/schema_tests/fail/invalid_avro_id
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/schema_tests/fail/invalid_avro_id?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/schema_tests/fail/invalid_avro_id (added)
+++ hadoop/avro/trunk/lang/c/tests/schema_tests/fail/invalid_avro_id Sat Jan 16 01:52:24 2010
@@ -0,0 +1,3 @@
+{ "name" : "2d2",
+  "type": "enum",
+  "symbols" : [ "c3po" ] }

Added: hadoop/avro/trunk/lang/c/tests/schema_tests/fail/record_with_invalid_reference
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/schema_tests/fail/record_with_invalid_reference?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/schema_tests/fail/record_with_invalid_reference (added)
+++ hadoop/avro/trunk/lang/c/tests/schema_tests/fail/record_with_invalid_reference Sat Jan 16 01:52:24 2010
@@ -0,0 +1,7 @@
+{ "type": "record",
+  "name": "recursive",
+  "fields": [
+    { "name": "label", "type": "string" },
+    { "name": "children", "type": {"type": "array", "items": "foobar"} }
+  ]
+}

Modified: hadoop/avro/trunk/lang/c/tests/schema_tests/pass/enum
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/schema_tests/pass/enum?rev=899870&r1=899869&r2=899870&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/schema_tests/pass/enum (original)
+++ hadoop/avro/trunk/lang/c/tests/schema_tests/pass/enum Sat Jan 16 01:52:24 2010
@@ -1,4 +1,4 @@
 { "type": "enum",
-  "name": "Three Stooges",
+  "name": "three_stooges",
   "symbols" : [ "Moe", "Larry", "Curly" ]
 }

Added: hadoop/avro/trunk/lang/c/tests/schema_tests/pass/interop.avsc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/schema_tests/pass/interop.avsc?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/schema_tests/pass/interop.avsc (added)
+++ hadoop/avro/trunk/lang/c/tests/schema_tests/pass/interop.avsc Sat Jan 16 01:52:24 2010
@@ -0,0 +1,28 @@
+{"type": "record", "name":"Interop", "namespace": "org.apache.avro",
+  "fields": [
+      {"name": "intField", "type": "int"},
+      {"name": "longField", "type": "long"},
+      {"name": "stringField", "type": "string"},
+      {"name": "boolField", "type": "boolean"},
+      {"name": "floatField", "type": "float"},
+      {"name": "doubleField", "type": "double"},
+      {"name": "bytesField", "type": "bytes"},
+      {"name": "nullField", "type": "null"},
+      {"name": "arrayField", "type": {"type": "array", "items": "double"}},
+      {"name": "mapField", "type":
+       {"type": "map", "values":
+        {"type": "record", "name": "Foo",
+         "fields": [{"name": "label", "type": "string"}]}}},
+      {"name": "unionField", "type":
+       ["boolean", "double", {"type": "array", "items": "bytes"}]},
+      {"name": "enumField", "type":
+       {"type": "enum", "name": "Kind", "symbols": ["A","B","C"]}},
+      {"name": "fixedField", "type":
+       {"type": "fixed", "name": "MD5", "size": 16}},
+      {"name": "recordField", "type":
+       {"type": "record", "name": "Node",
+        "fields": [
+            {"name": "label", "type": "string"},
+            {"name": "children", "type": {"type": "array", "items": "Node"}}]}}
+  ]
+}

Added: hadoop/avro/trunk/lang/c/tests/schema_tests/pass/string_extra_attributes
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/schema_tests/pass/string_extra_attributes?rev=899870&view=auto
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/schema_tests/pass/string_extra_attributes (added)
+++ hadoop/avro/trunk/lang/c/tests/schema_tests/pass/string_extra_attributes Sat Jan 16 01:52:24 2010
@@ -0,0 +1 @@
+{"type":"string", "ignored": "value"}

Modified: hadoop/avro/trunk/lang/c/tests/test_avro_data.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_data.c?rev=899870&r1=899869&r2=899870&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_data.c Sat Jan 16 01:52:24 2010
@@ -17,19 +17,19 @@
 under the License.
 */
 #include <stdlib.h>
+#include <stdint.h>
 #include <time.h>
 #include <string.h>
-#include "avro_private.h"
-#include "util/dump.h"
+#include "avro.h"
+#include "dump.h"
 
-char buf[1024];
+char buf[4096];
+
+typedef int (*avro_test) (void);
 
-typedef avro_status_t (*avro_test) (apr_pool_t * pool,
-				    avro_io_reader * reader,
-				    avro_io_writer * writer);
 struct test_case
 {
-  avro_long_t value;
+  long value;
   unsigned len;
   uint8_t bytes[16];
 };
@@ -47,359 +47,206 @@
   {.value = 65,.len = 2,.bytes = {0x82, 0x01}}
 };
 
-static avro_status_t
-test_string (apr_pool_t * pool, avro_io_reader * reader,
-	     avro_io_writer * writer)
+static int
+test_string (void)
 {
   int i;
-  avro_status_t status;
-  avro_string_t strings[] = { L"\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
-    L"\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?",
-    L"foo", L"bar", L"baz"
+  int status;
+  const char *strings[] = { "Four score and seven years ago",
+    "our father brought forth on this continent",
+    "a new nation", "conceived in Liberty",
+    "and dedicated to the proposition that all men are created equal."
   };
-  avro_string_t read_str;
-
   for (i = 0; i < sizeof (strings) / sizeof (strings[0]); i++)
     {
-      avro_string_t str = strings[i];
-      status = avro_write_string (writer, pool, str);
-      if (status != AVRO_OK)
-	{
-	  return status;
-	}
-      status = avro_read_string (reader, pool, &read_str);
-      if (status != AVRO_OK)
-	{
-	  return status;
-	}
-      if (wcscmp (str, read_str))
-	{
-	  /* string didn't survive encoding/decoding */
-	  fprintf (stderr, "%ls != %ls\n", str, read_str);
-	  return AVRO_FAILURE;
-	}
-      else
-	{
-	  fprintf (stderr, "%ls = %ls\n", str, read_str);
-	}
+      avro_binary_encode_to_memory (buf, sizeof (buf), avro_schema_string (),
+				    avro_string (strings[i]));
     }
-  return AVRO_OK;
+  return 0;
 }
 
-static avro_status_t
-test_bytes (apr_pool_t * pool, avro_io_reader * reader,
-	    avro_io_writer * writer)
+static int
+test_bytes (void)
 {
-  avro_status_t status;
+  int status;
   char bytes[] = { 0xDE, 0xAD, 0xBE, 0xEF };
   char *read_bytes;
-  avro_long_t len;
 
-  status = avro_write_bytes (writer, bytes, sizeof (bytes));
-  if (status != AVRO_OK)
+#if 0
+  status = avro_write_bytes (encoder, bytes, sizeof (bytes));
+  if (status != 0)
     {
       return status;
     }
-  status = avro_read_bytes (reader, pool, (void *) &read_bytes, &len);
-  if (status != AVRO_OK)
+  status = avro_read_bytes (decoder, pool, (void *) &read_bytes, &len);
+  if (status != 0)
     {
       return status;
     }
   if (len != sizeof (bytes))
     {
-      return AVRO_FAILURE;
+      return 1;
     }
   if (memcmp (bytes, read_bytes, len))
     {
-      return AVRO_FAILURE;
+      return 1;
     }
-  return AVRO_OK;
+#endif
+  return 0;
 }
 
-static avro_status_t
-test_int_long (apr_pool_t * pool, avro_io_reader * reader,
-	       avro_io_writer * writer, int is_long)
+static int
+test_int (void)
 {
-  apr_pool_t *subpool;
-  avro_status_t status;
-  int i;
-  const int num_rand_tests = 100;
-  uint8_t my_buf[64];
-  avro_io_writer *mywriter;
-  long rand_val;
-
-  apr_pool_create (&subpool, pool);
-  for (i = 0; i < sizeof (test_cases) / sizeof (test_cases[0]); i++)
-    {
-      struct test_case *test = test_cases + i;
-      avro_int_t int_test_val;
-      avro_long_t long_test_val;
-
-      mywriter =
-	avro_io_writer_from_memory (subpool, (void *) my_buf,
-				    sizeof (my_buf));
-      if (!mywriter)
-	{
-	  return AVRO_FAILURE;
-	}
-
-      if (is_long)
-	{
-	  long_test_val = test->value;
-	  DEBUG (fprintf
-		 (stderr, "Running long test val=%lld\n", long_test_val));
-	  status = avro_write_long (mywriter, &long_test_val);
-	}
-      else
-	{
-	  int_test_val = (avro_int_t) test->value;
-	  DEBUG (fprintf (stderr, "Running int test val=%d\n", int_test_val));
-	  status = avro_write_int (mywriter, &int_test_val);
-	}
-      if (status != AVRO_OK)
-	{
-	  return status;
-	}
-      if (memcmp ((void *) my_buf, (void *) test->bytes, test->len))
-	{
-	  fprintf (stderr, "Received bytes");
-	  dump (stderr, (void *) my_buf, test->len);
-	  fprintf (stderr, "Expected bytes");
-	  dump (stderr, (void *) test->bytes, test->len);
-	  return AVRO_FAILURE;
-	}
-      apr_pool_clear (subpool);
-    }
-
-  for (i = 0; i < num_rand_tests; i++)
-    {
-      avro_long_t long_in, long_out;
-      avro_int_t int_in, int_out;
-      rand_val = random ();
-      if (is_long)
-	{
-	  avro_long_t a, b;
-	  a = random ();
-	  b = random ();
-	  long_in = (a << 32) | b;
-	}
-      else
-	{
-	  int_in = random ();
-	}
-      if (rand_val % 2)
-	{
-	  long_in -= (long_in * 2);
-	  int_in -= (int_in * 2);
-	}
-      if (is_long)
-	{
-	  DEBUG (fprintf
-		 (stderr, "Running long test %d val=%lld\n", i, long_in));
-	  status = avro_write_long (writer, &long_in);
-	  if (status != AVRO_OK)
-	    {
-	      fprintf (stderr, "Unable to write long %lld\n", long_in);
-	      return status;
-	    }
-	  status = avro_read_long (reader, &long_out);
-	  if (status != AVRO_OK)
-	    {
-	      fprintf (stderr, "Unable to read long %lld\n", long_in);
-	      return status;
-	    }
-	  if (long_in != long_out)
-	    {
-	      fprintf (stderr, "%lld != %lld\n", long_in, long_out);
-	      return AVRO_FAILURE;
-	    }
-	}
-      else
-	{
-	  DEBUG (fprintf (stderr, "Running int test %d val=%d\n", i, int_in));
-	  status = avro_write_int (writer, &int_in);
-	  if (status != AVRO_OK)
-	    {
-	      fprintf (stderr, "Unable to write int %d\n", int_in);
-	      return status;
-	    }
-	  status = avro_read_int (reader, &int_out);
-	  if (status != AVRO_OK)
-	    {
-	      fprintf (stderr, "Unable to read int\n");
-	      return status;
-	    }
-	  if (int_in != int_out)
-	    {
-	      fprintf (stderr, "%d != %d\n", int_in, int_out);
-	      return AVRO_FAILURE;
-	    }
-	}
-    }
-  return AVRO_OK;
+  return 0;
 }
 
-static avro_status_t
-test_int (apr_pool_t * pool, avro_io_reader * reader, avro_io_writer * writer)
+static int
+test_long (void)
 {
-  return test_int_long (pool, reader, writer, 0);
+  return 0;
 }
 
-static avro_status_t
-test_long (apr_pool_t * pool, avro_io_reader * reader,
-	   avro_io_writer * writer)
+static int
+test_float (void)
 {
-  return test_int_long (pool, reader, writer, 1);
-}
-
-static avro_status_t
-test_float (apr_pool_t * pool, avro_io_reader * reader,
-	    avro_io_writer * writer)
-{
-  avro_status_t status;
+  int status;
   float input, output;
   int i;
   int const num_rand_tests = 25;
 
+#if 0
   for (i = 0; i < num_rand_tests; i++)
     {
       input = random () * 1.1;
-      status = avro_write_float (writer, input);
-      if (status != AVRO_OK)
+      status = avro_write_float (encoder, input);
+      if (status != 0)
 	{
 	  return status;
 	}
-      status = avro_read_float (reader, &output);
-      if (status != AVRO_OK)
+      status = avro_read_float (decoder, &output);
+      if (status != 0)
 	{
 	  return status;
 	}
       if (input != output)
 	{
 	  fprintf (stderr, "%f != %f\n", input, output);
-	  return AVRO_FAILURE;
+	  return 1;
 	}
     }
-  return AVRO_OK;
+#endif
+  return 0;
 }
 
-static avro_status_t
-test_double (apr_pool_t * pool, avro_io_reader * reader,
-	     avro_io_writer * writer)
+static int
+test_double (void)
 {
-  avro_status_t status;
+  int status;
   double input, output;
   int i;
   int const num_rand_tests = 25;
 
+#if 0
   for (i = 0; i < num_rand_tests; i++)
     {
       input = random () * 1.1;
-      status = avro_write_double (writer, input);
-      if (status != AVRO_OK)
+      status = avro_write_double (encoder, input);
+      if (status != 0)
 	{
 	  return status;
 	}
-      status = avro_read_double (reader, &output);
-      if (status != AVRO_OK)
+      status = avro_read_double (decoder, &output);
+      if (status != 0)
 	{
 	  return status;
 	}
       if (input != output)
 	{
 	  fprintf (stderr, "%f != %f\n", input, output);
-	  return AVRO_FAILURE;
+	  return 1;
 	}
     }
-  return AVRO_OK;
+#endif
+  return 0;
 }
 
-static avro_status_t
-test_boolean (apr_pool_t * pool, avro_io_reader * reader,
-	      avro_io_writer * writer)
+static int
+test_boolean (void)
 {
-  avro_status_t status;
+  int status;
   int i, bool_in, bool_out;
 
+#if 0
   for (i = 0; i < 2; i++)
     {
       bool_in = i;
-      status = avro_write_bool (writer, bool_in);
-      if (status != AVRO_OK)
+      status = avro_write_bool (encoder, bool_in);
+      if (status != 0)
 	{
 	  return status;
 	}
-      status = avro_read_bool (reader, &bool_out);
-      if (status != AVRO_OK)
+      status = avro_read_bool (decoder, &bool_out);
+      if (status != 0)
 	{
 	  return status;
 	}
       if (bool_in != bool_out)
 	{
 	  fprintf (stderr, "%d != %d\n", bool_in, bool_out);
-	  return AVRO_FAILURE;
+	  return 1;
 	}
     }
-  return AVRO_OK;
+#endif
+  return 0;
 }
 
-static avro_status_t
-test_null (apr_pool_t * pool, avro_io_reader * reader,
-	   avro_io_writer * writer)
+static int
+test_null (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_record (apr_pool_t * pool, avro_io_reader * reader,
-	     avro_io_writer * writer)
+int
+test_record (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_enum (apr_pool_t * pool, avro_io_reader * reader,
-	   avro_io_writer * writer)
+int
+test_enum (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_array (apr_pool_t * pool, avro_io_reader * reader,
-	    avro_io_writer * writer)
+int
+test_array (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_map (apr_pool_t * pool, avro_io_reader * reader, avro_io_writer * writer)
+int
+test_map (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_union (apr_pool_t * pool, avro_io_reader * reader,
-	    avro_io_writer * writer)
+int
+test_union (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-avro_status_t
-test_fixed (apr_pool_t * pool, avro_io_reader * reader,
-	    avro_io_writer * writer)
+int
+test_fixed (void)
 {
-  return AVRO_OK;
+  return 0;
 }
 
-
 int
 main (void)
 {
   int i;
-  apr_pool_t *pool, *subpool;
-  avro_status_t status;
-  avro_io_reader *reader;
-  avro_io_writer *writer;
   struct avro_tests
   {
     char *name;
@@ -435,32 +282,16 @@
   };
 
   srandom (time (NULL));
-
-  avro_initialize ();
-  apr_pool_create (&pool, NULL);
   for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
     {
       struct avro_tests *test = tests + i;
-      apr_pool_create (&subpool, pool);
-      reader = avro_io_reader_from_memory (subpool, buf, sizeof (buf));
-      if (!reader)
-	{
-	  return AVRO_FAILURE;
-	}
-      writer = avro_io_writer_from_memory (subpool, buf, sizeof (buf));
-      if (!writer)
-	{
-	  return AVRO_FAILURE;
-	}
       fprintf (stderr, "Running %s tests...\n", test->name);
-      status = test->func (subpool, reader, writer);
-      if (status != AVRO_OK)
+      if (test->func () != 0)
 	{
 	  fprintf (stderr, "failed!\n");
 	  return EXIT_FAILURE;
 	}
       fprintf (stderr, "\t... %s tests passed!\n", test->name);
     }
-  apr_pool_destroy (pool);
   return EXIT_SUCCESS;
 }

Modified: hadoop/avro/trunk/lang/c/tests/test_avro_schema.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_schema.c?rev=899870&r1=899869&r2=899870&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_schema.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_schema.c Sat Jan 16 01:52:24 2010
@@ -22,20 +22,20 @@
 #include <dirent.h>
 
 #include "avro.h"
-#include "avro_private.h"
-#include "apr_strings.h"
 
-apr_pool_t *pool;
+int test_cases = 0;
 
 static void
 run_tests (char *dirpath, int should_pass)
 {
-  char *jsontext;
-  apr_size_t jsonlen;
-  struct avro_value *value;
+  char jsontext[4096];
+  size_t jsonlen, rval;
+  char filepath[1024];
   DIR *dir;
   struct dirent *dent;
-  char *filepath;
+  FILE *fp;
+  avro_schema_t schema;
+  avro_schema_error_t avro_schema_error;
 
   dir = opendir (dirpath);
   if (dir == NULL)
@@ -48,29 +48,57 @@
       dent = readdir (dir);
       if (dent && dent->d_name[0] != '.')
 	{
-	  filepath = apr_pstrcat (pool, dirpath, "/", dent->d_name, NULL);
+	  int test_rval;
+	  snprintf (filepath, sizeof (filepath), "%s/%s", dirpath,
+		    dent->d_name);
 	  fprintf (stderr, "TEST %s...", filepath);
-	  jsontext = avro_util_file_read_full (pool, filepath, &jsonlen);
-	  if (!jsontext)
+	  jsonlen = 0;
+	  fp = fopen (filepath, "r");
+	  if (!fp)
 	    {
-	      fprintf (stderr, "Can't read the file\n");
+	      fprintf (stderr, "can't open!\n");
 	      exit (EXIT_FAILURE);
 	    }
-
-	  value = avro_value_create (pool, jsontext, jsonlen);
-	  if (value && should_pass)
-	    {
-	      avro_value_print_info (value, stderr);
-	    }
-	  else if (!value && !should_pass)
+	  rval = fread (jsontext, 1, sizeof (jsontext) - 1, fp);
+	  jsontext[rval] = '\0';
+	  test_rval =
+	    avro_schema_from_json (jsontext, jsonlen, &schema,
+				   &avro_schema_error);
+	  test_cases++;
+	  if (test_rval == 0)
 	    {
-	      /* failure expected */
+	      if (should_pass)
+		{
+		  avro_schema_t schema_copy = avro_schema_copy (schema);
+		  fprintf (stderr, "pass\n");
+		  avro_schema_printf (schema, stderr);
+		  if (!avro_schema_equal (schema, schema_copy))
+		    {
+		      fprintf (stderr,
+			       "failed to avro_schema_equal(schema,avro_schema_copy())\n");
+		      exit (EXIT_FAILURE);
+		    }
+		}
+	      else
+		{
+		  /* Unexpected success */
+		  fprintf (stderr, "fail! (shouldn't succeed but did)\n");
+		  exit (EXIT_FAILURE);
+		}
 	    }
 	  else
 	    {
-	      exit (EXIT_FAILURE);
+	      if (should_pass)
+		{
+		  fprintf (stderr,
+			   "fail! (should have succeeded but didn't)\n");
+		  exit (EXIT_FAILURE);
+		}
+	      else
+		{
+		  fprintf (stderr, "pass\n");
+		}
 	    }
-	  fprintf (stderr, "ok!\n");
 	}
     }
   while (dent != NULL);
@@ -79,25 +107,27 @@
 int
 main (int argc, char *argv[])
 {
+  int i, j;
   char *srcdir = getenv ("srcdir");
-  char *path;
+  char path[1024];
 
   if (!srcdir)
     {
       srcdir = ".";
     }
 
-  avro_initialize ();
-  apr_pool_create (&pool, NULL);
-
   /* Run the tests that should pass */
-  path = apr_pstrcat (pool, srcdir, "/tests/schema_tests/pass", NULL);
+  snprintf (path, sizeof (path), "%s/schema_tests/pass", srcdir);
   fprintf (stderr, "RUNNING %s\n", path);
   run_tests (path, 1);
-  path = apr_pstrcat (pool, srcdir, "/tests/schema_tests/fail", NULL);
+  snprintf (path, sizeof (path), "%s/schema_tests/fail", srcdir);
   fprintf (stderr, "RUNNING %s\n", path);
   run_tests (path, 0);
 
-  apr_pool_destroy (pool);
+  fprintf (stderr, "==================================================\n");
+  fprintf (stderr, "Finished running %d schema test cases successfully \n",
+	   test_cases);
+  fprintf (stderr, "==================================================\n");
+
   return EXIT_SUCCESS;
 }

Modified: hadoop/avro/trunk/lang/c/version.sh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/version.sh?rev=899870&r1=899869&r2=899870&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/version.sh (original)
+++ hadoop/avro/trunk/lang/c/version.sh Sat Jan 16 01:52:24 2010
@@ -18,9 +18,9 @@
 #         libavro_binary_age = 0
 #         libavro_interface_age = 0
 #
-libavro_micro_version=2
+libavro_micro_version=3
 libavro_interface_age=0
-libavro_binary_age=2
+libavro_binary_age=0
 
 # IGNORE EVERYTHING ELSE FROM HERE DOWN.........
 if test $# != 1; then
@@ -40,10 +40,10 @@
 libage=$(($libavro_binary_age - $libavro_interface_age))
 
 if test "$1" = "project"; then
-	build_xml="../../build.xml"
 	project_ver="undef"
-	if test -f $build_xml; then
-		project_ver=$(sed -n '/name="version"/s/.*value="\(.*\)".*$/\1/p' $build_xml)
+        version_file="../../share/VERSION.txt"
+	if test -f $version_file; then
+		project_ver=$(cat $version_file)
 	fi
 	printf "%s" $project_ver
 elif test "$1" = "libtool"; then