Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6663864B3 for ; Sat, 28 May 2011 15:00:30 +0000 (UTC) Received: (qmail 52421 invoked by uid 500); 28 May 2011 15:00:30 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 52351 invoked by uid 500); 28 May 2011 15:00:29 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 52337 invoked by uid 99); 28 May 2011 15:00:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 May 2011 15:00:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 May 2011 15:00:27 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 9B919E5154 for ; Sat, 28 May 2011 14:59:47 +0000 (UTC) Date: Sat, 28 May 2011 14:59:47 +0000 (UTC) From: "Thiruvalluvan M. G. (JIRA)" To: dev@avro.apache.org Message-ID: <648767720.50910.1306594787634.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1689485008.27198.1305823727408.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (AVRO-825) C++ code generation issues with records when member of the record is of type itself MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AVRO-825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Thiruvalluvan M. G. updated AVRO-825: ------------------------------------- Attachment: AVRO-825-v5.patch Ramana and I had a few e-mail exchanges where he found some corner cases where the code generator did not produce correct code. This one fixes those problems and had additional test cases. > C++ code generation issues with records when member of the record is of type itself > ----------------------------------------------------------------------------------- > > Key: AVRO-825 > URL: https://issues.apache.org/jira/browse/AVRO-825 > Project: Avro > Issue Type: Bug > Components: c++ > Affects Versions: 1.5.1 > Reporter: Ramana Suvarapu > Assignee: Thiruvalluvan M. G. > Priority: Blocker > Attachments: AVRO-825-v2.patch, AVRO-825-v5.patch, AVRO-825.patch > > > I am trying to generate C++ code for the following schema using new avrogencpp. This schema is one the of the example given in Avro specification > { > "type": "record", > "name": "LongList", > "aliases": ["LinkedLongs"], // old name for this > "fields" : [ > {"name": "value", "type": "long"}, // each element has a long > {"name": "next", "type": ["LongList", "null"]} // optional next element > ] > } > It generated the following .hh file and when I tried to compile I am getting > #ifndef __TEST_LINKEDLIST_HH_1817083040__H_ > #define __TEST_LINKEDLIST_HH_1817083040__H_ > #include "boost/any.hpp" > #include "Specific.hh" > #include "Encoder.hh" > #include "Decoder.hh" > struct _imaginary_avr_Union__0__ { > private: > size_t idx_; > boost::any value_; > public: > size_t idx() const { return idx_; } > LongList get_LongList() const { > if (idx_ != 0) { > throw avro::Exception("Invalid type for union"); > } > return boost::any_cast(value_); > } > void set_LongList(const LongList& v) { > idx_ = 0; > value_ = v; > } > void set_null() { > idx_ = 1; > value_ = boost::any(); > } > _imaginary_avr_Union__0__() : idx_(0) { > value_ = LongList(); > } > }; > struct LongList { > int64_t value; > _imaginary_avr_Union__0__ next; > }; > namespace avro { > template<> struct codec_traits<_imaginary_avr_Union__0__> { > static void encode(Encoder& e, _imaginary_avr_Union__0__ v) { > e.encodeUnionIndex(v.idx()); > switch (v.idx()) { > case 0: > avro::encode(e, v.get_LongList()); > break; > case 1: > e.encodeNull(); > break; > } > } > static void decode(Decoder& d, _imaginary_avr_Union__0__& v) { > size_t n = d.decodeUnionIndex(); > if (n >= 2) { throw avro::Exception("Union index too big"); } > switch (n) { > case 0: > { > LongList vv; > avro::decode(d, vv); > v.set_LongList(vv); > } > break; > case 1: > d.decodeNull(); > v.set_null(); > break; > } > } > }; > template<> struct codec_traits { > static void encode(Encoder& e, const LongList& v) { > avro::encode(e, v.value); > avro::encode(e, v.next); > } > static void decode(Decoder& d, LongList& v) { > avro::decode(d, v.value); > avro::decode(d, v.next); > } > }; > } > #endif > When I tried to compile I am getting following errors due to incomplete type. > Errors > In file included from /home/rsuvarap/avro-src-1.5.1/lang/c++/test/AvrogencppTests.cc:24: > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:34: error: `LongList' does not name a type > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:40: error: expected `,' or `...' before '&' token > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:40: error: ISO C++ forbids declaration of `LongList' with no type > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh: In member function `void _imaginary_avr_Union__0__::set_LongList(int)': > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:42: error: `v' was not declared in this scope > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh: In constructor `_imaginary_avr_Union__0__::_imaginary_avr_Union__0__()': > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:49: error: `LongList' was not declared in this scope > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh: In static member function `static void avro::codec_traits<_imaginary_avr_Union__0__>::encode(avro::Encoder&, _imaginary_avr_Union__0__)': > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:64: error: 'struct _imaginary_avr_Union__0__' has no member named 'get_LongList' > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh: In static member function `static void avro::codec_traits<_imaginary_avr_Union__0__>::decode(avro::Decoder&, _imaginary_avr_Union__0__&)': > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:79: error: no matching function for call to `_imaginary_avr_Union__0__::set_LongList(LongList&)' > /home/rsuvarap/avro-src-1.5.1/lang/c++/test/linkedlist.hh:40: note: candidates are: void _imaginary_avr_Union__0__::set_LongList(int) > make[2]: *** [CMakeFiles/AvrogencppTests.dir/test/AvrogencppTests.cc.o] Error 1 > make[1]: *** [CMakeFiles/AvrogencppTests.dir/all] Error 2 > make: *** [all] Error 2 > I think the issue is get_LongList of the union should return pointer to LongList instead of value. It's a same issue with c++ generation using python script. > We use lot of similar schemas in our project and we use cross language messaging between Java and C++ applications and these errors are affecting C++ applications. > Please let us know when this issue is going to be fixed? > Thanks, > Ramana -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira