-
Jim Meyering authored
Summary: The first (and sometimes 2nd) argument to __attribute__ should begin and end with "__". If it does not, then it is at risk of conflicting with user cpp-defined symbols. Don't do that. This change mechanically corrects most such violations in fbcode. A companion change (see parent task) adds a lint rule to help keep things clean going forwards. Define this function to filter the list of file names to which we will apply the transformations. First, ensure we modify only C and C++ sources. The second process excludes a few directories that appear to contain third-party code: filter() { grep -E '\.(c|h|cc|cpp|hpp)$' | grep -vE \ '^external/|/unbound/|/gearmand_|(3rd|third.)party|/external/libevent' } then, run this command, git grep -l __attribute__ | filter \ | xargs perl -pi -e 's/(__attribute__ *)\(\(( *[^_]\w+)/$1((__${2}__/g' inducing changes like this, for each such keyword: -} __attribute__((packed)); +} __attribute__((__packed__)); That got all but the __format__ archetype arguments like this: __attribute__((__format__(printf. That final "printf" keyword should have the "__" prefix and suffix, too. Run this command to transform those remaining uses: git grep -l '__attribute__.*__format' | filter | xargs perl -pi -e \ 's/(__attribute__ *\(\(__format__ *)\( *(printf|scanf|strftime|strfmon)/$1(__${2}__/g' That command induces changes like this: -static inline int __attribute__ ((__format__ (printf, 3, 4))) +static inline int __attribute__ ((__format__ (__printf__, 3, 4))) This exercise is useful to avoid spurious name-space conflicts, especially when the unprotected keyword is used in a header file. Test Plan: I've ensured tao builds and passes its tests. I will watch the arc-run tests. Reviewed By: njormrod@fb.com Subscribers: rounak, trunkagent, hphp-diffs@, nli, ps, fbcode-common-diffs@, mcdonald, chaoyc, bill, search-fbcode-diffs@, lars, net-systems@, davejwatson, varunk, ruibalp, hero-diffs@, andrewcox, sorg, dfechete, dhruba, sdoroshenko, mcduff, marccelani, hitesh, mshneer, cold-storage-diffs@, omry, jcoens, unicorn-diffs@, ldbrandy, sumeet, abirchall, fugalh, atlas2-eng@, dcapra, mpawlowski, alandau, nkgupta, shilin, bmatheny, everstore-dev@, zhuohuang, wormhole-diffs@, vnalla, msk, maoy, mwa, jgehring, adsatlasreporting@, mconnor, oujin, bwester, micha, tulloch, ptc, logdevice-diffs, alikhtarov, shikong, fuegen FB internal diff: D1508983 Tasks: 4947824 @override-unit-failures
a42878e3