PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Doc/Devel/migrate.txt

#
Plain Text | 140 lines | 104 code | 36 blank | 0 comment | 0 complexity | e62a82d98599ed10529ccec0db0d7e03 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. SWIG1.3 Migration Guide
  2. (The not entirely complete guide to updating language modules to work with SWIG1.3).
  3. Dave Beazley
  4. August 15, 2000
  5. 1. Introduction
  6. ---------------
  7. Virtually all of SWIG's internal data structures have now been
  8. rewritten. Take everything you thought you knew about SWIG1.1 and
  9. throw it out.
  10. 2. DataTypes
  11. ------------
  12. The old 'DataType' data structure is gone. Therefore, direct
  13. manipulation of 'is_pointer', 'implicit_ptr', and 'arraystr'
  14. attributes no longer applies. Sorry.
  15. Datatypes are now represented by the type 'SwigType' which has no
  16. public attributes. Actually, if you look at it closely, 'SwigType' is
  17. really just an alias for 'void' and if you look at it even closer than
  18. that you will realize that it's nothing more than a string!
  19. The string encoding of types is described in more detail in the file
  20. Source/Swig/stype.c and is not so important here. What is important is
  21. the functions used to produce various types of output:
  22. SwigType_str(type,name = 0);
  23. This produces an exact C representation of the datatype with all
  24. qualifiers, arrays, references, and so forth. name is an optional
  25. name that is given if you wanted to associate the type with a
  26. parameter name or something.
  27. SwigType_lstr(type,name = 0);
  28. This function takes a type and produces a C string containing
  29. a type suitable for assignment (appearing as an lvalue in an
  30. expression). To do this, certain things such as 'const',
  31. arrays, and references are stripped away or converted into
  32. pointers.
  33. SwigType_ltype(type);
  34. Returns a SwigType object corresponding to the type created
  35. by SwigType_lstr().
  36. SwigType_lcaststr(type,name);
  37. Produces a string casting a value 'name' from the real datatype
  38. to the assignable type created by SwigType_lstr().
  39. SwigType_rcaststr(type,name)
  40. Produces a string that casts a value 'name' from the type
  41. created by SwigType_lstr() to the real datatype.
  42. SwigType_manglestr(type)
  43. Produces the 'mangled' version of a datatype.
  44. Getting the 'type' code. Most language modules still operate by
  45. looking at special integer type codes. This interface is a little
  46. ragged and will probably go away at some point. However, for now the
  47. following function can be used to get the type code:
  48. int SwigType_type(type)
  49. The codes are the same as the before, except that there are a few
  50. special codes:
  51. T_STRING - The 'char *' type and variations.
  52. T_POINTER - Any pointer type (not char * though)
  53. T_REFERENCE - Any C++ reference
  54. T_ARRAY - Any array
  55. T_FUNCTION - A function (this is usually an error).
  56. Because of the special codes, it is no longer necessary to have code like this:
  57. if ((t->is_pointer == 1) and (t->type == T_CHAR)) {
  58. ... get a string ...
  59. }
  60. Instead, just use the type code above like this:
  61. switch(SwigType_type(type)) {
  62. case T_STRING:
  63. ... get a string ...
  64. break;
  65. case T_POINTER:
  66. ... get a pointer ...
  67. break;
  68. }
  69. There are about 2-dozen type manipulation functions that could also be useful.
  70. See Source/Swig/swig.h and Source/Swig/stype.c.
  71. 3. Parameter Lists
  72. ------------------
  73. The ParmList data structure is gone. In reality, parameter lists are nothing more than
  74. a linked list of parameters. The proper way to iterate over this list and get
  75. parameter values is as follows:
  76. ParmList *l;
  77. Parm *p;
  78. for (p = l; p; p = Getnext(p)) {
  79. SwigType *pt = Gettype(p); /* Get parameter type */
  80. String *pn = Getname(p); /* Get parameter name */
  81. String *value = Getvalue(p); /* Get parameter value */
  82. ...
  83. do whatever
  84. ...
  85. }
  86. 4. Typemaps
  87. -----------
  88. Typemaps more or less work. However, the interface has changed slightly. Instead of
  89. typemap_lookup("in","python",type,pname,"$source","$target",wrapper);
  90. the function is
  91. Swig_typemap_lookup("in",type,pname,"$source","$target",wrapper);
  92. There are a variety of other changes to typemaps (see CHANGES).
  93. 5. Use of new types
  94. -------------------
  95. When possible, language modules should try to use the built in String,
  96. List, and Hash objects instead of C arrays or 'char *'. This will probably require a
  97. detailed pass through the code with an eye towards cleanup.
  98. 6. Miscellaneous
  99. ----------------
  100. Language modules no longer need to concern themselves with formatting the
  101. wrapper code they produce (provided you are using the special Wrapper object).
  102. The function Wrapper_print() passes everything through a pretty-printer that
  103. automatically performs indentation and tries to clean things up. This especially
  104. works well when there are lots of typemaps.