1 %module python_pybuffer 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 10 %inline %{ func1(char * buf1,int len)11 void func1(char *buf1, int len) 12 { 13 int i; 14 for (i=0; i<len; ++i) 15 buf1[i] = 'a'; 16 return; 17 } func2(char * buf2)18 void func2(char *buf2) 19 { 20 strcpy(buf2, "Hello world!"); 21 } func3(const char * buf3,int len)22 int func3(const char *buf3, int len) 23 { 24 int count = 0; 25 int i; 26 for(i=0; i<len; ++i) 27 if (isalnum(buf3[i])) 28 ++count; 29 return count; 30 } func4(const char * buf4)31 size_t func4(const char *buf4) 32 { 33 return strlen(buf4); 34 } 35 %} 36 37 /*functions for the benchmark*/ 38 %pybuffer_mutable_string(char *str1); 39 %cstring_mutable(char *str2); 40 41 %inline %{ title(char * str)42void title(char *str) { 43 int outword = 1; 44 while(*str) { 45 if (isalnum(*str)) { 46 if (outword) { 47 outword = 0; 48 *str = toupper(*str); 49 } 50 } 51 else { 52 outword = 0; 53 } 54 str++; 55 } 56 } 57 title1(char * str1)58void title1(char *str1) { 59 title(str1); 60 } title2(char * str2)61void title2(char *str2) { 62 title(str2); 63 } 64 %} 65