Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sat, 22 Sep 2012 15:52:29 Commit: 772509e898a6847117e28156859483993376118e https://github.com/geany/geany/commit/772509e898a6847117e2815685948399337611...
Log Message: ----------- ctags: fix improper use of "const" type qualifier
The external declaration of "File" in read.h (defined in read.c) was improperly tagged as "const" for it not to be modifiable outside of read.c. Although it is good to protect this global variable against improper modification, the use of "const" here makes it perfectly valid for the compiler to assume that the fields in this structure never changes during runtime, thus allowing it to do optimizations on this assumption. However, this assumption is wrong because this structure actually gets modified by many read.c's functions, and thus possibly lead to improper and unexpected behavior if the compiler sees a window for optimizing fields access.
Moreover, protecting "File" as it was with the "const" type qualifier required a hack to be able to include read.h in read.c since "const" and non-"const" declarations conflicts.
Actually, at least the JavaScript parser did suffer of the issue, because it calls getSourceLineNumber() macro (expanding to a direct "File" member access) several times in one single function, making it easy for the compilers to cache the value as an optimization. Both GCC and CLang showed this behavior with optimization enabled. As a result, the line numbers of JavaScript tags were often incorrect.
Modified Paths: -------------- tagmanager/ctags/read.h
Modified: tagmanager/ctags/read.h 9 files changed, 2 insertions(+), 7 deletions(-) =================================================================== @@ -10,12 +10,6 @@ #ifndef _READ_H #define _READ_H
-#if defined(FILE_WRITE) || defined(VAXC) -# define CONST_FILE -#else -# define CONST_FILE const -#endif - /* * INCLUDE FILES */ @@ -96,7 +90,8 @@ enum eCharacters { /* * GLOBAL VARIABLES */ -extern CONST_FILE inputFile File; +/* should not be modified externally */ +extern inputFile File;
/* * FUNCTION PROTOTYPES
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: TBD).