File: overview_cpp_rtti_disabled.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (85 lines) | stat: -rw-r--r-- 7,119 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Caveats When Not Using C++ RTTI</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Caveats When Not Using C++ RTTI </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_cpp_rtti_disabled_bind">Bind() Issues</a></li>
<li class="level1"><a href="#overview_cpp_rtti_disabled_wxany">wxAny Issues</a></li>
</ul>
</div>
<div class="textblock"><dl class="section note"><dt>Note</dt><dd>C++ RTTI is usually enabled by default in most wxWidgets builds. If you do not know if your build has C++ RTTI enabled or not, then it probably is enabled, and you should not worry about anything mentioned in this section.</dd></dl>
<p>While in general wxWidgets standard <a class="el" href="overview_rtti.html">Runtime Type Information (RTTI)</a> is used throughout the library, there are some places where it won't work. One of those places is template classes.</p>
<p>When available, C++ RTTI is used to address this issue. If you have built the library with C++ RTTI disabled, an internal RTTI system is substituted. However, this system is not perfect and one proven scenario where it may break is a shared library or DLL build. More specifically, a template class instance created in one physical binary may not be recognized as its correct type when used in another one.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="overview_rtti.html">Runtime Type Information (RTTI)</a>, <a class="el" href="classwx_evt_handler.html#a0f30c8fa5583b4a5f661897d63de3b62" title="Binds the given function, functor or method dynamically with the event.">wxEvtHandler::Bind()</a>, <a class="el" href="classwx_any.html" title="The wxAny class represents a container for any type.">wxAny</a></dd></dl>
<h1><a class="anchor" id="overview_cpp_rtti_disabled_bind"></a>
Bind() Issues</h1>
<p>wxWidgets 2.9.0 introduced a new <a class="el" href="overview_events.html#overview_events_bind">Dynamic Event Handling</a> system, using <a class="el" href="classwx_evt_handler.html#a0f30c8fa5583b4a5f661897d63de3b62" title="Binds the given function, functor or method dynamically with the event.">wxEvtHandler::Bind&lt;&gt;()</a> and Unbind&lt;&gt;(). This functionality uses templates behind the scenes and therefore is vulnerable to breakage in shared library builds, as described above.</p>
<p>Currently only Unbind&lt;&gt;() needs the type information, so you should be immune to this problem simply if you only need to use Bind&lt;&gt;() and not Unbind&lt;&gt;().</p>
<p>Also, if you only bind and unbind same event handler inside same binary, you should be fine.</p>
<h1><a class="anchor" id="overview_cpp_rtti_disabled_wxany"></a>
wxAny Issues</h1>
<p><a class="el" href="classwx_any.html" title="The wxAny class represents a container for any type.">wxAny</a> is a dynamic type class which transparently uses templates to generate data type handlers, and therefore is vulnerable to breakage in shared library builds, as described above</p>
<p>You should be fine if you only create and use <a class="el" href="classwx_any.html" title="The wxAny class represents a container for any type.">wxAny</a> instances inside same physical binary. However, if you do need to be able to use <a class="el" href="classwx_any.html" title="The wxAny class represents a container for any type.">wxAny</a> freely across binary boundaries, (and for sake of code-safety, you probably do), then specializations for wxAnyValueTypeImpl&lt;&gt; templates need to be defined in one of your shared library (DLL) files. One specialization is required for every data type you use with <a class="el" href="classwx_any.html" title="The wxAny class represents a container for any type.">wxAny</a>. Easiest way to do this is using macros provided in <a class="el" href="any_8h.html">wx/any.h</a>. Note that you <b>do</b> <b>not</b> need to define specializations for C built-in types, nor for <a class="el" href="classwx_string.html" title="String class for passing textual data to or receiving it from wxWidgets.">wxString</a> or <a class="el" href="classwx_date_time.html" title="wxDateTime class represents an absolute moment in time.">wxDateTime</a>, because these are already provided in wxBase. However, you <b>do</b> need to define specializations for all pointer types except char* and wchar_t*.</p>
<p>Let's define a specialization for imaginary type 'MyClass'. In your shared library source code you will need to have this line:</p>
<div class="fragment"><div class="line">WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl&lt;MyClass&gt;)</div>
</div><!-- fragment --><p>In your header file you will need the following:</p>
<div class="fragment"><div class="line">wxDECLARE_ANY_TYPE(MyClass, WXIMPORT_OR_WXEXPORT)</div>
</div><!-- fragment --><p>Where WXIMPORT_OR_WXEXPORT is WXEXPORT when being included from the shared library that called the WX_IMPLEMENT_ANY_VALUE_TYPE() macro, and WXIMPORT otherwise. </p>
</div></div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>