A list of ways to avoid c++ and Python problems on the RHEL4 platform This is
HTML, i.e. for a Wiki page.
----------------------------------------------------------------------------------------------------------
Key: QPID-915
URL: https://issues.apache.org/jira/browse/QPID-915
Project: Qpid
Issue Type: Improvement
Components: C++ Broker
Environment: RHEL4
Reporter: michael goulish
<HTML>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><FONT FACE="URW Chancery L"><FONT
SIZE=6>A
RHEL4 Grimoire</FONT></FONT></P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"> by Michael Goulish on this
11th day of April, 2008</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">Introduction</H1>
<P STYLE="margin-bottom: 0in"><I>Programmer! Turn back now, if you
can, to the daylit world! </I>
</P>
<P STYLE="margin-bottom: 0in"><I>But if you must walk this road --
take with you this map! Do not stray into the mires and pits where I
have wandered and despaired.</I></P>
<P STYLE="margin-bottom: 0in"><I>Herein I will describe what I can of
the perils I have encountered in the antique land of RHEL4. </I>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">
</P>
<H1 CLASS="western">1. Iterators and the "->" operator.</H1>
<P STYLE="margin-bottom: 0in">I believe this is a compiler problem
with the -> operator, in the neighborhood of any kind of
iterators.</P>
<P STYLE="margin-bottom: 0in">Code like this will not compile:</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">ConsumerImplMap::iterator
i = consumers.find(delivery.getTag());</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">if
(i != consumers.end())</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">{</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">get_pointer(i)->acknowledged(delivery);
<FONT COLOR="#ff0000"><B>// <--- Bad!</B></FONT></FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">}</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">Do this instead:</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">ConsumerImplMap::iterator
i = consumers.find(delivery.getTag());</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">if
(i != consumers.end())</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">{</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">(*i).second->complete(delivery);
<FONT COLOR="#ff0000"><B>// <--- Good!</B></FONT></FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">}</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"> <I>( Thanks, Kim! ) </I>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">2. Don't use BOOST_FIXTURE_TEST_CASE</H1>
<P STYLE="margin-bottom: 0in">Because it Doesn't Exist.</P>
<P STYLE="margin-bottom: 0in">All it does is allow you to use a class
(or struct) declaration in many test cases without declaring it in
every one.
</P>
<P STYLE="margin-bottom: 0in">So what? Big deal! Just declare your
structure in each test case, and use the <FONT
COLOR="#004586">QPID_AUTO_TEST_CASE</FONT>
macro instead!
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"> If you have this struct:</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"> <FONT FACE="Courier
10 Pitch">struct
ClientSessionFixture : public Foo</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier
10 Pitch">{</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier
10 Pitch">int
bar;</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier
10 Pitch">};</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">Don't do this:</P>
<P STYLE="margin-bottom: 0in">
<FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">BOOST_FIXTURE_TEST_CASE(testQueueQuery,
ClientSessionFixture)</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">{</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">bar
= 666;</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">BOOST_CHECK_EQUAL ( bar, 666 );</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">}</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">Do do this:</P>
<P STYLE="margin-bottom: 0in">
<FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">QPID_AUTO_TEST_CASE(testQueueQuery)</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">{</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">ClientSessionFixture fix;</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">fix.bar
= 666;</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">BOOST_CHECK_EQUAL ( fix.bar, 666
);</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">}</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"> <I>(Thanks, Alan!)</I></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">3. Don't use the BOOST_*_TEST_* macros !</H1>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">If you are tempted to use
</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586">
</FONT><FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">BOOST_AUTO_TEST_SUITE</FONT></FONT>,
or</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">BOOST_AUTO_TEST_CASE</FONT></FONT>,
or</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">BOOST_AUTO_TEST_SUITE_END</FONT></FONT>,</P>
<P STYLE="margin-bottom: 0in">dont!</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">Use instead:</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">QPID_AUTO_TEST_SUITE</FONT></FONT>,
or</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">QPID_AUTO_TEST_CASE</FONT></FONT>,
or</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">QPID_AUTO_TEST_SUITE_END</FONT></FONT>
!</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">They turn into Appropriate Things
depending on the version of Boost you are using.
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">Sometimes the Appropriate Thing is
whitespace...</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"> <I>(Thanks, Alan and Kim !)</I></P>
<P STYLE="margin-bottom: 0in">
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">4. Don't use boost::iostreams.</H1>
<P STYLE="margin-bottom: 0in">They don't exist.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">/usr/include/boost/iostreams/:
No such file or directory</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">Instead, use low-level Unix IO, from
the Dawn of Time.</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">open()</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">read()</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">write()</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">5. Don't use the Boost timestamp code!</H1>
<P STYLE="margin-bottom: 0in">It does not exist! Use old stuff
instead!</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">No!
</P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">#include
<boost/date_time/posix_time/posix_time.hpp></FONT></FONT></P>
<P STYLE="margin-bottom: 0in">Yes!
</P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">#include
<time.h></FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">6. In gcc 3.3, c++ vectors did not have data().</H1>
<P STYLE="margin-bottom: 0in">They did have a function called <FONT
COLOR="#004586"><FONT FACE="Courier 10 Pitch">front()
</FONT></FONT>which returns an iterator.</P>
<P STYLE="margin-bottom: 0in">Try to use that instead.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">7. The old compiler is not as clever as the new
compiler...</H1>
<P STYLE="margin-bottom: 0in"> ...and it can be confused.</P>
<P STYLE="margin-bottom: 0in">Templatized classes with templatized
parent classes that typedef templatized classes, declare them to be
friends, and then have their private parts accessed by those friends
-- are a good way to get the compiler to throw a shoe and break a
leg.</P>
<P STYLE="margin-bottom: 0in">After that, the compiler never heals
properly, and has to be put down.</P>
<P STYLE="margin-bottom: 0in">For examples, just look at any of
Alan's code...</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">8. Don't use BOOST_REQUIRE_EQUAL</P>
<P STYLE="margin-bottom: 0in">change
</P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10 Pitch">BOOST_REQUIRE_EQUAL ( L, R )</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">to
</P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">BOOST_REQUIRE
( L == R )</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">9. Python: don't use the "@staticmethod"
syntax.</H1>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT FACE="Courier 10
Pitch">@staticmethod</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">def
foo():</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">blah</FONT></FONT>
</P>
<P STYLE="margin-bottom: 0in">will need to be changed to this:</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">def
foo():</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">blah</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">foo
= staticmethod(foo)</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"> <I>(Thanks, Rafi!)</I></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">10. Python: don't use shutdown()</H1>
<P STYLE="margin-bottom: 0in">replace
</P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586">
<FONT FACE="Courier 10
Pitch">self.sock.shutdown(socket.SHUT_RDWR)</FONT></FONT></P>
<P STYLE="margin-bottom: 0in">with
</P>
<P STYLE="margin-bottom: 0in"> <FONT COLOR="#004586"><FONT
FACE="Courier 10 Pitch">self.sock.shutdown(socket.2)</FONT></FONT></P>
<P STYLE="margin-bottom: 0in"><FONT COLOR="#004586"> <FONT FACE="Courier 10
Pitch">self.close()
</FONT></FONT>
</P>
<P STYLE="margin-bottom: 0in"> <I>( Thanks, Alan, Rafi ! )</I></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<H1 CLASS="western">Conclusion</H1>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">That's about all I know now. If you
find more perils, please let me know, and I will add them to this
document. ( Or of course feel free to edit this yourself! )</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
</HTML>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.