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/26 01:31:09 UTC

svn commit: r903028 - in /hadoop/avro/trunk: ./ lang/c/ lang/c/src/ lang/c/tests/

Author: massie
Date: Tue Jan 26 00:31:08 2010
New Revision: 903028

URL: http://svn.apache.org/viewvc?rev=903028&view=rev
Log:
AVRO-377.  Add getters and setters for all Avro datum types

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/c/src/avro.h
    hadoop/avro/trunk/lang/c/src/datum.c
    hadoop/avro/trunk/lang/c/src/datum.h
    hadoop/avro/trunk/lang/c/src/datum_equal.c
    hadoop/avro/trunk/lang/c/src/datum_read.c
    hadoop/avro/trunk/lang/c/src/datum_validate.c
    hadoop/avro/trunk/lang/c/src/datum_write.c
    hadoop/avro/trunk/lang/c/src/schema.c
    hadoop/avro/trunk/lang/c/src/schema_printf.c
    hadoop/avro/trunk/lang/c/tests/test_avro_data.c
    hadoop/avro/trunk/lang/c/version.sh

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jan 26 00:31:08 2010
@@ -252,6 +252,8 @@
 
     AVRO-371. Add support for encoding/decoding unions (massie)
 
+    AVRO-377. Add getters and setters for all Avro datum types (massie)
+
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/lang/c/src/avro.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/avro.h?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/avro.h (original)
+++ hadoop/avro/trunk/lang/c/src/avro.h Tue Jan 26 00:31:08 2010
@@ -29,8 +29,8 @@
 enum avro_type_t {
 	AVRO_STRING,
 	AVRO_BYTES,
-	AVRO_INT,
-	AVRO_LONG,
+	AVRO_INT32,
+	AVRO_INT64,
 	AVRO_FLOAT,
 	AVRO_DOUBLE,
 	AVRO_BOOLEAN,
@@ -64,16 +64,16 @@
 #define avro_typeof(obj)      ((obj)->type)
 #define is_avro_string(obj)   (obj && avro_typeof(obj) == AVRO_STRING)
 #define is_avro_bytes(obj)    (obj && avro_typeof(obj) == AVRO_BYTES)
-#define is_avro_int(obj)      (obj && avro_typeof(obj) == AVRO_INT)
-#define is_avro_long(obj)     (obj && avro_typeof(obj) == AVRO_LONG)
+#define is_avro_int32(obj)    (obj && avro_typeof(obj) == AVRO_INT32)
+#define is_avro_int64(obj)    (obj && avro_typeof(obj) == AVRO_INT64)
 #define is_avro_float(obj)    (obj && avro_typeof(obj) == AVRO_FLOAT)
 #define is_avro_double(obj)   (obj && avro_typeof(obj) == AVRO_DOUBLE)
 #define is_avro_boolean(obj)  (obj && avro_typeof(obj) == AVRO_BOOLEAN)
 #define is_avro_null(obj)     (obj && avro_typeof(obj) == AVRO_NULL)
 #define is_avro_primitive(obj)(is_avro_string(obj) \
                              ||is_avro_bytes(obj) \
-                             ||is_avro_int(obj) \
-                             ||is_avro_long(obj) \
+                             ||is_avro_int32(obj) \
+                             ||is_avro_int64(obj) \
                              ||is_avro_float(obj) \
                              ||is_avro_double(obj) \
                              ||is_avro_boolean(obj) \
@@ -166,6 +166,8 @@
 /*
  * datum 
  */
+
+/* constructors */
 typedef struct avro_obj_t *avro_datum_t;
 avro_datum_t avro_string(const char *str);
 avro_datum_t avro_wrapstring(const char *str);
@@ -173,38 +175,68 @@
 avro_datum_t avro_bytes(const char *buf, int64_t len);
 avro_datum_t avro_wrapbytes(const char *buf, int64_t len);
 avro_datum_t avro_givebytes(const char *buf, int64_t len);
-avro_datum_t avro_int(int32_t i);
-avro_datum_t avro_long(int64_t l);
+avro_datum_t avro_int32(int32_t i);
+avro_datum_t avro_int64(int64_t l);
 avro_datum_t avro_float(float f);
 avro_datum_t avro_double(double d);
 avro_datum_t avro_boolean(int8_t i);
 avro_datum_t avro_null(void);
-
 avro_datum_t avro_record(const char *name);
-avro_datum_t avro_record_field_get(const avro_datum_t record,
-				   const char *field_name);
-int avro_record_field_set(const avro_datum_t record,
-			  const char *field_name, const avro_datum_t value);
-
 avro_datum_t avro_enum(const char *name, const char *symbol);
-
 avro_datum_t avro_fixed(const char *name, const char *bytes,
 			const int64_t size);
 avro_datum_t avro_wrapfixed(const char *name, const char *bytes,
 			    const int64_t size);
 avro_datum_t avro_givefixed(const char *name, const char *bytes,
 			    const int64_t size);
-
 avro_datum_t avro_map(void);
+avro_datum_t avro_array(void);
+avro_datum_t avro_union(const avro_schema_t schema, const avro_datum_t datum);
+
+/* getters */
+int avro_string_get(avro_datum_t datum, char **p);
+int avro_bytes_get(avro_datum_t datum, char **bytes, int64_t * size);
+int avro_int32_get(avro_datum_t datum, int32_t * i);
+int avro_int64_get(avro_datum_t datum, int64_t * l);
+int avro_float_get(avro_datum_t datum, float *f);
+int avro_double_get(avro_datum_t datum, double *d);
+int avro_boolean_get(avro_datum_t datum, int8_t * i);
+
+int avro_fixed_get(avro_datum_t datum, char **bytes, int64_t * size);
+avro_datum_t avro_record_field_get(const avro_datum_t record,
+				   const char *field_name);
+
+/* setters */
+int avro_string_set(avro_datum_t datum, const char *p);
+int avro_givestring_set(avro_datum_t datum, const char *p);
+int avro_wrapstring_set(avro_datum_t datum, const char *p);
+
+int avro_bytes_set(avro_datum_t datum, const char *bytes, const int64_t size);
+int avro_givebytes_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size);
+int avro_wrapbytes_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size);
+
+int avro_int32_set(avro_datum_t datum, const int32_t i);
+int avro_int64_set(avro_datum_t datum, const int64_t l);
+int avro_float_set(avro_datum_t datum, const float f);
+int avro_double_set(avro_datum_t datum, const double d);
+int avro_boolean_set(avro_datum_t datum, const int8_t i);
+
+int avro_fixed_set(avro_datum_t datum, const char *bytes, const int64_t size);
+int avro_givefixed_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size);
+int avro_wrapfixed_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size);
+
+int avro_record_field_set(const avro_datum_t record,
+			  const char *field_name, const avro_datum_t value);
 int avro_map_set(const avro_datum_t map, const char *key,
 		 const avro_datum_t value);
-
-avro_datum_t avro_array(void);
 int avro_array_append_datum(const avro_datum_t array_datum,
 			    const avro_datum_t datum);
 
-avro_datum_t avro_union(const avro_schema_t schema, const avro_datum_t datum);
-
+/* reference counting */
 avro_datum_t avro_datum_incref(avro_datum_t value);
 void avro_datum_decref(avro_datum_t value);
 

Modified: hadoop/avro/trunk/lang/c/src/datum.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum.c Tue Jan 26 00:31:08 2010
@@ -62,6 +62,55 @@
 	return avro_string_private((char *)str, NULL);
 }
 
+int avro_string_get(avro_datum_t datum, char **p)
+{
+	if (!(is_avro_datum(datum) && is_avro_string(datum)) || !p) {
+		return EINVAL;
+	}
+	*p = avro_datum_to_string(datum)->s;
+	return 0;
+}
+
+static int avro_string_set_private(avro_datum_t datum, const char *p,
+				   void (*string_free) (void *ptr))
+{
+	struct avro_string_datum_t *string;
+	if (!(is_avro_datum(datum) && is_avro_string(datum)) || !p) {
+		return EINVAL;
+	}
+	string = avro_datum_to_string(datum);
+	if (string->free) {
+		string->free(string->s);
+	}
+	string->free = string_free;
+	string->s = (char *)p;
+	return 0;
+}
+
+int avro_string_set(avro_datum_t datum, const char *p)
+{
+	char *string_copy = strdup(p);
+	int rval;
+	if (!string_copy) {
+		return ENOMEM;
+	}
+	rval = avro_string_set_private(datum, p, free);
+	if (rval) {
+		free(string_copy);
+	}
+	return rval;
+}
+
+int avro_givestring_set(avro_datum_t datum, const char *p)
+{
+	return avro_string_set_private(datum, p, free);
+}
+
+int avro_wrapstring_set(avro_datum_t datum, const char *p)
+{
+	return avro_string_set_private(datum, p, NULL);
+}
+
 static avro_datum_t avro_bytes_private(char *bytes, int64_t size,
 				       void (*bytes_free) (void *ptr))
 {
@@ -98,32 +147,129 @@
 	return avro_bytes_private((char *)bytes, size, NULL);
 }
 
-avro_datum_t avro_int(int32_t i)
+static int avro_bytes_set_private(avro_datum_t datum, const char *bytes,
+				  const int64_t size,
+				  void (*bytes_free) (void *ptr))
+{
+	struct avro_bytes_datum_t *b;
+
+	if (!(is_avro_datum(datum) && is_avro_bytes(datum))) {
+		return EINVAL;
+	}
+
+	b = avro_datum_to_bytes(datum);
+	if (b->free) {
+		b->free(b->bytes);
+	}
+
+	b->free = bytes_free;
+	b->bytes = (char *)bytes;
+	return 0;
+}
+
+int avro_bytes_set(avro_datum_t datum, const char *bytes, const int64_t size)
+{
+	int rval;
+	char *bytes_copy = malloc(size);
+	if (!bytes_copy) {
+		return ENOMEM;
+	}
+	memcpy(bytes_copy, bytes, size);
+	rval = avro_bytes_set_private(datum, bytes, size, free);
+	if (rval) {
+		free(bytes_copy);
+	}
+	return rval;
+}
+
+int avro_givebytes_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size)
+{
+	return avro_bytes_set_private(datum, bytes, size, free);
+}
+
+int avro_wrapbytes_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size)
+{
+	return avro_bytes_set_private(datum, bytes, size, NULL);
+}
+
+int avro_bytes_get(avro_datum_t datum, char **bytes, int64_t * size)
+{
+	if (!(is_avro_datum(datum) && is_avro_string(datum)) || !bytes || !size) {
+		return EINVAL;
+	}
+	*bytes = avro_datum_to_bytes(datum)->bytes;
+	*size = avro_datum_to_bytes(datum)->size;
+	return 0;
+}
+
+avro_datum_t avro_int32(int32_t i)
 {
-	struct avro_int_datum_t *datum =
-	    malloc(sizeof(struct avro_int_datum_t));
+	struct avro_int32_datum_t *datum =
+	    malloc(sizeof(struct avro_int32_datum_t));
 	if (!datum) {
 		return NULL;
 	}
-	datum->i = i;
+	datum->i32 = i;
 
-	avro_datum_init(&datum->obj, AVRO_INT);
+	avro_datum_init(&datum->obj, AVRO_INT32);
 	return &datum->obj;
 }
 
-avro_datum_t avro_long(int64_t l)
+int avro_int32_get(avro_datum_t datum, int32_t * i)
+{
+	if (!(is_avro_datum(datum) && is_avro_int32(datum)) || !i) {
+		return EINVAL;
+	}
+	*i = avro_datum_to_int32(datum)->i32;
+	return 0;
+}
+
+int avro_int32_set(avro_datum_t datum, const int32_t i)
+{
+	struct avro_int32_datum_t *intp;
+	if (!(is_avro_datum(datum) && is_avro_int32(datum))) {
+		return EINVAL;
+	}
+	intp = avro_datum_to_int32(datum);
+	intp->i32 = i;
+	return 0;
+}
+
+avro_datum_t avro_int64(int64_t l)
 {
-	struct avro_long_datum_t *datum =
-	    malloc(sizeof(struct avro_long_datum_t));
+	struct avro_int64_datum_t *datum =
+	    malloc(sizeof(struct avro_int64_datum_t));
 	if (!datum) {
 		return NULL;
 	}
-	datum->l = l;
+	datum->i64 = l;
 
-	avro_datum_init(&datum->obj, AVRO_LONG);
+	avro_datum_init(&datum->obj, AVRO_INT64);
 	return &datum->obj;
 }
 
+int avro_int64_get(avro_datum_t datum, int64_t * l)
+{
+	if (!(is_avro_datum(datum) && is_avro_int64(datum)) || !l) {
+		return EINVAL;
+	}
+	*l = avro_datum_to_int64(datum)->i64;
+	return 0;
+}
+
+int avro_int64_set(avro_datum_t datum, const int64_t l)
+{
+	struct avro_int64_datum_t *longp;
+	if (!(is_avro_datum(datum) && is_avro_int64(datum))) {
+		return EINVAL;
+	}
+	longp = avro_datum_to_int64(datum);
+	longp->i64 = l;
+	return 0;
+}
+
 avro_datum_t avro_float(float f)
 {
 	struct avro_float_datum_t *datum =
@@ -137,6 +283,26 @@
 	return &datum->obj;
 }
 
