~ubuntu-branches/ubuntu/hoary/swig1.3/hoary

« back to all changes in this revision

Viewing changes to Doc/Devel/internals.html

  • Committer: Bazaar Package Importer
  • Author(s): Thom May
  • Date: 2004-08-02 15:57:10 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040802155710-bm292q1d6x6tw7gc
Tags: 1.3.21-5ubuntu1
Fix linking for ruby, python, perl and tcl bindings

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
</center>
19
19
 
20
20
<p>
21
 
<b>$Header: /cvs/projects/SWIG/Doc/Devel/Attic/internals.html,v 1.1.2.4 2001/07/30 12:14:44 mkoeppe Exp $</b>
 
21
<b>$Header: /cvsroot/SWIG/Doc/Devel/internals.html,v 1.4 2003/09/23 21:38:32 cheetah Exp $</b>
22
22
 
23
23
<p>
24
24
(Note : This is a work in progress.) 
48
48
<li><a name="i5" href="#5">5. Difference Between SWIG 1.1 and SWIG 1.3</a>
49
49
<li><a name="i6" href="#6">6. Plans for SWIG 2.0</a>
50
50
<li><a name="i7" href="#7">7. C/C++ Wrapper Support Functions</a>
51
 
<li><a name="i8" href="#8">8. Reserved</a>
 
51
<li><a name="i8" href="#8">8. Symbol Naming Guidelines for Generated C/C++ Code</a>
52
52
<li><a name="i9" href="#9">9. Reserved</a>
53
53
<li><a name="i10" href="#10">10. Guile Support</a>
54
54
<li><a name="i11" href="#11">11. Python Support</a>
919
919
 
920
920
 
921
921
<a name="8" href="#i8">
922
 
<h2>8. Reserved</h2>
 
922
<h2>8. Symbol Naming Guidelines for Generated C/C++ Code</h2>
923
923
</a>
 
924
The C++ standard (ISO/IEC 14882:1998(E)) states:
 
925
<blockquote>
 
926
<pre>
 
927
<i>
 
928
17.4.3.1.2 Global names [lib.global.names]
 
929
 
 
930
1 Certain sets of names and function signatures are always reserved to the implementation:
 
931
 
 
932
    * Each name that contains a double underscore (__) or begins with an underscore followed 
 
933
      by an upper case letter (2.11) is reserved to the implementation for any use.
 
934
    * Each name that begins with an underscore is reserved to the implementation for use as 
 
935
      a name in the global namespace.165)
 
936
 
 
937
    165) Such names are also reserved in namespace ::std (17.4.3.1). [back to text] 
 
938
</i>
 
939
</pre>
 
940
</blockquote>
 
941
 
 
942
When generating code it is important not to generate symbols that might clash with the code being wrapped. It is tempting to flout the standard or just use a symbol which starts with a single underscore followed by a lowercase letter in order to avoid name clashes. However even these legal symbols can also clash with symbols being wrapped. The following guidelines should be used when generating code in order to meet the standard and make it highly unlikely that symbol clashes will occur:
 
943
<p>
 
944
 
 
945
For C++ code that doesn't attempt to mangle a symbol being wrapped (for example SWIG convenience functions):
 
946
<ul>
 
947
    <li> Put symbols in the <tt>Swig</tt> namespace, for example class <tt>Swig::Director</tt>. Qualify using the <tt>Swig</tt> namespace whenever the symbol is referenced, even within the <tt>Swig</tt> namespace, for example <tt>new Swig::Director()</tt> not <tt>new Director()</tt>.</li>
 
948
    <li> Use <tt>swig_</tt> as a prefix for all member variables and member functions that are involved in an inheritance chain with wrapped classes, for example <tt>Swig::Director::swig_get_up()</tt> and <tt>bool Swig::Director::swig_up</tt>.</li>
 
949
    <li> Alternatively class names can be prefixed with <tt>Swig</tt> in the global namespace for example <tt>template&lt;class T&gt; class SwigValueWrapper</tt>.</li>
 
950
</ul>
 
951
<p>
 
952
 
 
953
For code compiled as C or C++ that doesn't attempt to mangle a symbol being wrapped (for example SWIG convenience functions):
 
954
<ul>
 
955
    <li> Use <tt>SWIG_</tt> as a prefix for structures for example <tt>SWIG_JavaExceptions_t</tt>.</li>
 
956
    <li> Use <tt>SWIG_</tt> as a prefix for global functions for example <tt>SWIG_TypeRegister</tt>. </li>
 
957
    <li> Use <tt>SWIG_</tt> as a prefix for macros for example <tt>#define SWIG_PY_INT 1</tt></li>
 
958
</ul>
 
959
 
 
960
For code compiled as C or C++ that attempts to mangle a wrapped symbol:
 
961
<ul>
 
962
    <li> Use <tt>SWIGxxx</tt> or <tt>Swigxxx</tt> as a prefix where xxx is chosen which would make <tt>SWIGxxx</tt>/<tt>Swigxxx</tt> a unique symbol in the global namespace, for example <tt>class SwigDirectorFoo</tt> when wrapping <tt>class Foo</tt>. Don't use a trailing underscore for the prefix as this may generate a double underscore when wrapping a symbol which starts with a single underscore.</li>
 
963
</ul>
 
964
 
 
965
In the past SWIG has generated many symbols which flout the standard especially double underscores. In fact they may not all be rooted out yet, so please fix them when you see them.
 
966
 
924
967
 
925
968
<a name="9" href="#i9">
926
969
<h2>9. Reserved</h2>