/tags/Root-branch-php-utl/SWIG/Examples/chicken/zlib/example.i

# · Swig · 76 lines · 52 code · 10 blank · 14 comment · 0 complexity · 69084fd365d5117a66aa83ec1adaa8e5 MD5 · raw file

  1. /* File : example.i */
  2. %module example
  3. %{
  4. /* Put headers and other declarations here */
  5. #include "zlib.h"
  6. %}
  7. %include typemaps.i
  8. %rename(VERSION) ZLIB_VERSION;
  9. %rename(z_error) zError;
  10. %apply char * { Bytef * };
  11. /* Allow the sourceLen to be automatically filled in from the length
  12. of the 'source' string */
  13. %typemap(in) (const Bytef *source, uLong sourceLen)
  14. %{ if (!C_swig_is_string ($input)) {
  15. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
  16. }
  17. $2 = (uLong) C_header_size ($input);
  18. $1 = C_c_string ($input);
  19. %}
  20. /* Allocate space the size of which is determined by the Scheme
  21. integer argument, and make a temporary integer so we can set
  22. destLen. */
  23. %typemap(in) (Bytef *dest, uLongf *destLen) (uLong len)
  24. %{ if (!C_swig_is_fixnum ($input)) {
  25. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a integer");
  26. }
  27. len = (uLong) C_unfix ($input);
  28. $2 = &len;
  29. $1 = (char *) malloc (*$2);
  30. %}
  31. /* Return the mutated string as a new object. */
  32. %typemap(argout) (Bytef *dest, uLongf *destLen)
  33. (C_word *scmstr)
  34. %{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
  35. SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1));
  36. free ($1);
  37. %}
  38. %include "zconf.h"
  39. %include "zlib.h"
  40. /* Ignore destLen as an input argument, and make a temporary integer so
  41. we can set destLen. */
  42. %typemap(numinputs=0) uLongf *destLen (uLong len)
  43. "$1 = &len;";
  44. /* Return a sized string as a new object. */
  45. %typemap(argout)
  46. (void *outstr, uLongf *destLen) (C_word *scmstr)
  47. %{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
  48. SWIG_APPEND_VALUE(C_string (&scmstr, *$2, $1));
  49. %}
  50. %inline %{
  51. /* %inline blocks are seen by SWIG and are inserted into the header
  52. portion of example_wrap.c, so that they are also seen by the C
  53. compiler. */
  54. int deflate_init(z_streamp strm, int level) {
  55. return deflateInit(strm,level); /* call macro */
  56. }
  57. int inflate_init(z_streamp strm) {
  58. return inflateInit(strm); /* call macro */
  59. }
  60. void* z_stream_save_next_out(z_streamp strm) {
  61. return (void*) strm->next_out;
  62. }
  63. void z_stream_get_next_chunk(z_streamp strm, void *outstr, uLongf *destLen) {
  64. *destLen = strm->next_out - (Bytef*)outstr;
  65. }
  66. %}