Author: dcreager
Date: Fri Jul 26 13:55:39 2013
New Revision: 1507317
URL: http://svn.apache.org/r1507317
Log:
AVRO-1279. C: Treat missing codec in data file as null codec.
Contributed by Carl Steinbach.
Added:
avro/trunk/lang/c/tests/avro-1279-codec.avro (with props)
avro/trunk/lang/c/tests/avro-1279-no-codec.avro (with props)
avro/trunk/lang/c/tests/test_avro_1279.c
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/c/src/datafile.c
avro/trunk/lang/c/src/generic.c
avro/trunk/lang/c/tests/CMakeLists.txt
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1507317&r1=1507316&r2=1507317&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Jul 26 13:55:39 2013
@@ -78,6 +78,9 @@ Trunk (not yet released)
AVRO-1297. NettyTransceiver: Provide overloaded
close(boolean awaitCompletion). (jbaldassari)
+ AVRO-1279. C: Treat missing codec in data files as null codec.
+ (Carl Steinbach via dcreager)
+
BUG FIXES
AVRO-1296. Python: Fix schemas retrieved from protocol types
Modified: avro/trunk/lang/c/src/datafile.c
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=1507317&r1=1507316&r2=1507317&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Fri Jul 26 13:55:39 2013
@@ -276,9 +276,11 @@ static int file_read_header(avro_reader_
rval = avro_value_get_by_name(&meta, "avro.codec", &codec_val, NULL);
if (rval) {
- avro_set_error("File header doesn't contain a codec");
- avro_value_decref(&meta);
- return rval;
+ if (avro_codec(codec, NULL) != 0) {
+ avro_set_error("Codec not specified in header and
unable to set 'null' codec");
+ avro_value_decref(&meta);
+ return EILSEQ;
+ }
} else {
const void *buf;
size_t size;
@@ -307,7 +309,7 @@ static int file_read_header(avro_reader_
if (rval) {
avro_set_error("File header doesn't contain a schema");
avro_value_decref(&meta);
- return rval;
+ return EILSEQ;
}
avro_value_get_bytes(&schema_bytes, &p, &len);
Modified: avro/trunk/lang/c/src/generic.c
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/src/generic.c?rev=1507317&r1=1507316&r2=1507317&view=diff
==============================================================================
--- avro/trunk/lang/c/src/generic.c (original)
+++ avro/trunk/lang/c/src/generic.c Fri Jul 26 13:55:39 2013
@@ -2653,6 +2653,10 @@ avro_generic_map_get_by_name(const avro_
const avro_generic_map_t *self = (const avro_generic_map_t *) vself;
child->iface = &iface->child_giface->parent;
child->self = avro_raw_map_get(&self->map, name, index);
+ if (child->self == NULL) {
+ avro_set_error("No map element named %s", name);
+ return EINVAL;
+ }
return 0;
}
Modified: avro/trunk/lang/c/tests/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/CMakeLists.txt?rev=1507317&r1=1507316&r2=1507317&view=diff
==============================================================================
--- avro/trunk/lang/c/tests/CMakeLists.txt (original)
+++ avro/trunk/lang/c/tests/CMakeLists.txt Fri Jul 26 13:55:39 2013
@@ -55,6 +55,7 @@ add_avro_test(test_avro_1084)
add_avro_test(test_avro_1087)
add_avro_test(test_avro_1165)
add_avro_test(test_avro_1238)
+add_avro_test(test_avro_1279)
add_avro_test(test_avro_data)
add_avro_test(test_refcount)
add_avro_test(test_cpp test_cpp.cpp)
Added: avro/trunk/lang/c/tests/avro-1279-codec.avro
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/avro-1279-codec.avro?rev=1507317&view=auto
==============================================================================
Binary file - no diff available.
Propchange: avro/trunk/lang/c/tests/avro-1279-codec.avro
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: avro/trunk/lang/c/tests/avro-1279-no-codec.avro
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/avro-1279-no-codec.avro?rev=1507317&view=auto
==============================================================================
Binary file - no diff available.
Propchange: avro/trunk/lang/c/tests/avro-1279-no-codec.avro
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: avro/trunk/lang/c/tests/test_avro_1279.c
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/c/tests/test_avro_1279.c?rev=1507317&view=auto
==============================================================================
--- avro/trunk/lang/c/tests/test_avro_1279.c (added)
+++ avro/trunk/lang/c/tests/test_avro_1279.c Fri Jul 26 13:55:39 2013
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+#include <avro.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define check_exit(call) \
+ do { \
+ int __rc = call; \
+ if (__rc != 0) { \
+ fprintf(stderr, "Unexpected error:\n %s\n %s\n", \
+ avro_strerror(), #call); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
+int main(void)
+{
+ avro_file_reader_t reader;
+
+ /* First open the file with the explicit codec. */
+ check_exit(avro_file_reader("avro-1279-codec.avro", &reader));
+ check_exit(avro_file_reader_close(reader));
+
+
+ /* Then the file with no codec. */
+ check_exit(avro_file_reader("avro-1279-no-codec.avro", &reader));
+ check_exit(avro_file_reader_close(reader));
+
+ /* Clean up and exit */
+ exit(EXIT_SUCCESS);
+}