PR# 18944 [RJ] Use 'const' for C arrays in E1.

Problem Report Summary
Submitter: axarosenberg
Category: Compiler
Priority: Medium
Date: 2014/08/25
Class: Feature Request
Severity: Non-critical
Number: 18944
Release: 14.05.9.5417
Confidential: No
Status: Analyzed
Responsible:
Environment: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Synopsis: [RJ] Use 'const' for C arrays in E1.

Description
I am requesting that the arrays in the generated .c (and .x) files in the E1 folder be marked with 'const'.  I tried this with every array in eskelet.x and it compiled, linked and ran OK.

On Windows, the linker placed this into .rdata which is read-only.  A 'write' will cause an access violation.

Debugging ill behaved C code (the Eiffel run-time?) is hard enough.  You shouldn't allow writes to these arrays.

Randy

p.s.  I am currently trying to debug a crash with no stack trace or exception_trace.log.  It's intermittent, too.
To Reproduce

										
Problem Report Interactions
From:manus_eiffel    Date:2014/09/29    Download   
Maybe a few was not the proper quantitative word to use, but there are arrays that the runtime modifies. The other negative aspect of using `const' is that now we have to update our header files and C files of the runtime to use `const' a lot.

But we will certainly have a look at them.

From:axarosenberg    Date:2014/09/29    Download   
Only a few?  I encourage you to do as many as possible.  I did everything I could find in E1 and only had to back off on two of them (or was I lucky?).

In eparents (ptf):

   /* ANY */
   static EIF_TYPE_INDEX ptf0[] = {0,0xFFFF};


And in evisib (cr):

   static char *(*cr2836[])() = {
   (char *(*)()) 0,
   (char *(*)()) F1_18,
   (char *(*)()) F2709_41139,
   (char *(*)()) F2709_41140,
   ...

Actually, I don't remember why I didn't make that one 'const'.  It may have been too complicated for my puny C skills to figure out where the 'const' goes.

I just glanced at E2, etc.  It looks like you could do 'Y10726_pgtype0'.  You could also do 'O10724[2006]' but the initialization would be very expensive.  But it wouldn't be expensive for 'O10769[5]'!  What you really need here is called "Designated Initializers" (as I just found out).  Unfortunately, it's a C99 addition.  Visual Studio 2013 adds support for it but you may not find it everywhere else.  Apparently, it's not legal in C++ at all
....
Output truncated, Click download to get the full message

From:manus_eiffel    Date:2014/09/29    Status: Analyzed    Download   
Not all arrays are read only, only a few. You are right that those in `eskelet' and `enames' would be good candidate.

We will be looking into those.