You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2010/08/06 01:32:15 UTC
[jira] Closed: (THRIFT-609) generator allows for fields that break
code
[ https://issues.apache.org/jira/browse/THRIFT-609?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bryan Duxbury closed THRIFT-609.
--------------------------------
Resolution: Duplicate
> generator allows for fields that break code
> -------------------------------------------
>
> Key: THRIFT-609
> URL: https://issues.apache.org/jira/browse/THRIFT-609
> Project: Thrift
> Issue Type: Bug
> Components: Compiler (Ruby)
> Affects Versions: 0.2
> Reporter: Andrew Kuhnhausen
>
> affects latest SVN and latest snapshot.
> generator should allow for any possible known conflict with some ruby specific constant by either throwing an error for every known ruby specific constant name, or appending something like '__' to each of the fields. here is an example and a possible solution
> // EXAMPLE
> struct TimeInterval {
> 1: UnixTime start,
> 2: UnixTime end,
> }
> will generate invalid ruby code by trying to define "END":
> class TimeInterval
> include ::Thrift::Struct
> START = 1
> END = 2
> ::Thrift::Struct.field_accessor self, :start, :end
> FIELDS = {
> START => {:type => ::Thrift::Types::I32, :name => 'start'},
> END => {:type => ::Thrift::Types::I32, :name => 'end'}
> }
> def struct_fields; FIELDS; end
> def validate
> end
> end
> // POSSIBLE SOLUTION
> line 523:
> void t_rb_generator::generate_field_constants(std::ofstream& out, t_struct* tstruct) {
> const vector<t_field*>& fields = tstruct->get_members();
> vector<t_field*>::const_iterator f_iter;
> for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
> std::string field_name = (*f_iter)->get_name();
> std::string cap_field_name = upcase_string(field_name);
> //
> // append '__' to the end of field names
> cap_field_name = cap_field_name + "__";
> //
> //
> indent(out) << cap_field_name << " = " << (*f_iter)->get_key() << endl;
> }
> out << endl;
> }
> line 551:
> void t_rb_generator::generate_field_defns(std::ofstream& out, t_struct* tstruct) {
> const vector<t_field*>& fields = tstruct->get_members();
> vector<t_field*>::const_iterator f_iter;
> indent(out) << "FIELDS = {" << endl;
> indent_up();
> for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
> if (f_iter != fields.begin()) {
> out << "," << endl;
> }
> // generate the field docstrings within the FIELDS constant. no real better place...
> generate_rdoc(out, *f_iter);
> //
> //
> // add the '__' to the end of the field name
> indent(out) <<
> upcase_string((*f_iter)->get_name()) << "__ => ";
> //
> //
> generate_field_data(out, (*f_iter)->get_type(), (*f_iter)->get_name(), (*f_iter)->get_value(),
> (*f_iter)->get_req() == t_field::T_OPTIONAL);
> }
> indent_down();
> out << endl;
> indent(out) << "}" << endl << endl;
>
> indent(out) << "def struct_fields; FIELDS; end" << endl << endl;
>
> }
> this will then make all possible variations in ruby syntactically sound
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.