You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/08/25 20:46:07 UTC
svn commit: r989288 - in /avro/trunk/lang/c: ./ examples/ src/ tests/
tests/linux/ tests/windows/
Author: cutting
Date: Wed Aug 25 18:46:06 2010
New Revision: 989288
URL: http://svn.apache.org/viewvc?rev=989288&view=rev
Log:
Reverting revisions 949400, 947962, 947389, 947385, and 947299 in preparation for 1.4.0 branch. Re-opening AVRO-441, AVRO-464, AVRO-466, AVRO-549, and AVRO-552.
Removed:
avro/trunk/lang/c/src/allocator.c
avro/trunk/lang/c/src/allocator.h
avro/trunk/lang/c/src/allocator_system.c
avro/trunk/lang/c/src/allocator_system.h
avro/trunk/lang/c/src/atom_table.c
avro/trunk/lang/c/src/avro.c
avro/trunk/lang/c/src/config.h
avro/trunk/lang/c/src/types.h
avro/trunk/lang/c/tests/dir_iterator.h
avro/trunk/lang/c/tests/linux/
avro/trunk/lang/c/tests/windows/
Modified:
avro/trunk/lang/c/CMakeLists.txt
avro/trunk/lang/c/examples/quickstop.c
avro/trunk/lang/c/src/CMakeLists.txt
avro/trunk/lang/c/src/Makefile.am
avro/trunk/lang/c/src/avro.h
avro/trunk/lang/c/src/datafile.c
avro/trunk/lang/c/src/datum.c
avro/trunk/lang/c/src/datum.h
avro/trunk/lang/c/src/datum_equal.c
avro/trunk/lang/c/src/datum_read.c
avro/trunk/lang/c/src/datum_size.c
avro/trunk/lang/c/src/datum_validate.c
avro/trunk/lang/c/src/datum_write.c
avro/trunk/lang/c/src/dump.h
avro/trunk/lang/c/src/encoding_binary.c
avro/trunk/lang/c/src/io.c
avro/trunk/lang/c/src/schema.c
avro/trunk/lang/c/src/schema.h
avro/trunk/lang/c/src/schema_equal.c
avro/trunk/lang/c/src/st.c
avro/trunk/lang/c/src/st.h
avro/trunk/lang/c/tests/CMakeLists.txt
avro/trunk/lang/c/tests/generate_interop_data.c
avro/trunk/lang/c/tests/test_avro_data.c
avro/trunk/lang/c/tests/test_avro_schema.c
avro/trunk/lang/c/tests/test_interop_data.c
Modified: avro/trunk/lang/c/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/CMakeLists.txt?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/CMakeLists.txt (original)
+++ avro/trunk/lang/c/CMakeLists.txt Wed Aug 25 18:46:06 2010
@@ -36,8 +36,6 @@ add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tests)
-if(NOT WIN32)
add_custom_target(pretty
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake_pretty.cmake")
-endif()
Modified: avro/trunk/lang/c/examples/quickstop.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/examples/quickstop.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/examples/quickstop.c (original)
+++ avro/trunk/lang/c/examples/quickstop.c Wed Aug 25 18:46:06 2010
@@ -19,22 +19,11 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
-#ifndef WIN32
#include <unistd.h>
-#endif
avro_schema_t person_schema;
int64_t id = 0;
-struct atom_holder {
- avro_atom_t id;
- avro_atom_t first;
- avro_atom_t last;
- avro_atom_t phone;
- avro_atom_t age;
-};
-struct atom_holder atoms;
-
/* A simple schema for our tutorial */
#define PERSON_SCHEMA \
"{\"type\":\"record\",\
@@ -57,24 +46,6 @@ void init_schema(void)
}
}
-void init_atoms(void)
-{
- atoms.id = avro_atom_add("ID");
- atoms.first = avro_atom_add("First");
- atoms.last = avro_atom_add("Last");
- atoms.phone = avro_atom_add("Phone");
- atoms.age = avro_atom_add("Age");
-}
-
-void cleanup_atoms(void)
-{
- avro_atom_decref(atoms.id);
- avro_atom_decref(atoms.first);
- avro_atom_decref(atoms.last);
- avro_atom_decref(atoms.phone);
- avro_atom_decref(atoms.age);
-}
-
/* Create a datum to match the person schema and save it */
void
add_person(avro_file_writer_t db, const char *first, const char *last,
@@ -88,11 +59,11 @@ add_person(avro_file_writer_t db, const
avro_datum_t age_datum = avro_int32(age);
avro_datum_t phone_datum = avro_string(phone);
- if (avro_record_set(person, atoms.id, id_datum)
- || avro_record_set(person, atoms.first, first_datum)
- || avro_record_set(person, atoms.last, last_datum)
- || avro_record_set(person, atoms.age, age_datum)
- || avro_record_set(person, atoms.phone, phone_datum)) {
+ if (avro_record_set(person, "ID", id_datum)
+ || avro_record_set(person, "First", first_datum)
+ || avro_record_set(person, "Last", last_datum)
+ || avro_record_set(person, "Age", age_datum)
+ || avro_record_set(person, "Phone", phone_datum)) {
fprintf(stderr, "Unable to create Person datum structure");
exit(EXIT_FAILURE);
}
@@ -127,23 +98,23 @@ int print_person(avro_file_reader_t db,
avro_datum_t id_datum, first_datum, last_datum, phone_datum,
age_datum;
- if (avro_record_get(person, atoms.id, &id_datum) == 0) {
+ if (avro_record_get(person, "ID", &id_datum) == 0) {
avro_int64_get(id_datum, &i64);
fprintf(stdout, "%"PRId64" | ", i64);
}
- if (avro_record_get(person, atoms.first, &first_datum) == 0) {
+ if (avro_record_get(person, "First", &first_datum) == 0) {
avro_string_get(first_datum, &p);
fprintf(stdout, "%15s | ", p);
}
- if (avro_record_get(person, atoms.last, &last_datum) == 0) {
+ if (avro_record_get(person, "Last", &last_datum) == 0) {
avro_string_get(last_datum, &p);
fprintf(stdout, "%15s | ", p);
}
- if (avro_record_get(person, atoms.phone, &phone_datum) == 0) {
+ if (avro_record_get(person, "Phone", &phone_datum) == 0) {
avro_string_get(phone_datum, &p);
fprintf(stdout, "%15s | ", p);
}
- if (avro_record_get(person, atoms.age, &age_datum) == 0) {
+ if (avro_record_get(person, "Age", &age_datum) == 0) {
avro_int32_get(age_datum, &i32);
fprintf(stdout, "%d", i32);
}
@@ -164,16 +135,9 @@ int main(void)
int64_t i;
const char *dbname = "quickstop.db";
- avro_init();
-
- /* Initialize our atoms */
- init_atoms();
-
/* Initialize the schema structure from JSON */
init_schema();
- fprintf(stdout, "Let's create our initial database\n");
-
/* Delete the database if it exists */
unlink(dbname);
/* Create a new database */
@@ -232,8 +196,5 @@ int main(void)
/* We don't need this schema anymore */
avro_schema_decref(person_schema);
-
- cleanup_atoms();
- avro_shutdown();
return 0;
}
Modified: avro/trunk/lang/c/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/CMakeLists.txt?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/CMakeLists.txt (original)
+++ avro/trunk/lang/c/src/CMakeLists.txt Wed Aug 25 18:46:06 2010
@@ -18,15 +18,8 @@
#
set(AVRO_SRC
- allocator.c
- allocator.h
- allocator_system.c
- allocator_system.h
- atom_table.c
- avro.c
avro.h
avro_private.h
- config.h
datafile.c
datum.c
datum.h
@@ -46,7 +39,6 @@ set(AVRO_SRC
schema_equal.c
st.c
st.h
- types.h
)
set(JANSSON_SRC
@@ -69,24 +61,15 @@ source_group(Jansson FILES ${JANSSON_SRC
add_library(avro-static STATIC ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-static PROPERTIES OUTPUT_NAME avro)
-
add_library(avro-shared SHARED ${AVRO_SRC} ${JANSSON_SRC})
set_target_properties(avro-shared PROPERTIES
- OUTPUT_NAME avro
- SOVERSION ${AVRO_VERSION}
-)
+ OUTPUT_NAME avro
+ SOVERSION ${AVRO_VERSION})
-if(MSVC)
- set_target_properties(avro-static avro-shared PROPERTIES
- COMPILE_DEFINITIONS "_CRT_SECURE_NO_WARNINGS"
- )
-endif()
-
-if(NOT WIN32)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/avro.h DESTINATION include)
install(TARGETS avro-static avro-shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
-endif()
+
Modified: avro/trunk/lang/c/src/Makefile.am
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/Makefile.am?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/Makefile.am (original)
+++ avro/trunk/lang/c/src/Makefile.am Wed Aug 25 18:46:06 2010
@@ -8,8 +8,8 @@ include_HEADERS = avro.h
lib_LTLIBRARIES = libavro.la
libavro_la_SOURCES = st.c st.h schema.c schema.h schema_equal.c \
datum.c datum_equal.c datum_validate.c datum_read.c datum_skip.c datum_write.c datum_size.c datum.h \
-io.c dump.c dump.h encoding_binary.c allocator.c allocator_system.c \
-avro_private.h encoding.h datafile.c atom_table.c avro.c
+io.c dump.c dump.h encoding_binary.c \
+avro_private.h encoding.h datafile.c
libavro_la_LIBADD = $(top_builddir)/jansson/src/.libs/libjansson.a
libavro_la_LDFLAGS = \
-version-info $(LIBAVRO_VERSION) \
Modified: avro/trunk/lang/c/src/avro.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/avro.h?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/avro.h (original)
+++ avro/trunk/lang/c/src/avro.h Wed Aug 25 18:46:06 2010
@@ -24,9 +24,7 @@ extern "C" {
#endif
#include <stdio.h>
-#include "types.h"
-
-typedef int32_t avro_atom_t;
+#include <stdint.h>
enum avro_type_t {
AVRO_STRING,
@@ -96,12 +94,6 @@ typedef struct avro_reader_t_ *avro_read
typedef struct avro_writer_t_ *avro_writer_t;
/*
- * Initialize the underlying library and properly close things down
- */
-void avro_init(void);
-void avro_shutdown(void);
-
-/*
* schema
*/
typedef struct avro_obj_t *avro_schema_t;
@@ -117,7 +109,7 @@ avro_schema_t avro_schema_null(void);
avro_schema_t avro_schema_record(const char *name, const char *space);
avro_schema_t avro_schema_record_field_get(const avro_schema_t
- record, avro_atom_t field_name);
+ record, const char *field_name);
int avro_schema_record_field_append(const avro_schema_t record,
const char *field_name,
const avro_schema_t type);
@@ -201,7 +193,7 @@ avro_datum_t avro_givefixed(const char *
const int64_t size);
avro_datum_t avro_map(void);
avro_datum_t avro_array(void);
-avro_datum_t avro_union(int64_t discriminant, avro_datum_t datum);
+avro_datum_t avro_union(int64_t discriminant, const avro_datum_t datum);
/* getters */
int avro_string_get(avro_datum_t datum, char **p);
@@ -213,7 +205,7 @@ int avro_double_get(avro_datum_t datum,
int avro_boolean_get(avro_datum_t datum, int8_t * i);
int avro_fixed_get(avro_datum_t datum, char **bytes, int64_t * size);
-int avro_record_get(const avro_datum_t record, avro_atom_t field_name,
+int avro_record_get(const avro_datum_t record, const char *field_name,
avro_datum_t * value);
int avro_map_get(const avro_datum_t datum, const char *key,
avro_datum_t * value);
@@ -242,7 +234,7 @@ int avro_givefixed_set(avro_datum_t datu
int avro_wrapfixed_set(avro_datum_t datum, const char *bytes,
const int64_t size);
-int avro_record_set(const avro_datum_t record, avro_atom_t field_name,
+int avro_record_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);
@@ -255,7 +247,7 @@ void avro_datum_decref(avro_datum_t valu
void avro_datum_print(avro_datum_t value, FILE * fp);
-int avro_datum_equal(const avro_datum_t a, const avro_datum_t b);
+int avro_datum_equal(avro_datum_t a, avro_datum_t b);
int avro_schema_match(avro_schema_t writers_schema,
avro_schema_t readers_schema);
@@ -290,30 +282,5 @@ int avro_file_reader_read(avro_file_read
avro_schema_t readers_schema, avro_datum_t * datum);
int avro_file_reader_close(avro_file_reader_t reader);
-/* Atom handling */
-typedef struct avro_atom_table_t_ *avro_atom_table_t;
-extern avro_atom_table_t g_avro_atom_table;
-
-avro_atom_table_t avro_atom_table_create(int32_t);
-void avro_atom_table_destroy(avro_atom_table_t table);
-void avro_atom_table_dump(avro_atom_table_t table);
-
-avro_atom_t avro_atom_table_add(avro_atom_table_t table, const char *s);
-avro_atom_t avro_atom_table_add_length(avro_atom_table_t table, const char *s, int32_t length);
-avro_atom_t avro_atom_table_lookup(avro_atom_table_t table, const char *s, int32_t length);
-int avro_atom_table_describe(avro_atom_table_t table, avro_atom_t atom, const char **s, int32_t *length);
-const char *avro_atom_table_to_string(avro_atom_table_t table, avro_atom_t atom);
-
-avro_atom_t avro_atom_table_incref(avro_atom_table_t table, avro_atom_t atom);
-void avro_atom_table_decref(avro_atom_table_t table, avro_atom_t atom);
-
-#define avro_atom_add(s) avro_atom_table_add(g_avro_atom_table, s)
-#define avro_atom_add_length(s, length) avro_atom_table_add_length(g_avro_atom_table, s, length)
-#define avro_atom_lookup(s, length) avro_atom_table_lookup(g_avro_atom_table, s, length)
-#define avro_atom_describe(atom, s, length) avro_atom_table_describe(g_avro_atom_table, atom, s, length)
-#define avro_atom_to_string(atom) avro_atom_table_to_string(g_avro_atom_table, atom)
-#define avro_atom_incref(atom) avro_atom_table_incref(g_avro_atom_table, atom)
-#define avro_atom_decref(atom) avro_atom_table_decref(g_avro_atom_table, atom)
-
CLOSE_EXTERN
#endif
Modified: avro/trunk/lang/c/src/datafile.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Wed Aug 25 18:46:06 2010
@@ -17,7 +17,6 @@
#include "avro_private.h"
#include "encoding.h"
-#include "allocator.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -109,11 +108,7 @@ file_writer_init_fp(const char *path, co
static int
file_writer_create(const char *path, avro_schema_t schema, avro_file_writer_t w)
{
-#ifdef WIN32
- int rval = file_writer_init_fp(path, "w", w);
-#else
int rval = file_writer_init_fp(path, "wx", w);
-#endif
if (rval) {
check(rval, file_writer_init_fp(path, "w", w));
}
@@ -138,13 +133,13 @@ avro_file_writer_create(const char *path
if (!path || !is_avro_schema(schema) || !writer) {
return EINVAL;
}
- w = g_avro_allocator.malloc(sizeof(struct avro_file_writer_t_));
+ w = malloc(sizeof(struct avro_file_writer_t_));
if (!w) {
return ENOMEM;
}
rval = file_writer_create(path, schema, w);
if (rval) {
- g_avro_allocator.free(w);
+ free(w);
return rval;
}
*writer = w;
@@ -205,7 +200,7 @@ static int file_writer_open(const char *
/* Position to end of file and get ready to write */
rval = file_writer_init_fp(path, "a", w);
if (rval) {
- g_avro_allocator.free(w);
+ free(w);
}
return rval;
}
@@ -217,13 +212,13 @@ int avro_file_writer_open(const char *pa
if (!path || !writer) {
return EINVAL;
}
- w = g_avro_allocator.malloc(sizeof(struct avro_file_writer_t_));
+ w = malloc(sizeof(struct avro_file_writer_t_));
if (!w) {
return ENOMEM;
}
rval = file_writer_open(path, w);
if (rval) {
- g_avro_allocator.free(w);
+ free(w);
return rval;
}
@@ -245,7 +240,7 @@ int avro_file_reader(const char *path, a
{
int rval;
FILE *fp;
- avro_file_reader_t r = g_avro_allocator.malloc(sizeof(struct avro_file_reader_t_));
+ avro_file_reader_t r = malloc(sizeof(struct avro_file_reader_t_));
if (!r) {
return ENOMEM;
}
Modified: avro/trunk/lang/c/src/datum.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum.c (original)
+++ avro/trunk/lang/c/src/datum.c Wed Aug 25 18:46:06 2010
@@ -21,10 +21,7 @@
#include <errno.h>
#include "datum.h"
#include "encoding.h"
-#include "allocator.h"
-#define DEFAULT_ARRAY_SIZE 10
-#define DEFAULT_FIELD_COUNT 10
#define DEFAULT_TABLE_SIZE 32
static void avro_datum_init(avro_datum_t datum, avro_type_t type)
@@ -38,7 +35,7 @@ static avro_datum_t avro_string_private(
void (*string_free) (void *ptr))
{
struct avro_string_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_string_datum_t));
+ malloc(sizeof(struct avro_string_datum_t));
if (!datum) {
return NULL;
}
@@ -51,16 +48,16 @@ static avro_datum_t avro_string_private(
avro_datum_t avro_string(const char *str)
{
- char *p = avro_strdup(str);
+ char *p = strdup(str);
if (!p) {
return NULL;
}
- return avro_string_private(p, g_avro_allocator.free);
+ return avro_string_private(p, free);
}
avro_datum_t avro_givestring(const char *str)
{
- return avro_string_private((char *)str, g_avro_allocator.free);
+ return avro_string_private((char *)str, free);
}
avro_datum_t avro_wrapstring(const char *str)
@@ -95,21 +92,21 @@ static int avro_string_set_private(avro_
int avro_string_set(avro_datum_t datum, const char *p)
{
- char *string_copy = avro_strdup(p);
+ char *string_copy = strdup(p);
int rval;
if (!string_copy) {
return ENOMEM;
}
- rval = avro_string_set_private(datum, p, g_avro_allocator.free);
+ rval = avro_string_set_private(datum, p, free);
if (rval) {
- g_avro_allocator.free(string_copy);
+ free(string_copy);
}
return rval;
}
int avro_givestring_set(avro_datum_t datum, const char *p)
{
- return avro_string_set_private(datum, p, g_avro_allocator.free);
+ return avro_string_set_private(datum, p, free);
}
int avro_wrapstring_set(avro_datum_t datum, const char *p)
@@ -121,7 +118,7 @@ static avro_datum_t avro_bytes_private(c
void (*bytes_free) (void *ptr))
{
struct avro_bytes_datum_t *datum;
- datum = g_avro_allocator.malloc(sizeof(struct avro_bytes_datum_t));
+ datum = malloc(sizeof(struct avro_bytes_datum_t));
if (!datum) {
return NULL;
}
@@ -135,17 +132,17 @@ static avro_datum_t avro_bytes_private(c
avro_datum_t avro_bytes(const char *bytes, int64_t size)
{
- char *bytes_copy = g_avro_allocator.malloc(size);
+ char *bytes_copy = malloc(size);
if (!bytes_copy) {
return NULL;
}
memcpy(bytes_copy, bytes, size);
- return avro_bytes_private(bytes_copy, size, g_avro_allocator.free);
+ return avro_bytes_private(bytes_copy, size, free);
}
avro_datum_t avro_givebytes(const char *bytes, int64_t size)
{
- return avro_bytes_private((char *)bytes, size, g_avro_allocator.free);
+ return avro_bytes_private((char *)bytes, size, free);
}
avro_datum_t avro_wrapbytes(const char *bytes, int64_t size)
@@ -178,14 +175,14 @@ static int avro_bytes_set_private(avro_d
int avro_bytes_set(avro_datum_t datum, const char *bytes, const int64_t size)
{
int rval;
- char *bytes_copy = g_avro_allocator.malloc(size);
+ char *bytes_copy = malloc(size);
if (!bytes_copy) {
return ENOMEM;
}
memcpy(bytes_copy, bytes, size);
- rval = avro_bytes_set_private(datum, bytes, size, g_avro_allocator.free);
+ rval = avro_bytes_set_private(datum, bytes, size, free);
if (rval) {
- g_avro_allocator.free(bytes_copy);
+ free(bytes_copy);
}
return rval;
}
@@ -193,7 +190,7 @@ int avro_bytes_set(avro_datum_t datum, c
int avro_givebytes_set(avro_datum_t datum, const char *bytes,
const int64_t size)
{
- return avro_bytes_set_private(datum, bytes, size, g_avro_allocator.free);
+ return avro_bytes_set_private(datum, bytes, size, free);
}
int avro_wrapbytes_set(avro_datum_t datum, const char *bytes,
@@ -215,7 +212,7 @@ int avro_bytes_get(avro_datum_t datum, c
avro_datum_t avro_int32(int32_t i)
{
struct avro_int32_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_int32_datum_t));
+ malloc(sizeof(struct avro_int32_datum_t));
if (!datum) {
return NULL;
}
@@ -248,7 +245,7 @@ int avro_int32_set(avro_datum_t datum, c
avro_datum_t avro_int64(int64_t l)
{
struct avro_int64_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_int64_datum_t));
+ malloc(sizeof(struct avro_int64_datum_t));
if (!datum) {
return NULL;
}
@@ -281,7 +278,7 @@ int avro_int64_set(avro_datum_t datum, c
avro_datum_t avro_float(float f)
{
struct avro_float_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_float_datum_t));
+ malloc(sizeof(struct avro_float_datum_t));
if (!datum) {
return NULL;
}
@@ -314,7 +311,7 @@ int avro_float_get(avro_datum_t datum, f
avro_datum_t avro_double(double d)
{
struct avro_double_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_double_datum_t));
+ malloc(sizeof(struct avro_double_datum_t));
if (!datum) {
return NULL;
}
@@ -347,7 +344,7 @@ int avro_double_get(avro_datum_t datum,
avro_datum_t avro_boolean(int8_t i)
{
struct avro_boolean_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_boolean_datum_t));
+ malloc(sizeof(struct avro_boolean_datum_t));
if (!datum) {
return NULL;
}
@@ -379,9 +376,9 @@ int avro_boolean_get(avro_datum_t datum,
avro_datum_t avro_null(void)
{
static struct avro_obj_t obj = {
- AVRO_NULL, // type
- AVRO_DATUM, // class_type
- 1 // refcount
+ .type = AVRO_NULL,
+ .class_type = AVRO_DATUM,
+ .refcount = 1
};
return &obj;
}
@@ -389,7 +386,7 @@ avro_datum_t avro_null(void)
avro_datum_t avro_union(int64_t discriminant, avro_datum_t value)
{
struct avro_union_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_union_datum_t));
+ malloc(sizeof(struct avro_union_datum_t));
if (!datum) {
return NULL;
}
@@ -403,56 +400,54 @@ avro_datum_t avro_union(int64_t discrimi
avro_datum_t avro_record(const char *name, const char *space)
{
struct avro_record_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_record_datum_t));
+ malloc(sizeof(struct avro_record_datum_t));
if (!datum) {
return NULL;
}
- datum->name = avro_strdup(name);
+ datum->name = strdup(name);
if (!datum->name) {
- g_avro_allocator.free(datum);
+ free(datum);
return NULL;
}
- datum->space = space ? avro_strdup(space) : NULL;
+ datum->space = space ? strdup(space) : NULL;
if (space && !datum->space) {
- g_avro_allocator.free((void *)datum->name);
- g_avro_allocator.free((void *)datum);
+ free((void *)datum->name);
+ free((void *)datum);
return NULL;
}
- datum->alloc_fields = DEFAULT_FIELD_COUNT;
- datum->field_order = (avro_atom_t*)g_avro_allocator.malloc(datum->alloc_fields * sizeof(avro_atom_t));
+ datum->field_order = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
if (!datum->field_order) {
if (space) {
- g_avro_allocator.free((void *)datum->space);
+ free((void *)datum->space);
}
- g_avro_allocator.free((char *)datum->name);
- g_avro_allocator.free(datum);
+ free((char *)datum->name);
+ free(datum);
return NULL;
}
- datum->fields_byname = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
+ datum->fields_byname = st_init_strtable_with_size(DEFAULT_TABLE_SIZE);
if (!datum->fields_byname) {
- g_avro_allocator.free(datum->field_order);
+ st_free_table(datum->field_order);
if (space) {
- g_avro_allocator.free((void *)datum->space);
+ free((void *)datum->space);
}
- g_avro_allocator.free((char *)datum->name);
- g_avro_allocator.free(datum);
+ free((char *)datum->name);
+ free(datum);
return NULL;
}
- datum->num_fields = 0;
avro_datum_init(&datum->obj, AVRO_RECORD);
return &datum->obj;
}
int
-avro_record_get(const avro_datum_t datum, avro_atom_t field_name,
+avro_record_get(const avro_datum_t datum, const char *field_name,
avro_datum_t * field)
{
union {
avro_datum_t field;
st_data_t data;
} val;
- if (is_avro_datum(datum) && is_avro_record(datum)) {
+ if (is_avro_datum(datum) && is_avro_record(datum) && field_name) {
if (st_lookup
(avro_datum_to_record(datum)->fields_byname,
(st_data_t) field_name, &(val.data))) {
@@ -464,11 +459,13 @@ avro_record_get(const avro_datum_t datum
}
int
-avro_record_set(const avro_datum_t datum, avro_atom_t field_name,
+avro_record_set(const avro_datum_t datum, const char *field_name,
const avro_datum_t field_value)
{
+ char *key = (char *)field_name;
avro_datum_t old_field;
- if (is_avro_datum(datum) && is_avro_record(datum)) {
+
+ if (is_avro_datum(datum) && is_avro_record(datum) && field_name) {
if (avro_record_get(datum, field_name, &old_field) == 0) {
/* Overriding old value */
avro_datum_decref(old_field);
@@ -476,18 +473,17 @@ avro_record_set(const avro_datum_t datum
/* Inserting new value */
struct avro_record_datum_t *record =
avro_datum_to_record(datum);
- if ((record->num_fields + 1) > record->alloc_fields) {
- record->alloc_fields *= 2;
- record->field_order = (avro_atom_t*)g_avro_allocator.realloc(record->field_order,
- (record->alloc_fields) * sizeof(avro_atom_t));
- }
- avro_atom_incref(field_name);
- record->field_order[record->num_fields++] = field_name;
+ key = strdup(field_name);
+ if (!key) {
+ return ENOMEM;
+ }
+ st_insert(record->field_order,
+ record->field_order->num_entries,
+ (st_data_t) key);
}
avro_datum_incref(field_value);
- avro_atom_incref(field_name);
st_insert(avro_datum_to_record(datum)->fields_byname,
- (st_data_t) field_name, (st_data_t) field_value);
+ (st_data_t) key, (st_data_t) field_value);
return 0;
}
return EINVAL;
@@ -496,11 +492,11 @@ avro_record_set(const avro_datum_t datum
avro_datum_t avro_enum(const char *name, int i)
{
struct avro_enum_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_enum_datum_t));
+ malloc(sizeof(struct avro_enum_datum_t));
if (!datum) {
return NULL;
}
- datum->name = avro_strdup(name);
+ datum->name = strdup(name);
datum->value = i;
avro_datum_init(&datum->obj, AVRO_ENUM);
@@ -512,11 +508,11 @@ static avro_datum_t avro_fixed_private(c
void (*fixed_free) (void *ptr))
{
struct avro_fixed_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_fixed_datum_t));
+ malloc(sizeof(struct avro_fixed_datum_t));
if (!datum) {
return NULL;
}
- datum->name = avro_strdup(name);
+ datum->name = strdup(name);
datum->size = size;
datum->bytes = (char *)bytes;
datum->free = fixed_free;
@@ -527,12 +523,12 @@ static avro_datum_t avro_fixed_private(c
avro_datum_t avro_fixed(const char *name, const char *bytes, const int64_t size)
{
- char *bytes_copy = g_avro_allocator.malloc(size);
+ char *bytes_copy = malloc(size);
if (!bytes_copy) {
return NULL;
}
memcpy(bytes_copy, bytes, size);
- return avro_fixed_private(name, bytes, size, g_avro_allocator.free);
+ return avro_fixed_private(name, bytes, size, free);
}
avro_datum_t avro_wrapfixed(const char *name, const char *bytes,
@@ -544,7 +540,7 @@ avro_datum_t avro_wrapfixed(const char *
avro_datum_t avro_givefixed(const char *name, const char *bytes,
const int64_t size)
{
- return avro_fixed_private(name, bytes, size, g_avro_allocator.free);
+ return avro_fixed_private(name, bytes, size, free);
}
static int avro_fixed_set_private(avro_datum_t datum, const char *bytes,
@@ -572,14 +568,14 @@ static int avro_fixed_set_private(avro_d
int avro_fixed_set(avro_datum_t datum, const char *bytes, const int64_t size)
{
int rval;
- char *bytes_copy = g_avro_allocator.malloc(size);
+ char *bytes_copy = malloc(size);
if (!bytes_copy) {
return ENOMEM;
}
memcpy(bytes_copy, bytes, size);
- rval = avro_fixed_set_private(datum, bytes, size, g_avro_allocator.free);
+ rval = avro_fixed_set_private(datum, bytes, size, free);
if (rval) {
- g_avro_allocator.free(bytes_copy);
+ free(bytes_copy);
}
return rval;
}
@@ -587,7 +583,7 @@ int avro_fixed_set(avro_datum_t datum, c
int avro_givefixed_set(avro_datum_t datum, const char *bytes,
const int64_t size)
{
- return avro_fixed_set_private(datum, bytes, size, g_avro_allocator.free);
+ return avro_fixed_set_private(datum, bytes, size, free);
}
int avro_wrapfixed_set(avro_datum_t datum, const char *bytes,
@@ -609,13 +605,13 @@ int avro_fixed_get(avro_datum_t datum, c
avro_datum_t avro_map(void)
{
struct avro_map_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_map_datum_t));
+ malloc(sizeof(struct avro_map_datum_t));
if (!datum) {
return NULL;
}
datum->map = st_init_strtable_with_size(DEFAULT_TABLE_SIZE);
if (!datum->map) {
- g_avro_allocator.free(datum);
+ free(datum);
return NULL;
}
@@ -661,7 +657,7 @@ avro_map_set(const avro_datum_t datum, c
avro_datum_decref(old_datum);
} else {
/* Inserting a new value */
- save_key = avro_strdup(key);
+ save_key = strdup(key);
if (!save_key) {
return ENOMEM;
}
@@ -675,17 +671,15 @@ avro_map_set(const avro_datum_t datum, c
avro_datum_t avro_array(void)
{
struct avro_array_datum_t *datum =
- g_avro_allocator.malloc(sizeof(struct avro_array_datum_t));
+ malloc(sizeof(struct avro_array_datum_t));
if (!datum) {
return NULL;
}
- datum->alloc_els = DEFAULT_ARRAY_SIZE;
- datum->els = g_avro_allocator.malloc(datum->alloc_els * sizeof(avro_datum_t));
+ datum->els = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
if (!datum->els) {
- g_avro_allocator.free(datum);
+ free(datum);
return NULL;
}
- datum->num_els = 0;
avro_datum_init(&datum->obj, AVRO_ARRAY);
return &datum->obj;
@@ -694,14 +688,18 @@ avro_datum_t avro_array(void)
int
avro_array_get(const avro_datum_t array_datum, int64_t index, avro_datum_t * value)
{
- if (is_avro_datum(array_datum) && is_avro_array(array_datum) && (index >= 0)) {
- const struct avro_array_datum_t * array = avro_datum_to_array(array_datum);
- if ((index >= 0) && (index < array->num_els)) {
- *value = array->els[index];
- return 0;
- }
- }
- return EINVAL;
+ union {
+ st_data_t data;
+ avro_datum_t datum;
+ } val;
+ if (is_avro_datum(array_datum) && is_avro_array(array_datum)) {
+ const struct avro_array_datum_t * array = avro_datum_to_array(array_datum);
+ if (st_lookup(array->els, index, &val.data)) {
+ *value = val.datum;
+ return 0;
+ }
+ }
+ return EINVAL;
}
int
@@ -714,30 +712,26 @@ avro_array_append_datum(const avro_datum
return EINVAL;
}
array = avro_datum_to_array(array_datum);
- if ((array->num_els + 1) > array->alloc_els) {
- array->alloc_els *= 2;
- array->els = (avro_datum_t *)g_avro_allocator.realloc(array->els,
- (array->alloc_els) * sizeof(avro_datum_t));
- }
- array->els[array->num_els++] = avro_datum_incref(datum);
+ st_insert(array->els, array->els->num_entries,
+ (st_data_t) avro_datum_incref(datum));
return 0;
}
-static int atom_datum_free_foreach(avro_atom_t key, avro_datum_t datum, void *arg)
+static int char_datum_free_foreach(char *key, avro_datum_t datum, void *arg)
{
AVRO_UNUSED(arg);
avro_datum_decref(datum);
- avro_atom_decref(key);
+ free(key);
return ST_DELETE;
}
-static int char_datum_free_foreach(char *key, avro_datum_t datum, void *arg)
+static int array_free_foreach(int i, avro_datum_t datum, void *arg)
{
+ AVRO_UNUSED(i);
AVRO_UNUSED(arg);
avro_datum_decref(datum);
- g_avro_allocator.free(key);
return ST_DELETE;
}
@@ -751,7 +745,7 @@ static void avro_datum_free(avro_datum_t
if (string->free) {
string->free(string->s);
}
- g_avro_allocator.free(string);
+ free(string);
}
break;
case AVRO_BYTES:{
@@ -760,37 +754,37 @@ static void avro_datum_free(avro_datum_t
if (bytes->free) {
bytes->free(bytes->bytes);
}
- g_avro_allocator.free(bytes);
+ free(bytes);
}
break;
case AVRO_INT32:{
struct avro_int32_datum_t *i;
i = avro_datum_to_int32(datum);
- g_avro_allocator.free(i);
+ free(i);
}
break;
case AVRO_INT64:{
struct avro_int64_datum_t *l;
l = avro_datum_to_int64(datum);
- g_avro_allocator.free(l);
+ free(l);
}
break;
case AVRO_FLOAT:{
struct avro_float_datum_t *f;
f = avro_datum_to_float(datum);
- g_avro_allocator.free(f);
+ free(f);
}
break;
case AVRO_DOUBLE:{
struct avro_double_datum_t *d;
d = avro_datum_to_double(datum);
- g_avro_allocator.free(d);
+ free(d);
}
break;
case AVRO_BOOLEAN:{
struct avro_boolean_datum_t *b;
b = avro_datum_to_boolean(datum);
- g_avro_allocator.free(b);
+ free(b);
}
break;
case AVRO_NULL:
@@ -798,38 +792,34 @@ static void avro_datum_free(avro_datum_t
break;
case AVRO_RECORD:{
- int i;
struct avro_record_datum_t *record;
record = avro_datum_to_record(datum);
- g_avro_allocator.free((void *)record->name);
+ free((void *)record->name);
if (record->space) {
- g_avro_allocator.free((void *)record->space);
+ free((void *)record->space);
}
st_foreach(record->fields_byname,
- atom_datum_free_foreach, 0);
- for (i = 0; i < record->num_fields; i++) {
- avro_atom_decref(record->field_order[i]);
- }
- g_avro_allocator.free(record->field_order);
+ char_datum_free_foreach, 0);
+ st_free_table(record->field_order);
st_free_table(record->fields_byname);
- g_avro_allocator.free(record);
+ free(record);
}
break;
case AVRO_ENUM:{
struct avro_enum_datum_t *enump;
enump = avro_datum_to_enum(datum);
- g_avro_allocator.free((void *)enump->name);
- g_avro_allocator.free(enump);
+ free((void *)enump->name);
+ free(enump);
}
break;
case AVRO_FIXED:{
struct avro_fixed_datum_t *fixed;
fixed = avro_datum_to_fixed(datum);
- g_avro_allocator.free((void *)fixed->name);
+ free((void *)fixed->name);
if (fixed->free) {
fixed->free((void *)fixed->bytes);
}
- g_avro_allocator.free(fixed);
+ free(fixed);
}
break;
case AVRO_MAP:{
@@ -838,25 +828,22 @@ static void avro_datum_free(avro_datum_t
st_foreach(map->map, char_datum_free_foreach,
0);
st_free_table(map->map);
- g_avro_allocator.free(map);
+ free(map);
}
break;
case AVRO_ARRAY:{
- int i;
struct avro_array_datum_t *array;
array = avro_datum_to_array(datum);
- for (i = 0; i < array->num_els; i++) {
- avro_datum_decref(array->els[i]);
- }
- g_avro_allocator.free(array->els);
- g_avro_allocator.free(array);
+ st_foreach(array->els, array_free_foreach, 0);
+ st_free_table(array->els);
+ free(array);
}
break;
case AVRO_UNION:{
struct avro_union_datum_t *unionp;
unionp = avro_datum_to_union(datum);
avro_datum_decref(unionp->value);
- g_avro_allocator.free(unionp);
+ free(unionp);
}
break;
case AVRO_LINK:{
Modified: avro/trunk/lang/c/src/datum.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum.h?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum.h (original)
+++ avro/trunk/lang/c/src/datum.h Wed Aug 25 18:46:06 2010
@@ -76,10 +76,8 @@ struct avro_record_datum_t {
struct avro_obj_t obj;
const char *name;
const char *space;
- avro_atom_t *field_order;
+ st_table *field_order;
st_table *fields_byname;
- int32_t num_fields;
- int32_t alloc_fields;
};
struct avro_enum_datum_t {
@@ -90,9 +88,7 @@ struct avro_enum_datum_t {
struct avro_array_datum_t {
struct avro_obj_t obj;
- int32_t num_els;
- int32_t alloc_els;
- avro_datum_t *els;
+ st_table *els;
};
struct avro_union_datum_t {
Modified: avro/trunk/lang/c/src/datum_equal.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum_equal.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum_equal.c (original)
+++ avro/trunk/lang/c/src/datum_equal.c Wed Aug 25 18:46:06 2010
@@ -24,11 +24,17 @@ array_equal(struct avro_array_datum_t *a
{
long i;
- if (a->num_els != b->num_els) {
+ if (a->els->num_entries != b->els->num_entries) {
return 0;
}
- for (i = 0; i < a->num_els; i++) {
- if (!avro_datum_equal(a->els[i], b->els[i])) {
+ for (i = 0; i < a->els->num_entries; i++) {
+ union {
+ st_data_t data;
+ avro_datum_t datum;
+ } ael, bel;
+ st_lookup(a->els, i, &ael.data);
+ st_lookup(b->els, i, &bel.data);
+ if (!avro_datum_equal(ael.datum, bel.datum)) {
return 0;
}
}
@@ -41,25 +47,7 @@ struct st_equal_args {
};
static int
-st_equal_map_foreach(char *key, avro_datum_t datum, struct st_equal_args *args)
-{
- union {
- avro_datum_t datum_other;
- st_data_t data;
- } val;
- if (!st_lookup(args->st, (st_data_t) key, &(val.data))) {
- args->rval = 0;
- return ST_STOP;
- }
- if (!avro_datum_equal(datum, val.datum_other)) {
- args->rval = 0;
- return ST_STOP;
- }
- return ST_CONTINUE;
-}
-
-static int
-st_equal_record_foreach(avro_atom_t key, avro_datum_t datum, struct st_equal_args *args)
+st_equal_foreach(char *key, avro_datum_t datum, struct st_equal_args *args)
{
union {
avro_datum_t datum_other;
@@ -82,7 +70,7 @@ static int map_equal(struct avro_map_dat
if (a->map->num_entries != b->map->num_entries) {
return 0;
}
- st_foreach(a->map, st_equal_map_foreach, (st_data_t) & args);
+ st_foreach(a->map, st_equal_foreach, (st_data_t) & args);
return args.rval;
}
@@ -106,7 +94,7 @@ static int record_equal(struct avro_reco
if (a->fields_byname->num_entries != b->fields_byname->num_entries) {
return 0;
}
- st_foreach(a->fields_byname, st_equal_record_foreach, (st_data_t) & args);
+ st_foreach(a->fields_byname, st_equal_foreach, (st_data_t) & args);
return args.rval;
}
Modified: avro/trunk/lang/c/src/datum_read.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum_read.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum_read.c (original)
+++ avro/trunk/lang/c/src/datum_read.c Wed Aug 25 18:46:06 2010
@@ -22,7 +22,6 @@
#include "encoding.h"
#include "schema.h"
#include "datum.h"
-#include "allocator.h"
int
avro_schema_match(avro_schema_t writers_schema, avro_schema_t readers_schema)
@@ -198,16 +197,16 @@ read_map(avro_reader_t reader, const avr
avro_schema_to_map(readers_schema)->
values, &value);
if (rval) {
- g_avro_allocator.free(key);
+ free(key);
return rval;
}
rval = avro_map_set(map, key, value);
if (rval) {
- g_avro_allocator.free(key);
+ free(key);
return rval;
}
avro_datum_decref(value);
- g_avro_allocator.free(key);
+ free(key);
}
rval = enc->read_long(reader, &block_count);
if (rval) {
@@ -393,7 +392,7 @@ avro_read_data(avro_reader_t reader, avr
int64_t size =
avro_schema_to_fixed(writers_schema)->size;
- bytes = g_avro_allocator.malloc(size);
+ bytes = malloc(size);
if (!bytes) {
return ENOMEM;
}
Modified: avro/trunk/lang/c/src/datum_size.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum_size.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum_size.c (original)
+++ avro/trunk/lang/c/src/datum_size.c Wed Aug 25 18:46:06 2010
@@ -57,10 +57,15 @@ size_record(avro_writer_t writer, const
/* No schema. Just write the record datum */
struct avro_record_datum_t *record =
avro_datum_to_record(datum);
- for (i = 0; i < record->num_fields; i++) {
- avro_atom_t name = record->field_order[i];
+ for (i = 0; i < record->field_order->num_entries; i++) {
+ union {
+ st_data_t data;
+ char *name;
+ } val;
+ st_lookup(record->field_order, i, &val.data);
size_check(rval,
- avro_record_get(datum, name, &field_datum));
+ avro_record_get(datum, val.name,
+ &field_datum));
size_accum(rval, size,
size_datum(writer, enc, NULL, field_datum));
}
@@ -138,14 +143,19 @@ size_array(avro_writer_t writer, const a
int64_t size;
size = 0;
- if (array->num_els) {
+ if (array->els->num_entries) {
size_accum(rval, size,
- enc->size_long(writer, array->num_els));
- for (i = 0; i < array->num_els; i++) {
+ enc->size_long(writer, array->els->num_entries));
+ for (i = 0; i < array->els->num_entries; i++) {
+ union {
+ st_data_t data;
+ avro_datum_t datum;
+ } val;
+ st_lookup(array->els, i, &val.data);
size_accum(rval, size,
size_datum(writer, enc,
schema ? schema->items : NULL,
- array->els[i]));
+ val.datum));
}
}
size_accum(rval, size, enc->size_long(writer, 0));
Modified: avro/trunk/lang/c/src/datum_validate.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum_validate.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum_validate.c (original)
+++ avro/trunk/lang/c/src/datum_validate.c Wed Aug 25 18:46:06 2010
@@ -101,10 +101,15 @@ avro_schema_datum_validate(avro_schema_t
struct avro_array_datum_t *array =
avro_datum_to_array(datum);
- for (i = 0; i < array->num_els; i++) {
+ for (i = 0; i < array->els->num_entries; i++) {
+ union {
+ st_data_t data;
+ avro_datum_t datum;
+ } val;
+ st_lookup(array->els, i, &val.data);
if (!avro_schema_datum_validate
((avro_schema_to_array
- (expected_schema))->items, array->els[i])) {
+ (expected_schema))->items, val.datum)) {
return 0;
}
}
Modified: avro/trunk/lang/c/src/datum_write.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum_write.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum_write.c (original)
+++ avro/trunk/lang/c/src/datum_write.c Wed Aug 25 18:46:06 2010
@@ -52,10 +52,14 @@ write_record(avro_writer_t writer, const
/* No schema. Just write the record datum */
struct avro_record_datum_t *record =
avro_datum_to_record(datum);
- for (i = 0; i < record->num_fields; i++) {
- avro_atom_t name = record->field_order[i];
+ for (i = 0; i < record->field_order->num_entries; i++) {
+ union {
+ st_data_t data;
+ char *name;
+ } val;
+ st_lookup(record->field_order, i, &val.data);
check(rval,
- avro_record_get(datum, name, &field_datum));
+ avro_record_get(datum, val.name, &field_datum));
check(rval,
write_datum(writer, enc, NULL, field_datum));
}
@@ -129,16 +133,21 @@ write_array(avro_writer_t writer, const
int rval;
long i;
- if (array->num_els) {
- rval = enc->write_long(writer, array->num_els);
+ if (array->els->num_entries) {
+ rval = enc->write_long(writer, array->els->num_entries);
if (rval) {
return rval;
}
- for (i = 0; i < array->num_els; i++) {
+ for (i = 0; i < array->els->num_entries; i++) {
+ union {
+ st_data_t data;
+ avro_datum_t datum;
+ } val;
+ st_lookup(array->els, i, &val.data);
check(rval,
write_datum(writer, enc,
schema ? schema->items : NULL,
- array->els[i]));
+ val.datum));
}
}
return enc->write_long(writer, 0);
Modified: avro/trunk/lang/c/src/dump.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/dump.h?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/dump.h (original)
+++ avro/trunk/lang/c/src/dump.h Wed Aug 25 18:46:06 2010
@@ -19,7 +19,7 @@
#define DUMP_H
#include <stdio.h>
-#include "types.h"
+#include <sys/types.h>
void dump(FILE * out, const caddr_t addr, const long len);
Modified: avro/trunk/lang/c/src/encoding_binary.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/encoding_binary.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/encoding_binary.c (original)
+++ avro/trunk/lang/c/src/encoding_binary.c Wed Aug 25 18:46:06 2010
@@ -16,13 +16,12 @@
*/
#include "avro_private.h"
-#include "allocator.h"
#include "encoding.h"
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <string.h>
-#include "types.h"
+#include <sys/types.h>
#define MAX_VARINT_BUF_SIZE 10
@@ -78,6 +77,8 @@ static int write_long(avro_writer_t writ
static int64_t size_long(avro_writer_t writer, int64_t l)
{
+ AVRO_UNUSED(writer);
+
int64_t len = 0;
uint64_t n = (l << 1) ^ (l >> 63);
while (n & ~0x7F) {
@@ -85,9 +86,6 @@ static int64_t size_long(avro_writer_t w
n >>= 7;
}
len++;
-
- AVRO_UNUSED(writer);
-
return len;
}
@@ -128,7 +126,7 @@ static int read_bytes(avro_reader_t read
if (rval) {
return rval;
}
- *bytes = g_avro_allocator.malloc(*len + 1);
+ *bytes = malloc(*len + 1);
if (!*bytes) {
return ENOMEM;
}
@@ -373,61 +371,61 @@ static int64_t size_null(avro_writer_t w
}
const avro_encoding_t avro_binary_encoding = {
- "BINARY FORMAT",
+ .description = "BINARY FORMAT",
/*
* string
*/
- read_string,
- skip_string,
- write_string,
- size_string,
+ .read_string = read_string,
+ .skip_string = skip_string,
+ .write_string = write_string,
+ .size_string = size_string,
/*
* bytes
*/
- read_bytes,
- skip_bytes,
- write_bytes,
- size_bytes,
+ .read_bytes = read_bytes,
+ .skip_bytes = skip_bytes,
+ .write_bytes = write_bytes,
+ .size_bytes = size_bytes,
/*
* int
*/
- read_int,
- skip_int,
- write_int,
- size_int,
+ .read_int = read_int,
+ .skip_int = skip_int,
+ .write_int = write_int,
+ .size_int = size_int,
/*
* long
*/
- read_long,
- skip_long,
- write_long,
- size_long,
+ .read_long = read_long,
+ .skip_long = skip_long,
+ .write_long = write_long,
+ .size_long = size_long,
/*
* float
*/
- read_float,
- skip_float,
- write_float,
- size_float,
+ .read_float = read_float,
+ .skip_float = skip_float,
+ .write_float = write_float,
+ .size_float = size_float,
/*
* double
*/
- read_double,
- skip_double,
- write_double,
- size_double,
+ .read_double = read_double,
+ .skip_double = skip_double,
+ .write_double = write_double,
+ .size_double = size_double,
/*
* boolean
*/
- read_boolean,
- skip_boolean,
- write_boolean,
- size_boolean,
+ .read_boolean = read_boolean,
+ .skip_boolean = skip_boolean,
+ .write_boolean = write_boolean,
+ .size_boolean = size_boolean,
/*
* null
*/
- read_skip_null,
- read_skip_null,
- write_null,
- size_null
+ .read_null = read_skip_null,
+ .skip_null = read_skip_null,
+ .write_null = write_null,
+ .size_null = size_null
};
Modified: avro/trunk/lang/c/src/io.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/io.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/io.c (original)
+++ avro/trunk/lang/c/src/io.c Wed Aug 25 18:46:06 2010
@@ -21,7 +21,6 @@
#include <errno.h>
#include <string.h>
#include "dump.h"
-#include "allocator.h"
enum avro_io_type_t {
AVRO_FILE_IO,
@@ -90,7 +89,7 @@ static void writer_init(avro_writer_t wr
avro_reader_t avro_reader_file(FILE * fp)
{
struct _avro_reader_file_t *file_reader =
- g_avro_allocator.malloc(sizeof(struct _avro_reader_file_t));
+ malloc(sizeof(struct _avro_reader_file_t));
if (!file_reader) {
return NULL;
}
@@ -103,7 +102,7 @@ avro_reader_t avro_reader_file(FILE * fp
avro_writer_t avro_writer_file(FILE * fp)
{
struct _avro_writer_file_t *file_writer =
- g_avro_allocator.malloc(sizeof(struct _avro_writer_file_t));
+ malloc(sizeof(struct _avro_writer_file_t));
if (!file_writer) {
return NULL;
}
@@ -115,7 +114,7 @@ avro_writer_t avro_writer_file(FILE * fp
avro_reader_t avro_reader_memory(const char *buf, int64_t len)
{
struct _avro_reader_memory_t *mem_reader =
- g_avro_allocator.malloc(sizeof(struct _avro_reader_memory_t));
+ malloc(sizeof(struct _avro_reader_memory_t));
if (!mem_reader) {
return NULL;
}
@@ -129,7 +128,7 @@ avro_reader_t avro_reader_memory(const c
avro_writer_t avro_writer_memory(const char *buf, int64_t len)
{
struct _avro_writer_memory_t *mem_writer =
- g_avro_allocator.malloc(sizeof(struct _avro_writer_memory_t));
+ malloc(sizeof(struct _avro_writer_memory_t));
if (!mem_writer) {
return NULL;
}
@@ -160,7 +159,7 @@ static int
avro_read_file(struct _avro_reader_file_t *reader, void *buf, int64_t len)
{
int64_t needed = len;
- char *p = buf;
+ void *p = buf;
int rval;
if (len == 0) {
@@ -347,19 +346,19 @@ void avro_reader_dump(avro_reader_t read
void avro_reader_free(avro_reader_t reader)
{
if (is_memory_io(reader)) {
- g_avro_allocator.free(avro_reader_to_memory(reader));
+ free(avro_reader_to_memory(reader));
} else if (is_file_io(reader)) {
fclose(avro_reader_to_file(reader)->fp);
- g_avro_allocator.free(avro_reader_to_file(reader));
+ free(avro_reader_to_file(reader));
}
}
void avro_writer_free(avro_writer_t writer)
{
if (is_memory_io(writer)) {
- g_avro_allocator.free(avro_writer_to_memory(writer));
+ free(avro_writer_to_memory(writer));
} else if (is_file_io(writer)) {
fclose(avro_writer_to_file(writer)->fp);
- g_avro_allocator.free(avro_writer_to_file(writer));
+ free(avro_writer_to_file(writer));
}
}
Modified: avro/trunk/lang/c/src/schema.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/schema.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/schema.c (original)
+++ avro/trunk/lang/c/src/schema.c Wed Aug 25 18:46:06 2010
@@ -15,7 +15,6 @@
* permissions and limitations under the License.
*/
-#include "config.h"
#include "avro_private.h"
#include <inttypes.h>
#include <stdlib.h>
@@ -26,7 +25,6 @@
#include "jansson.h"
#include "st.h"
#include "schema.h"
-#include "allocator.h"
#define DEFAULT_TABLE_SIZE 32
@@ -70,9 +68,9 @@ static int record_free_foreach(int i, st
AVRO_UNUSED(i);
AVRO_UNUSED(arg);
- avro_atom_decref(field->name);
+ free(field->name);
avro_schema_decref(field->type);
- g_avro_allocator.free(field);
+ free(field);
return ST_DELETE;
}
@@ -81,7 +79,7 @@ static int enum_free_foreach(int i, char
AVRO_UNUSED(i);
AVRO_UNUSED(arg);
- g_avro_allocator.free(sym);
+ free(sym);
return ST_DELETE;
}
@@ -112,35 +110,35 @@ static void avro_schema_free(avro_schema
case AVRO_RECORD:{
struct avro_record_schema_t *record;
record = avro_schema_to_record(schema);
- g_avro_allocator.free(record->name);
+ free(record->name);
if (record->space) {
- g_avro_allocator.free(record->space);
+ free(record->space);
}
st_foreach(record->fields, record_free_foreach,
0);
st_free_table(record->fields_byname);
st_free_table(record->fields);
- g_avro_allocator.free(record);
+ free(record);
}
break;
case AVRO_ENUM:{
struct avro_enum_schema_t *enump;
enump = avro_schema_to_enum(schema);
- g_avro_allocator.free(enump->name);
+ free(enump->name);
st_foreach(enump->symbols, enum_free_foreach,
0);
st_free_table(enump->symbols);
st_free_table(enump->symbols_byname);
- g_avro_allocator.free(enump);
+ free(enump);
}
break;
case AVRO_FIXED:{
struct avro_fixed_schema_t *fixed;
fixed = avro_schema_to_fixed(schema);
- g_avro_allocator.free((char *)fixed->name);
- g_avro_allocator.free(fixed);
+ free((char *)fixed->name);
+ free(fixed);
}
break;
@@ -148,7 +146,7 @@ static void avro_schema_free(avro_schema
struct avro_map_schema_t *map;
map = avro_schema_to_map(schema);
avro_schema_decref(map->values);
- g_avro_allocator.free(map);
+ free(map);
}
break;
@@ -156,7 +154,7 @@ static void avro_schema_free(avro_schema
struct avro_array_schema_t *array;
array = avro_schema_to_array(schema);
avro_schema_decref(array->items);
- g_avro_allocator.free(array);
+ free(array);
}
break;
case AVRO_UNION:{
@@ -165,7 +163,7 @@ static void avro_schema_free(avro_schema
st_foreach(unionp->branches, union_free_foreach,
0);
st_free_table(unionp->branches);
- g_avro_allocator.free(unionp);
+ free(unionp);
}
break;
@@ -173,7 +171,7 @@ static void avro_schema_free(avro_schema
struct avro_link_schema_t *link;
link = avro_schema_to_link(schema);
avro_schema_decref(link->to);
- g_avro_allocator.free(link);
+ free(link);
}
break;
}
@@ -199,9 +197,9 @@ void avro_schema_decref(avro_schema_t sc
avro_schema_t avro_schema_string(void)
{
static struct avro_obj_t obj = {
- AVRO_STRING, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_STRING,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -209,9 +207,9 @@ avro_schema_t avro_schema_string(void)
avro_schema_t avro_schema_bytes(void)
{
static struct avro_obj_t obj = {
- AVRO_BYTES, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_BYTES,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -219,9 +217,9 @@ avro_schema_t avro_schema_bytes(void)
avro_schema_t avro_schema_int(void)
{
static struct avro_obj_t obj = {
- AVRO_INT32, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_INT32,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -229,9 +227,9 @@ avro_schema_t avro_schema_int(void)
avro_schema_t avro_schema_long(void)
{
static struct avro_obj_t obj = {
- AVRO_INT64, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_INT64,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -239,9 +237,9 @@ avro_schema_t avro_schema_long(void)
avro_schema_t avro_schema_float(void)
{
static struct avro_obj_t obj = {
- AVRO_FLOAT, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_FLOAT,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -249,9 +247,9 @@ avro_schema_t avro_schema_float(void)
avro_schema_t avro_schema_double(void)
{
static struct avro_obj_t obj = {
- AVRO_DOUBLE, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_DOUBLE,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -259,9 +257,9 @@ avro_schema_t avro_schema_double(void)
avro_schema_t avro_schema_boolean(void)
{
static struct avro_obj_t obj = {
- AVRO_BOOLEAN, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_BOOLEAN,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -269,9 +267,9 @@ avro_schema_t avro_schema_boolean(void)
avro_schema_t avro_schema_null(void)
{
static struct avro_obj_t obj = {
- AVRO_NULL, // type
- AVRO_SCHEMA, // class_type
- 1 // refcount
+ .type = AVRO_NULL,
+ .class_type = AVRO_SCHEMA,
+ .refcount = 1
};
return &obj;
}
@@ -279,14 +277,14 @@ avro_schema_t avro_schema_null(void)
avro_schema_t avro_schema_fixed(const char *name, const int64_t size)
{
struct avro_fixed_schema_t *fixed =
- g_avro_allocator.malloc(sizeof(struct avro_fixed_schema_t));
+ malloc(sizeof(struct avro_fixed_schema_t));
if (!fixed) {
return NULL;
}
if (!is_avro_id(name)) {
return NULL;
}
- fixed->name = avro_strdup(name);
+ fixed->name = strdup(name);
fixed->size = size;
avro_schema_init(&fixed->obj, AVRO_FIXED);
return &fixed->obj;
@@ -295,13 +293,13 @@ avro_schema_t avro_schema_fixed(const ch
avro_schema_t avro_schema_union(void)
{
struct avro_union_schema_t *schema =
- g_avro_allocator.malloc(sizeof(struct avro_union_schema_t));
+ malloc(sizeof(struct avro_union_schema_t));
if (!schema) {
return NULL;
}
schema->branches = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
if (!schema->branches) {
- g_avro_allocator.free(schema);
+ free(schema);
return NULL;
}
@@ -327,7 +325,7 @@ avro_schema_union_append(const avro_sche
avro_schema_t avro_schema_array(const avro_schema_t items)
{
struct avro_array_schema_t *array =
- g_avro_allocator.malloc(sizeof(struct avro_array_schema_t));
+ malloc(sizeof(struct avro_array_schema_t));
if (!array) {
return NULL;
}
@@ -339,7 +337,7 @@ avro_schema_t avro_schema_array(const av
avro_schema_t avro_schema_map(const avro_schema_t values)
{
struct avro_map_schema_t *map =
- g_avro_allocator.malloc(sizeof(struct avro_map_schema_t));
+ malloc(sizeof(struct avro_map_schema_t));
if (!map) {
return NULL;
}
@@ -355,26 +353,26 @@ avro_schema_t avro_schema_enum(const cha
if (!is_avro_id(name)) {
return NULL;
}
- enump = g_avro_allocator.malloc(sizeof(struct avro_enum_schema_t));
+ enump = malloc(sizeof(struct avro_enum_schema_t));
if (!enump) {
return NULL;
}
- enump->name = avro_strdup(name);
+ enump->name = strdup(name);
if (!enump->name) {
- g_avro_allocator.free(enump);
+ free(enump);
return NULL;
}
enump->symbols = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
if (!enump->symbols) {
- g_avro_allocator.free(enump->name);
- g_avro_allocator.free(enump);
+ free(enump->name);
+ free(enump);
return NULL;
}
enump->symbols_byname = st_init_strtable_with_size(DEFAULT_TABLE_SIZE);
if (!enump->symbols_byname) {
st_free_table(enump->symbols);
- g_avro_allocator.free(enump->name);
- g_avro_allocator.free(enump);
+ free(enump->name);
+ free(enump);
return NULL;
}
avro_schema_init(&enump->obj, AVRO_ENUM);
@@ -392,7 +390,7 @@ avro_schema_enum_symbol_append(const avr
return EINVAL;
}
enump = avro_schema_to_enum(enum_schema);
- sym = avro_strdup(symbol);
+ sym = strdup(symbol);
if (!sym) {
return ENOMEM;
}
@@ -415,11 +413,11 @@ avro_schema_record_field_append(const av
return EINVAL;
}
record = avro_schema_to_record(record_schema);
- new_field = g_avro_allocator.malloc(sizeof(struct avro_record_field_t));
+ new_field = malloc(sizeof(struct avro_record_field_t));
if (!new_field) {
return ENOMEM;
}
- new_field->name = avro_atom_add(field_name);
+ new_field->name = strdup(field_name);
new_field->type = avro_schema_incref(field_schema);
st_insert(record->fields, record->fields->num_entries,
(st_data_t) new_field);
@@ -434,38 +432,37 @@ avro_schema_t avro_schema_record(const c
if (!is_avro_id(name)) {
return NULL;
}
- record = g_avro_allocator.malloc(sizeof(struct avro_record_schema_t));
+ record = malloc(sizeof(struct avro_record_schema_t));
if (!record) {
return NULL;
}
- record->name = avro_strdup(name);
+ record->name = strdup(name);
if (!record->name) {
- g_avro_allocator.free(record);
+ free(record);
return NULL;
}
- record->space = space ? avro_strdup(space) : NULL;
+ record->space = space ? strdup(space) : NULL;
if (space && !record->space) {
- g_avro_allocator.free(record->name);
- g_avro_allocator.free(record);
+ free(record->name);
+ free(record);
return NULL;
}
record->fields = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
if (!record->fields) {
if (record->space) {
- g_avro_allocator.free(record->space);
+ free(record->space);
}
- g_avro_allocator.free(record->name);
- g_avro_allocator.free(record);
+ free(record->name);
+ free(record);
return NULL;
}
- record->fields_byname = st_init_numtable_with_size(DEFAULT_TABLE_SIZE);
+ record->fields_byname = st_init_strtable_with_size(DEFAULT_TABLE_SIZE);
if (!record->fields_byname) {
st_free_table(record->fields);
- g_avro_allocator.free(record->name);
- g_avro_allocator.free(record);
+ free(record->name);
+ free(record);
return NULL;
}
- record->num_fields = 0;
avro_schema_init(&record->obj, AVRO_RECORD);
return &record->obj;
@@ -499,7 +496,7 @@ avro_schema_t avro_schema_link(avro_sche
if (!is_avro_named_type(to)) {
return NULL;
}
- link = g_avro_allocator.malloc(sizeof(struct avro_link_schema_t));
+ link = malloc(sizeof(struct avro_link_schema_t));
if (!link) {
return NULL;
}
@@ -856,7 +853,7 @@ avro_schema_from_json(const char *jsonte
return EINVAL;
}
- error = g_avro_allocator.malloc(sizeof(struct avro_schema_error_t_));
+ error = malloc(sizeof(struct avro_schema_error_t_));
if (!error) {
return ENOMEM;
}
@@ -864,14 +861,14 @@ avro_schema_from_json(const char *jsonte
error->named_schemas = st_init_strtable_with_size(DEFAULT_TABLE_SIZE);
if (!error->named_schemas) {
- g_avro_allocator.free(error);
+ free(error);
return ENOMEM;
}
root = json_loads(jsontext, &error->json_error);
if (!root) {
st_free_table(error->named_schemas);
- g_avro_allocator.free(error);
+ free(error);
return EINVAL;
}
@@ -883,7 +880,7 @@ avro_schema_from_json(const char *jsonte
st_free_table(error->named_schemas);
if (rval == 0) {
/* no need for an error return */
- g_avro_allocator.free(error);
+ free(error);
}
return rval;
}
@@ -922,12 +919,11 @@ avro_schema_t avro_schema_copy(avro_sche
st_data_t data;
struct avro_record_field_t *field;
} val;
- avro_schema_t type_copy;
st_lookup(record_schema->fields, i, &val.data);
- type_copy = avro_schema_copy(val.field->type);
- // FIXME: Remove avro_atom_to_string() here.
+ avro_schema_t type_copy =
+ avro_schema_copy(val.field->type);
avro_schema_record_field_append(new_schema,
- avro_atom_to_string(val.field->name),
+ val.field->name,
type_copy);
}
}
@@ -1051,7 +1047,7 @@ static int write_field(avro_writer_t out
{
int rval;
check(rval, avro_write_str(out, "{\"name\":\""));
- check(rval, avro_write_str(out, avro_atom_to_string(field->name)));
+ check(rval, avro_write_str(out, field->name));
check(rval, avro_write_str(out, "\",\"type\":"));
check(rval, avro_schema_to_json(field->type, out));
return avro_write_str(out, "}");
Modified: avro/trunk/lang/c/src/schema.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/schema.h?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/schema.h (original)
+++ avro/trunk/lang/c/src/schema.h Wed Aug 25 18:46:06 2010
@@ -22,7 +22,7 @@
#include "st.h"
struct avro_record_field_t {
- avro_atom_t name;
+ char *name;
avro_schema_t type;
/*
* TODO: default values
@@ -35,7 +35,6 @@ struct avro_record_schema_t {
char *space;
st_table *fields;
st_table *fields_byname;
- int32_t num_fields;
};
struct avro_enum_schema_t {
Modified: avro/trunk/lang/c/src/schema_equal.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/schema_equal.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/schema_equal.c (original)
+++ avro/trunk/lang/c/src/schema_equal.c Wed Aug 25 18:46:06 2010
@@ -48,7 +48,7 @@ schema_record_equal(struct avro_record_s
if (!st_lookup(b->fields, i, &fb.data)) {
return 0;
}
- if (fa.f->name != fb.f->name) {
+ if (strcmp(fa.f->name, fb.f->name)) {
/*
* They have fields with different names
*/
Modified: avro/trunk/lang/c/src/st.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/st.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/st.c (original)
+++ avro/trunk/lang/c/src/st.c Wed Aug 25 18:46:06 2010
@@ -13,7 +13,6 @@
#include <string.h>
#include "st.h"
-#include "allocator.h"
typedef struct st_table_entry st_table_entry;
@@ -59,8 +58,8 @@ static void rehash(st_table *);
#define calloc xcalloc
#endif
-#define alloc(type) (type*)g_avro_allocator.malloc((unsigned)sizeof(type))
-#define Calloc(n,s) (char*)g_avro_allocator.calloc((n),(s))
+#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)
@@ -208,12 +207,12 @@ st_table *table;
ptr = table->bins[i];
while (ptr != 0) {
next = ptr->next;
- g_avro_allocator.free(ptr);
+ free(ptr);
ptr = next;
}
}
- g_avro_allocator.free(table->bins);
- g_avro_allocator.free(table);
+ free(table->bins);
+ free(table);
}
#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
@@ -328,7 +327,7 @@ register st_table *table;
ptr = next;
}
}
- g_avro_allocator.free(table->bins);
+ free(table->bins);
table->num_bins = new_num_bins;
table->bins = new_bins;
}
@@ -350,7 +349,7 @@ st_table *old_table;
Calloc((unsigned)num_bins, sizeof(st_table_entry *));
if (new_table->bins == 0) {
- g_avro_allocator.free(new_table);
+ free(new_table);
return 0;
}
@@ -360,8 +359,8 @@ st_table *old_table;
while (ptr != 0) {
entry = alloc(st_table_entry);
if (entry == 0) {
- g_avro_allocator.free(new_table->bins);
- g_avro_allocator.free(new_table);
+ free(new_table->bins);
+ free(new_table);
return 0;
}
*entry = *ptr;
@@ -397,7 +396,7 @@ st_data_t *value;
if (value != 0)
*value = ptr->record;
*key = ptr->key;
- g_avro_allocator.free(ptr);
+ free(ptr);
return 1;
}
@@ -409,7 +408,7 @@ st_data_t *value;
if (value != 0)
*value = tmp->record;
*key = tmp->key;
- g_avro_allocator.free(tmp);
+ free(tmp);
return 1;
}
}
@@ -516,7 +515,7 @@ st_data_t arg;
last->next = ptr->next;
}
ptr = ptr->next;
- g_avro_allocator.free(tmp);
+ free(tmp);
table->num_entries--;
}
}
Modified: avro/trunk/lang/c/src/st.h
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/st.h?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/src/st.h (original)
+++ avro/trunk/lang/c/src/st.h Wed Aug 25 18:46:06 2010
@@ -10,7 +10,7 @@
#ifndef ST_INCLUDED
#define ST_INCLUDED
-#include "types.h" /* for uintptr_t */
+#include <stdint.h> /* for uintptr_t */
typedef uintptr_t st_data_t;
typedef struct st_table st_table;
Modified: avro/trunk/lang/c/tests/CMakeLists.txt
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/CMakeLists.txt?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/CMakeLists.txt (original)
+++ avro/trunk/lang/c/tests/CMakeLists.txt Wed Aug 25 18:46:06 2010
@@ -22,19 +22,7 @@ target_link_libraries(generate_interop_d
add_executable(test_interop_data test_interop_data.c)
target_link_libraries(test_interop_data avro-static)
-if(WIN32)
- add_executable(test_avro_schema
- test_avro_schema.c
- dir_iterator.h
- windows/dir_iterator.c
- )
-else()
- add_executable(test_avro_schema
- test_avro_schema.c
- dir_iterator.h
- linux/dir_iterator.c
- )
-endif()
+add_executable(test_avro_schema test_avro_schema.c)
target_link_libraries(test_avro_schema avro-static)
add_test(test_avro_schema ${CMAKE_COMMAND} -E chdir ${AvroC_SOURCE_DIR}/tests ${CMAKE_CURRENT_BINARY_DIR}/test_avro_schema)
Modified: avro/trunk/lang/c/tests/generate_interop_data.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/generate_interop_data.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/generate_interop_data.c (original)
+++ avro/trunk/lang/c/tests/generate_interop_data.c Wed Aug 25 18:46:06 2010
@@ -18,67 +18,7 @@
#include "avro_private.h"
#include <stdio.h>
#include <stdlib.h>
-#include "config.h"
-
-struct atom_holder {
- avro_atom_t arrayField;
- avro_atom_t boolField;
- avro_atom_t bytesField;
- avro_atom_t doubleField;
- avro_atom_t enumField;
- avro_atom_t fixedField;
- avro_atom_t floatField;
- avro_atom_t intField;
- avro_atom_t longField;
- avro_atom_t mapField;
- avro_atom_t nullField;
- avro_atom_t recordField;
- avro_atom_t stringField;
- avro_atom_t unionField;
-
- avro_atom_t children;
- avro_atom_t label;
-} atoms;
-
-void init_atoms(void)
-{
- atoms.arrayField = avro_atom_add("arrayField");
- atoms.boolField = avro_atom_add("boolField");
- atoms.bytesField = avro_atom_add("bytesField");
- atoms.doubleField = avro_atom_add("doubleField");
- atoms.enumField = avro_atom_add("enumField");
- atoms.fixedField = avro_atom_add("fixedField");
- atoms.floatField = avro_atom_add("floatField");
- atoms.intField = avro_atom_add("intField");
- atoms.longField = avro_atom_add("longField");
- atoms.mapField = avro_atom_add("mapField");
- atoms.nullField = avro_atom_add("nullField");
- atoms.recordField = avro_atom_add("recordField");
- atoms.stringField = avro_atom_add("stringField");
- atoms.unionField = avro_atom_add("unionField");
- atoms.children = avro_atom_add("children");
- atoms.label = avro_atom_add("label");
-}
-
-void cleanup_atoms(void)
-{
- avro_atom_decref(atoms.arrayField);
- avro_atom_decref(atoms.boolField);
- avro_atom_decref(atoms.bytesField);
- avro_atom_decref(atoms.doubleField);
- avro_atom_decref(atoms.enumField);
- avro_atom_decref(atoms.fixedField);
- avro_atom_decref(atoms.floatField);
- avro_atom_decref(atoms.intField);
- avro_atom_decref(atoms.longField);
- avro_atom_decref(atoms.mapField);
- avro_atom_decref(atoms.nullField);
- avro_atom_decref(atoms.recordField);
- avro_atom_decref(atoms.stringField);
- avro_atom_decref(atoms.unionField);
- avro_atom_decref(atoms.children);
- avro_atom_decref(atoms.label);
-}
+#include <unistd.h>
int main(int argc, char *argv[])
{
@@ -101,9 +41,6 @@ int main(int argc, char *argv[])
KIND_C
};
- avro_init();
- init_atoms();
-
if (argc != 3) {
exit(EXIT_FAILURE);
}
@@ -120,34 +57,34 @@ int main(int argc, char *argv[])
/* TODO: create a method for generating random data from schema */
interop = avro_record("Interop", "org.apache.avro");
- avro_record_set(interop, atoms.intField, avro_int32(42));
- avro_record_set(interop, atoms.longField, avro_int64(4242));
- avro_record_set(interop, atoms.stringField,
+ avro_record_set(interop, "intField", avro_int32(42));
+ avro_record_set(interop, "longField", avro_int64(4242));
+ avro_record_set(interop, "stringField",
avro_wrapstring("Follow your bliss."));
- avro_record_set(interop, atoms.boolField, avro_boolean(1));
- avro_record_set(interop, atoms.floatField, avro_float(3.14159265));
- avro_record_set(interop, atoms.doubleField, avro_double(2.71828183));
- avro_record_set(interop, atoms.bytesField, avro_bytes("abcd", 4));
- avro_record_set(interop, atoms.nullField, avro_null());
+ avro_record_set(interop, "boolField", avro_boolean(1));
+ avro_record_set(interop, "floatField", avro_float(3.14159265));
+ avro_record_set(interop, "doubleField", avro_double(2.71828183));
+ avro_record_set(interop, "bytesField", avro_bytes("abcd", 4));
+ avro_record_set(interop, "nullField", avro_null());
array_datum = avro_array();
avro_array_append_datum(array_datum, avro_double(1.0));
avro_array_append_datum(array_datum, avro_double(2.0));
avro_array_append_datum(array_datum, avro_double(3.0));
- avro_record_set(interop, atoms.arrayField, array_datum);
+ avro_record_set(interop, "arrayField", array_datum);
- avro_record_set(interop, atoms.mapField, avro_map());
+ avro_record_set(interop, "mapField", avro_map());
union_datum = avro_union(1, avro_double(1.61803399));
- avro_record_set(interop, atoms.unionField, union_datum);
- avro_record_set(interop, atoms.enumField, avro_enum("Kind", KIND_A));
- avro_record_set(interop, atoms.fixedField,
+ avro_record_set(interop, "unionField", union_datum);
+ avro_record_set(interop, "enumField", avro_enum("Kind", KIND_A));
+ avro_record_set(interop, "fixedField",
avro_fixed("MD5", "1234567890123456", 16));
node_datum = avro_record("Node", NULL);
- avro_record_set(node_datum, atoms.label,
+ avro_record_set(node_datum, "label",
avro_wrapstring("If you label me, you negate me."));
- avro_record_set(node_datum, atoms.children, avro_array());
- avro_record_set(interop, atoms.recordField, node_datum);
+ avro_record_set(node_datum, "children", avro_array());
+ avro_record_set(interop, "recordField", node_datum);
rval = avro_file_writer_append(file_writer, interop);
if (rval) {
@@ -171,7 +108,5 @@ int main(int argc, char *argv[])
fprintf(stderr, "ok\n");
check(rval, avro_file_reader_close(file_reader));
fprintf(stderr, "Closed reader.\n");
- cleanup_atoms();
- avro_shutdown();
return 0;
}
Modified: avro/trunk/lang/c/tests/test_avro_data.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_data.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ avro/trunk/lang/c/tests/test_avro_data.c Wed Aug 25 18:46:06 2010
@@ -55,7 +55,6 @@ write_read_check(avro_schema_t writers_s
{
avro_datum_t datum_out;
int validate;
- int64_t size;
for (validate = 0; validate <= 1; validate++) {
@@ -69,7 +68,7 @@ write_read_check(avro_schema_t writers_s
type, validate);
exit(EXIT_FAILURE);
}
- size =
+ int64_t size =
avro_size_data(writer, validate ? writers_schema : NULL,
datum);
if (size != avro_writer_tell(writer)) {
@@ -206,20 +205,16 @@ static int test_record(void)
{
avro_schema_t schema = avro_schema_record("person", NULL);
avro_datum_t datum = avro_record("person", NULL);
- avro_atom_t name_atom, age_atom;
avro_datum_t name_datum, age_datum;
- name_atom = avro_atom_add("name");
- age_atom = avro_atom_add("age");
-
avro_schema_record_field_append(schema, "name", avro_schema_string());
avro_schema_record_field_append(schema, "age", avro_schema_int());
name_datum = avro_wrapstring("Joseph Campbell");
age_datum = avro_int32(83);
- avro_record_set(datum, name_atom, name_datum);
- avro_record_set(datum, age_atom, age_datum);
+ avro_record_set(datum, "name", name_datum);
+ avro_record_set(datum, "age", age_datum);
write_read_check(schema, NULL, datum, "record");
@@ -227,8 +222,6 @@ static int test_record(void)
avro_datum_decref(age_datum);
avro_datum_decref(datum);
avro_schema_decref(schema);
- avro_atom_decref(name_atom);
- avro_atom_decref(age_atom);
return 0;
}
@@ -351,8 +344,6 @@ int main(void)
"union", test_union}
};
- avro_init();
-
init_rand();
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
struct avro_tests *test = tests + i;
@@ -361,8 +352,5 @@ int main(void)
return EXIT_FAILURE;
}
}
-
- avro_shutdown();
-
return EXIT_SUCCESS;
}
Modified: avro/trunk/lang/c/tests/test_avro_schema.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_schema.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_schema.c (original)
+++ avro/trunk/lang/c/tests/test_avro_schema.c Wed Aug 25 18:46:06 2010
@@ -16,11 +16,10 @@
*/
#include "avro_private.h"
-#include "config.h"
-#include "dir_iterator.h"
#include <stdio.h>
#include <stdlib.h>
-#include <stdio.h>
+#include <sys/types.h>
+#include <dirent.h>
int test_cases = 0;
avro_writer_t avro_stderr;
@@ -30,23 +29,23 @@ static void run_tests(char *dirpath, int
char jsontext[4096];
size_t jsonlen, rval;
char filepath[1024];
- dir_iterator_t dir;
- const char *dent;
+ DIR *dir;
+ struct dirent *dent;
FILE *fp;
avro_schema_t schema;
avro_schema_error_t avro_schema_error;
- dir = dir_iterator_new(dirpath);
+ dir = opendir(dirpath);
if (dir == NULL) {
fprintf(stderr, "Unable to open '%s'\n", dirpath);
exit(EXIT_FAILURE);
}
- while (dir_iterator_next(dir)) {
- dent = dir_iterator_value(dir);
- if (dent && dent[0] != '.') {
+ do {
+ dent = readdir(dir);
+ if (dent && dent->d_name[0] != '.') {
int test_rval;
snprintf(filepath, sizeof(filepath), "%s/%s", dirpath,
- dent);
+ dent->d_name);
fprintf(stderr, "TEST %s...", filepath);
jsonlen = 0;
fp = fopen(filepath, "r");
@@ -95,10 +94,7 @@ static void run_tests(char *dirpath, int
}
}
}
- if (NULL != dir)
- {
- dir_iterator_destroy(dir);
- }
+ while (dent != NULL);
}
int main(int argc, char *argv[])
@@ -109,8 +105,6 @@ int main(int argc, char *argv[])
AVRO_UNUSED(argc);
AVRO_UNUSED(argv);
- avro_init();
-
if (!srcdir) {
srcdir = ".";
}
@@ -134,8 +128,5 @@ int main(int argc, char *argv[])
fprintf(stderr, "==================================================\n");
avro_writer_free(avro_stderr);
-
- avro_shutdown();
-
return EXIT_SUCCESS;
}
Modified: avro/trunk/lang/c/tests/test_interop_data.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_interop_data.c?rev=989288&r1=989287&r2=989288&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/test_interop_data.c (original)
+++ avro/trunk/lang/c/tests/test_interop_data.c Wed Aug 25 18:46:06 2010
@@ -1,8 +1,8 @@
#include "avro_private.h"
+#include <stdio.h>
+#include <unistd.h>
int main(void)
{
- avro_init();
- avro_shutdown();
return 0;
}