buggperf - Bugs: bug #37005, -P (PIC-friendly) code not correct...

 
 

bug #37005: -P (PIC-friendly) code not correct for structure table

Submitter:  Chip Salzenberg <chip>
Submitted:  Tue 31 Jul 2012 09:45:11 PM UTC
   
 
Category:  Generated code Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 08 Jan 2013 05:58:46 PM UTC, comment #3: 

c'mon, it's documented sure, but the patch makes it better; code doesn't have to care whether it's pic or not.

Anonymous
Tue 08 Jan 2013 12:28:57 AM UTC, comment #2: 

The documentation of the option -P in
http://www.gnu.org/software/gperf/manual/html_node/Output-Details.html
says:
"the first field of the user-defined struct must be of type ‘int’, not ‘char *’, because it will contain offsets into the string pool instead of actual strings."

Therefore your struct should be:

struct Foo {
   int name;
   int value;
};


Bruno Haible <haible>
Group administrator
Tue 31 Jul 2012 09:46:33 PM UTC, comment #1: 

Note, the comment on the second substitution is incorrect.

Chip Salzenberg <chip>
Tue 31 Jul 2012 09:45:11 PM UTC, original submission:  

Given input that defines the table structure as e.g.


struct Foo {
   char *name;
   int value;
};


the generated code for gperf -P does not compile in C nor C++.  First, it tries to put integer offsets into the name field, which is an error in C++, not just a warning.  Second, it attempts to add two when verifying a correct match, which is an error in C or C++.

To work around this, I had to run these substitutions on the output:


# fix static type of table entries
s{\Q(int)(long)&\E}{(const char *)&}g;

# return a static structure so we can fix it first
s{stringpool}{(size_t)stringpool} if m{ \b s \s* = \s* wordlist\[ }x;


Chip Salzenberg <chip>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by chip (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-24 haible CategoryNone Generated code
    2013-01-08 haible StatusNone Invalid
        Assigned toNone haible
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code