+int avro_float_set(avro_datum_t datum, const float f)
+{
+	struct avro_float_datum_t *floatp;
+	if (!(is_avro_datum(datum) && is_avro_float(datum))) {
+		return EINVAL;
+	}
+	floatp = avro_datum_to_float(datum);
+	floatp->f = f;
+	return 0;
+}
+
+int avro_float_get(avro_datum_t datum, float *f)
+{
+	if (!(is_avro_datum(datum) && is_avro_float(datum)) || !f) {
+		return EINVAL;
+	}
+	*f = avro_datum_to_float(datum)->f;
+	return 0;
+}
+
 avro_datum_t avro_double(double d)
 {
 	struct avro_double_datum_t *datum =
@@ -150,6 +316,26 @@
 	return &datum->obj;
 }
 
+int avro_double_set(avro_datum_t datum, const double d)
+{
+	struct avro_double_datum_t *doublep;
+	if (!(is_avro_datum(datum) && is_avro_double(datum))) {
+		return EINVAL;
+	}
+	doublep = avro_datum_to_double(datum);
+	doublep->d = d;
+	return 0;
+}
+
+int avro_double_get(avro_datum_t datum, double *d)
+{
+	if (!(is_avro_datum(datum) && is_avro_double(datum)) || !d) {
+		return EINVAL;
+	}
+	*d = avro_datum_to_double(datum)->d;
+	return 0;
+}
+
 avro_datum_t avro_boolean(int8_t i)
 {
 	struct avro_boolean_datum_t *datum =
@@ -162,6 +348,26 @@
 	return &datum->obj;
 }
 
+int avro_boolean_set(avro_datum_t datum, const int8_t i)
+{
+	struct avro_boolean_datum_t *booleanp;
+	if (!(is_avro_datum(datum) && is_avro_boolean(datum))) {
+		return EINVAL;
+	}
+	booleanp = avro_datum_to_boolean(datum);
+	booleanp->i = i;
+	return 0;
+}
+
+int avro_boolean_get(avro_datum_t datum, int8_t * i)
+{
+	if (!(is_avro_datum(datum) && is_avro_boolean(datum)) || !i) {
+		return EINVAL;
+	}
+	*i = avro_datum_to_boolean(datum)->i;
+	return 0;
+}
+
 avro_datum_t avro_null(void)
 {
 	static struct avro_obj_t obj = {
@@ -289,6 +495,63 @@
 	return avro_fixed_private(name, bytes, size, free);
 }
 
+static int avro_fixed_set_private(avro_datum_t datum, const char *bytes,
+				  const int64_t size,
+				  void (*fixed_free) (void *ptr))
+{
+	struct avro_fixed_datum_t *fixed;
+
+	if (!(is_avro_datum(datum) && is_avro_fixed(datum))) {
+		return EINVAL;
+	}
+
+	fixed = avro_datum_to_fixed(datum);
+	if (fixed->free) {
+		fixed->free(fixed->bytes);
+	}
+
+	fixed->free = fixed_free;
+	fixed->bytes = (char *)bytes;
+	return 0;
+}
+
+int avro_fixed_set(avro_datum_t datum, const char *bytes, const int64_t size)
+{
+	int rval;
+	char *bytes_copy = malloc(size);
+	if (!bytes_copy) {
+		return ENOMEM;
+	}
+	memcpy(bytes_copy, bytes, size);
+	rval = avro_fixed_set_private(datum, bytes, size, free);
+	if (rval) {
+		free(bytes_copy);
+	}
+	return rval;
+}
+
+int avro_givefixed_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size)
+{
+	return avro_fixed_set_private(datum, bytes, size, free);
+}
+
+int avro_wrapfixed_set(avro_datum_t datum, const char *bytes,
+		       const int64_t size)
+{
+	return avro_fixed_set_private(datum, bytes, size, NULL);
+}
+
+int avro_fixed_get(avro_datum_t datum, char **bytes, int64_t * size)
+{
+	if (!(is_avro_datum(datum) && is_avro_string(datum)) || !bytes || !size) {
+		return EINVAL;
+	}
+	*bytes = avro_datum_to_fixed(datum)->bytes;
+	*size = avro_datum_to_fixed(datum)->size;
+	return 0;
+}
+
 avro_datum_t avro_map(void)
 {
 	struct avro_map_datum_t *datum =
@@ -395,15 +658,15 @@
 				free(bytes);
 			}
 			break;
