PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/python_pybuf.i

#
Swig | 64 lines | 58 code | 4 blank | 2 comment | 0 complexity | 0c4196fa682b5475f90fd7dc4ec7a96e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module python_pybuf
  2. %include<pybuffer.i>
  3. %include<cstring.i>
  4. /*functions for the test case*/
  5. %pybuffer_mutable_binary(char *buf1, int len);
  6. %pybuffer_mutable_string(char *buf2);
  7. %pybuffer_binary(const char *buf3, int len);
  8. %pybuffer_string(const char *buf4);
  9. %inline %{
  10. void func1(char *buf1, int len)
  11. {
  12. int i;
  13. for (i=0; i<len; ++i)
  14. buf1[i] = 'a';
  15. return;
  16. }
  17. void func2(char *buf2)
  18. {
  19. strcpy(buf2, "Hello world!");
  20. }
  21. int func3(const char *buf3, int len)
  22. {
  23. int count = 0;
  24. int i;
  25. for(i=0; i<len; ++i)
  26. if (isalnum(buf3[i]))
  27. ++count;
  28. return count;
  29. }
  30. int func4(const char *buf4)
  31. {
  32. return strlen(buf4);
  33. }
  34. %}
  35. /*functions for the benchmark*/
  36. %pybuffer_mutable_string(char *str1);
  37. %cstring_mutable(char *str2);
  38. %inline %{
  39. void title(char *str) {
  40. int outword = 1;
  41. while(*str) {
  42. if (isalnum(*str)) {
  43. if (outword) {
  44. outword = 0;
  45. *str = toupper(*str);
  46. }
  47. }
  48. else {
  49. outword = 0;
  50. }
  51. str++;
  52. }
  53. }
  54. void title1(char *str1) {
  55. title(str1);
  56. }
  57. void title2(char *str2) {
  58. title(str2);
  59. }
  60. %}