-		case AVRO_INT:{
-				struct avro_int_datum_t *i;
-				i = avro_datum_to_int(datum);
+		case AVRO_INT32:{
+				struct avro_int32_datum_t *i;
+				i = avro_datum_to_int32(datum);
 				free(i);
 			}
 			break;
-		case AVRO_LONG:{
-				struct avro_long_datum_t *l;
-				l = avro_datum_to_long(datum);
+		case AVRO_INT64:{
+				struct avro_int64_datum_t *l;
+				l = avro_datum_to_int64(datum);
 				free(l);
 			}
 			break;

Modified: hadoop/avro/trunk/lang/c/src/datum.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum.h?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum.h (original)
+++ hadoop/avro/trunk/lang/c/src/datum.h Tue Jan 26 00:31:08 2010
@@ -35,14 +35,14 @@
 	void (*free) (void *ptr);
 };
 
-struct avro_int_datum_t {
+struct avro_int32_datum_t {
 	struct avro_obj_t obj;
-	int32_t i;
+	int32_t i32;
 };
 
-struct avro_long_datum_t {
+struct avro_int64_datum_t {
 	struct avro_obj_t obj;
-	int64_t l;
+	int64_t i64;
 };
 
 struct avro_float_datum_t {
@@ -98,8 +98,8 @@
 
 #define avro_datum_to_string(datum_)    (container_of(datum_, struct avro_string_datum_t, obj))
 #define avro_datum_to_bytes(datum_)     (container_of(datum_, struct avro_bytes_datum_t, obj))
-#define avro_datum_to_int(datum_)       (container_of(datum_, struct avro_int_datum_t, obj))
-#define avro_datum_to_long(datum_)      (container_of(datum_, struct avro_long_datum_t, obj))
+#define avro_datum_to_int32(datum_)     (container_of(datum_, struct avro_int32_datum_t, obj))
+#define avro_datum_to_int64(datum_)     (container_of(datum_, struct avro_int64_datum_t, obj))
 #define avro_datum_to_float(datum_)     (container_of(datum_, struct avro_float_datum_t, obj))
 #define avro_datum_to_double(datum_)    (container_of(datum_, struct avro_double_datum_t, obj))
 #define avro_datum_to_boolean(datum_)   (container_of(datum_, struct avro_boolean_datum_t, obj))

Modified: hadoop/avro/trunk/lang/c/src/datum_equal.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_equal.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_equal.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_equal.c Tue Jan 26 00:31:08 2010
@@ -113,10 +113,12 @@
 		    && memcmp(avro_datum_to_bytes(a)->bytes,
 			      avro_datum_to_bytes(b)->bytes,
 			      avro_datum_to_bytes(a)->size) == 0;
-	case AVRO_INT:
-		return avro_datum_to_int(a)->i == avro_datum_to_int(b)->i;
-	case AVRO_LONG:
-		return avro_datum_to_long(a)->l == avro_datum_to_long(b)->l;
+	case AVRO_INT32:
+		return avro_datum_to_int32(a)->i32 ==
+		    avro_datum_to_int32(b)->i32;
+	case AVRO_INT64:
+		return avro_datum_to_int64(a)->i64 ==
+		    avro_datum_to_int64(b)->i64;
 	case AVRO_FLOAT:
 		return avro_datum_to_float(a)->f == avro_datum_to_float(b)->f;
 	case AVRO_DOUBLE:

Modified: hadoop/avro/trunk/lang/c/src/datum_read.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_read.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_read.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_read.c Tue Jan 26 00:31:08 2010
@@ -32,14 +32,14 @@
 	case AVRO_UNION:
 		return 1;
 
-	case AVRO_INT:
-		return is_avro_int(readers_schema)
-		    || is_avro_long(readers_schema)
+	case AVRO_INT32:
+		return is_avro_int32(readers_schema)
+		    || is_avro_int64(readers_schema)
 		    || is_avro_float(readers_schema)
 		    || is_avro_double(readers_schema);
 
-	case AVRO_LONG:
-		return is_avro_long(readers_schema)
+	case AVRO_INT64:
+		return is_avro_int64(readers_schema)
 		    || is_avro_float(readers_schema)
 		    || is_avro_double(readers_schema);
 
@@ -353,22 +353,22 @@
 		}
 		break;
 
-	case AVRO_INT:
+	case AVRO_INT32:
 		{
 			int32_t i;
 			rval = enc->read_int(reader, &i);
 			if (!rval) {
-				*datum = avro_int(i);
+				*datum = avro_int32(i);
 			}
 		}
 		break;
 
-	case AVRO_LONG:
+	case AVRO_INT64:
 		{
 			int64_t l;
 			rval = enc->read_long(reader, &l);
 			if (!rval) {
-				*datum = avro_long(l);
+				*datum = avro_int64(l);
 			}
 		}
 		break;

Modified: hadoop/avro/trunk/lang/c/src/datum_validate.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_validate.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_validate.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_validate.c Tue Jan 26 00:31:08 2010
@@ -57,21 +57,21 @@
 	case AVRO_BYTES:
 		return is_avro_bytes(datum);
 
-	case AVRO_INT:
-		return is_avro_int(datum)
-		    || (is_avro_long(datum)
-			&& (INT_MIN <= avro_datum_to_long(datum)->l
-			    && avro_datum_to_long(datum)->l <= INT_MAX));
+	case AVRO_INT32:
+		return is_avro_int32(datum)
+		    || (is_avro_int64(datum)
+			&& (INT_MIN <= avro_datum_to_int64(datum)->i64
+			    && avro_datum_to_int64(datum)->i64 <= INT_MAX));
 
-	case AVRO_LONG:
-		return is_avro_int(datum) || is_avro_long(datum);
+	case AVRO_INT64:
+		return is_avro_int32(datum) || is_avro_int64(datum);
 
 	case AVRO_FLOAT:
-		return is_avro_int(datum) || is_avro_long(datum)
+		return is_avro_int32(datum) || is_avro_int64(datum)
 		    || is_avro_float(datum);
 
 	case AVRO_DOUBLE:
-		return is_avro_int(datum) || is_avro_long(datum)
+		return is_avro_int32(datum) || is_avro_int64(datum)
 		    || is_avro_float(datum) || is_avro_double(datum);
 
 	case AVRO_FIXED:

Modified: hadoop/avro/trunk/lang/c/src/datum_write.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_write.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_write.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_write.c Tue Jan 26 00:31:08 2010
@@ -181,13 +181,13 @@
 		    enc->write_bytes(writer, avro_datum_to_bytes(datum)->bytes,
 				     avro_datum_to_bytes(datum)->size);
 		break;
-	case AVRO_INT:
+	case AVRO_INT32:
 		{
 			int32_t i;
-			if (is_avro_int(datum)) {
-				i = avro_datum_to_int(datum)->i;
-			} else if (is_avro_long(datum)) {
-				i = (int32_t) avro_datum_to_long(datum)->l;
+			if (is_avro_int32(datum)) {
+				i = avro_datum_to_int32(datum)->i32;
+			} else if (is_avro_int64(datum)) {
+				i = (int32_t) avro_datum_to_int64(datum)->i64;
 			} else {
 				assert(0
 				       &&
@@ -196,16 +196,16 @@
 			rval = enc->write_int(writer, i);
 		}
 		break;
-	case AVRO_LONG:
-		rval = enc->write_long(writer, avro_datum_to_long(datum)->l);
+	case AVRO_INT64:
+		rval = enc->write_long(writer, avro_datum_to_int64(datum)->i64);
 		break;
 	case AVRO_FLOAT:
 		{
 			float f;
-			if (is_avro_int(datum)) {
-				f = (float)(avro_datum_to_int(datum)->i);
-			} else if (is_avro_long(datum)) {
-				f = (float)(avro_datum_to_long(datum)->l);
+			if (is_avro_int32(datum)) {
+				f = (float)(avro_datum_to_int32(datum)->i32);
+			} else if (is_avro_int64(datum)) {
+				f = (float)(avro_datum_to_int64(datum)->i64);
 			} else if (is_avro_float(datum)) {
 				f = avro_datum_to_float(datum)->f;
 			} else if (is_avro_double(datum)) {
@@ -221,10 +221,10 @@
 	case AVRO_DOUBLE:
 		{
 			double d;
-			if (is_avro_int(datum)) {
-				d = (double)(avro_datum_to_int(datum)->i);
-			} else if (is_avro_long(datum)) {
-				d = (double)(avro_datum_to_long(datum)->l);
+			if (is_avro_int32(datum)) {
+				d = (double)(avro_datum_to_int32(datum)->i32);
+			} else if (is_avro_int64(datum)) {
+				d = (double)(avro_datum_to_int64(datum)->i64);
 			} else if (is_avro_float(datum)) {
 				d = (double)(avro_datum_to_float(datum)->f);
 			} else if (is_avro_double(datum)) {

Modified: hadoop/avro/trunk/lang/c/src/schema.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/schema.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/schema.c (original)
+++ hadoop/avro/trunk/lang/c/src/schema.c Tue Jan 26 00:31:08 2010
@@ -64,8 +64,8 @@
 		switch (avro_typeof(schema)) {
 		case AVRO_STRING:
 		case AVRO_BYTES:
-		case AVRO_INT:
-		case AVRO_LONG:
+		case AVRO_INT32:
+		case AVRO_INT64:
 		case AVRO_FLOAT:
 		case AVRO_DOUBLE:
 		case AVRO_BOOLEAN:
@@ -195,7 +195,7 @@
 avro_schema_t avro_schema_int(void)
 {
 	static struct avro_obj_t obj = {
-		.type = AVRO_INT,
+		.type = AVRO_INT32,
 		.class_type = AVRO_SCHEMA,
 		.refcount = 1
 	};
@@ -205,7 +205,7 @@
 avro_schema_t avro_schema_long(void)
 {
 	static struct avro_obj_t obj = {
-		.type = AVRO_LONG,
+		.type = AVRO_INT64,
 		.class_type = AVRO_SCHEMA,
 		.refcount = 1
 	};
@@ -468,9 +468,9 @@
 	} else if (strcmp(type_str, "bytes") == 0) {
 		*type = AVRO_BYTES;
 	} else if (strcmp(type_str, "int") == 0) {
-		*type = AVRO_INT;
+		*type = AVRO_INT32;
 	} else if (strcmp(type_str, "long") == 0) {
-		*type = AVRO_LONG;
+		*type = AVRO_INT64;
 	} else if (strcmp(type_str, "float") == 0) {
 		*type = AVRO_FLOAT;
 	} else if (strcmp(type_str, "double") == 0) {
@@ -522,11 +522,11 @@
 		*schema = avro_schema_bytes();
 		break;
 
-	case AVRO_INT:
+	case AVRO_INT32:
 		*schema = avro_schema_int();
 		break;
 
-	case AVRO_LONG:
+	case AVRO_INT64:
 		*schema = avro_schema_long();
 		break;
 
@@ -804,8 +804,8 @@
 	switch (avro_typeof(schema)) {
 	case AVRO_STRING:
 	case AVRO_BYTES:
-	case AVRO_INT:
-	case AVRO_LONG:
+	case AVRO_INT32:
+	case AVRO_INT64:
 	case AVRO_FLOAT:
 	case AVRO_DOUBLE:
 	case AVRO_BOOLEAN:

Modified: hadoop/avro/trunk/lang/c/src/schema_printf.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/schema_printf.c?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/schema_printf.c (original)
+++ hadoop/avro/trunk/lang/c/src/schema_printf.c Tue Jan 26 00:31:08 2010
@@ -152,9 +152,9 @@
 		avro_schema_primitive_print("string", args);
 	} else if (is_avro_bytes(schema)) {
 		avro_schema_primitive_print("bytes", args);
-	} else if (is_avro_int(schema)) {
+	} else if (is_avro_int32(schema)) {
 		avro_schema_primitive_print("int", args);
-	} else if (is_avro_long(schema)) {
+	} else if (is_avro_int64(schema)) {
 		avro_schema_primitive_print("long", args);
 	} else if (is_avro_float(schema)) {
 		avro_schema_primitive_print("float", args);

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=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_data.c Tue Jan 26 00:31:08 2010
@@ -16,6 +16,7 @@
  */
 #include <stdlib.h>
 #include <stdint.h>
+#include <limits.h>
 #include <time.h>
 #include <string.h>
 #include "avro.h"
@@ -26,6 +27,27 @@
 
 typedef int (*avro_test) (void);
 
+void init_rand(void)
+{
+	srand(time(NULL));
+}
+
+double rand_number(double from, double to)
+{
+	double range = to - from;
+	return from + ((double)rand() / (RAND_MAX + 1.0)) * range;
+}
+
+int64_t rand_int64(void)
+{
+	return (int64_t) rand_number(LONG_MIN, LONG_MAX);
+}
+
+int32_t rand_int32(void)
+{
+	return (int32_t) rand_number(INT_MIN, INT_MAX);
+}
+
 void
 write_read_check(avro_schema_t writers_schema,
 		 avro_schema_t readers_schema, avro_datum_t datum, char *type)
@@ -82,12 +104,12 @@
 	return 0;
 }
 
-static int test_int(void)
+static int test_int32(void)
 {
 	int i;
 	avro_schema_t writer_schema = avro_schema_int();
 	for (i = 0; i < 100; i++) {
-		avro_datum_t datum = avro_int(rand());
+		avro_datum_t datum = avro_int32(rand_int32());
 		write_read_check(writer_schema, NULL, datum, "int");
 		avro_datum_decref(datum);
 	}
@@ -95,12 +117,12 @@
 	return 0;
 }
 
-static int test_long(void)
+static int test_int64(void)
 {
 	int i;
 	avro_schema_t writer_schema = avro_schema_long();
 	for (i = 0; i < 100; i++) {
-		avro_datum_t datum = avro_long(rand());
+		avro_datum_t datum = avro_int64(rand_int64());
 		write_read_check(writer_schema, NULL, datum, "long");
 		avro_datum_decref(datum);
 	}
@@ -113,7 +135,7 @@
 	int i;
 	avro_schema_t schema = avro_schema_double();
 	for (i = 0; i < 100; i++) {
-		avro_datum_t datum = avro_double((double)(rand()));
+		avro_datum_t datum = avro_double(rand_number(-1.0E10, 1.0E10));
 		write_read_check(schema, NULL, datum, "double");
 		avro_datum_decref(datum);
 	}
@@ -126,7 +148,7 @@
 	int i;
 	avro_schema_t schema = avro_schema_double();
 	for (i = 0; i < 100; i++) {
-		avro_datum_t datum = avro_double((double)(rand()));
+		avro_datum_t datum = avro_double(rand_number(-1.0E10, 1.0E10));
 		write_read_check(schema, NULL, datum, "float");
 		avro_datum_decref(datum);
 	}
@@ -166,7 +188,7 @@
 
 	avro_record_field_set(datum, "name",
 			      avro_wrapstring("Joseph Campbell"));
-	avro_record_field_set(datum, "age", avro_int(83));
+	avro_record_field_set(datum, "age", avro_int32(83));
 
 	write_read_check(schema, NULL, datum, "record");
 
@@ -199,7 +221,7 @@
 	avro_datum_t datum = avro_array();
 
 	for (i = 0; i < 10; i++) {
-		rval = avro_array_append_datum(datum, avro_int(i));
+		rval = avro_array_append_datum(datum, avro_int32(i));
 		if (rval) {
 			exit(rval);
 		}
@@ -218,7 +240,7 @@
 	char *nums[] =
 	    { "zero", "one", "two", "three", "four", "five", "six", NULL };
 	while (nums[i]) {
-		avro_map_set(datum, nums[i], avro_long(i));
+		avro_map_set(datum, nums[i], avro_int64(i));
 		i++;
 	}
 	write_read_check(schema, NULL, datum, "map");
@@ -265,8 +287,8 @@
 		{
 		"string", test_string}, {
 		"bytes", test_bytes}, {
-		"int", test_int}, {
-		"long", test_long}, {
+		"int", test_int32}, {
+		"long", test_int64}, {
 		"float", test_float}, {
 		"double", test_double}, {
 		"boolean", test_boolean}, {
@@ -279,7 +301,7 @@
 		"union", test_union}
 	};
 
-	srandom(time(NULL));
+	init_rand();
 	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
 		struct avro_tests *test = tests + i;
 		fprintf(stderr, "**** Running %s tests ****\n", test->name);

Modified: hadoop/avro/trunk/lang/c/version.sh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/version.sh?rev=903028&r1=903027&r2=903028&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/version.sh (original)
+++ hadoop/avro/trunk/lang/c/version.sh Tue Jan 26 00:31:08 2010
@@ -18,7 +18,7 @@
 #         libavro_binary_age = 0
 #         libavro_interface_age = 0
 #
-libavro_micro_version=11
+libavro_micro_version=12
 libavro_interface_age=0
 libavro_binary_age=0