diff --git a/Lib/python/cstrbase.swg b/Lib/python/cstrbase.swg index f69208aa5..2938d24c0 100644 --- a/Lib/python/cstrbase.swg +++ b/Lib/python/cstrbase.swg @@ -29,15 +29,16 @@ * */ -#define Name ## _input_binary(TYPEMAP, SIZE) \ -%typemap(in, fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE) \ - (Char *buf, size_t size) \ -{ \ - SWIG_AsCharPtrAndSize($input, &buf, &size); \ - if (SWIG_arg_fail($argnum)) SWIG_fail; \ - $1 = ($1_ltype) buf; \ - $2 = ($2_ltype) size - 1; \ -} +%define Name ## _input_binary(TYPEMAP, SIZE) +%typemap(in, fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE) + (Char *buf, size_t size) +{ + SWIG_AsCharPtrAndSize($input, &buf, &size); + if (SWIG_arg_fail($argnum)) SWIG_fail; + $1 = ($1_ltype) buf; + $2 = ($2_ltype) size - 1; +} +%enddef /* @@ -53,13 +54,13 @@ * */ -#define Name ## _bounded_output(TYPEMAP,MAX) \ -%typemap(in,numinputs=0) TYPEMAP(Char temp[MAX+1]) \ - "$1 = ($1_ltype) temp;"; \ - \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr ) TYPEMAP \ +%define Name ## _bounded_output(TYPEMAP,MAX) +%typemap(in,numinputs=0) TYPEMAP(Char temp[MAX+1]) + "$1 = ($1_ltype) temp;"; + +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr ) TYPEMAP "$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));"; - +%enddef /* @@ -75,12 +76,13 @@ * */ -#define Name ## _chunk_output(TYPEMAP,SIZE) \ -%typemap(in,numinputs=0) TYPEMAP(Char temp[SIZE]) \ - "$1 = ($1_ltype) temp;"; \ - \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) TYPEMAP \ +%define Name ## _chunk_output(TYPEMAP,SIZE) +%typemap(in,numinputs=0) TYPEMAP(Char temp[SIZE]) + "$1 = ($1_ltype) temp;"; + +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) TYPEMAP "$result = t_output_helper($result, SWIG_FromCharArray($1,SIZE));"; +%enddef /* @@ -99,19 +101,19 @@ */ -#define Name ## _bounded_mutable(TYPEMAP,MAX) \ -%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP(Char temp[MAX+1]) { \ - Char *t = 0; size_t n; \ - SWIG_AsCharPtrAndSize($input, &t, &n); \ - if (SWIG_arg_fail($argnum)) SWIG_fail; \ - if ( n > (size_t)MAX ) n = (size_t)MAX; \ - memcpy(temp, t, sizeof(Char)*n); \ - temp[n] = 0; \ - $1 = ($1_ltype) temp; \ -} \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP \ +%define Name ## _bounded_mutable(TYPEMAP,MAX) +%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP(Char temp[MAX+1]) { + Char *t = 0; size_t n; + SWIG_AsCharPtrAndSize($input, &t, &n); + if (SWIG_arg_fail($argnum)) SWIG_fail; + if ( n > (size_t)MAX ) n = (size_t)MAX; + memcpy(temp, t, sizeof(Char)*n); + temp[n] = 0; + $1 = ($1_ltype) temp; +} +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP "$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));"; - +%enddef /* @@ -130,22 +132,26 @@ * */ -#define Name ## _mutable(TYPEMAP,EXP...) \ -%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP { \ - const size_t expansion = strlen(#EXP) ? atoi(#EXP) : 0; \ - Char* t = 0; size_t n = 0; \ - SWIG_AsCharPtrAndSize($input, &t, &n); \ - if (SWIG_arg_fail($argnum)) SWIG_fail; \ - $1 = SWIG_new_array(n+1+expansion, $*1_ltype); \ - memcpy($1,t,sizeof(Char)*n); \ - $1[n] = 0; \ -} \ - \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { \ - $result = t_output_helper($result,SWIG_FromCharPtr($1));\ - SWIG_delete_array($1); \ +%define Name ## _mutable(TYPEMAP,EXP...) +%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP { +#if #EXP == "" + const size_t expansion = 1; +#else + const size_t expansion = 1 + EXP; +#endif + Char* t = 0; size_t n = 0; + SWIG_AsCharPtrAndSize($input, &t, &n); + if (SWIG_arg_fail($argnum)) SWIG_fail; + $1 = SWIG_new_array(n+expansion, $*1_ltype); + memcpy($1,t,sizeof(Char)*n); + $1[n] = 0; +} + +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { + $result = t_output_helper($result,SWIG_FromCharPtr($1)); + SWIG_delete_array($1); } - +%enddef /* * %cstring_output_maxsize(TYPEMAP, SIZE) @@ -158,16 +164,17 @@ * } */ -#define Name ## _output_maxsize(TYPEMAP, SIZE) \ -%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { \ - $2 = ($2_ltype) SWIG_As(unsigned long)($input); \ - if (SWIG_arg_fail($argnum)) SWIG_fail; \ - $1 = SWIG_new_array($2+1, $*1_ltype); \ -} \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) { \ - $result = t_output_helper($result,SWIG_FromCharPtr($1)); \ - SWIG_delete_array($1); \ +%define Name ## _output_maxsize(TYPEMAP, SIZE) +%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { + $2 = ($2_ltype) SWIG_As(unsigned long)($input); + if (SWIG_arg_fail($argnum)) SWIG_fail; + $1 = SWIG_new_array($2+1, $*1_ltype); +} +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) { + $result = t_output_helper($result,SWIG_FromCharPtr($1)); + SWIG_delete_array($1); } +%enddef @@ -184,19 +191,20 @@ * } */ -#define Name ## _output_withsize(TYPEMAP, SIZE) \ -%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { \ - size_t n = SWIG_As(unsigned long)($input); \ - if (SWIG_arg_fail($argnum)) SWIG_fail; \ - $1 = SWIG_new_array(n+1, $*1_ltype); \ - $2 = SWIG_new($*2_ltype); \ - *$2 = n; \ -} \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) { \ - $result = t_output_helper($result, SWIG_FromCharArray($1,*$2)); \ - SWIG_delete_array($1); \ - SWIG_delete($2); \ +%define Name ## _output_withsize(TYPEMAP, SIZE) +%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { + size_t n = SWIG_As(unsigned long)($input); + if (SWIG_arg_fail($argnum)) SWIG_fail; + $1 = SWIG_new_array(n+1, $*1_ltype); + $2 = SWIG_new($*2_ltype); + *$2 = n; +} +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) { + $result = t_output_helper($result, SWIG_FromCharArray($1,*$2)); + SWIG_delete_array($1); + SWIG_delete($2); } +%enddef /* @@ -212,16 +220,17 @@ * } */ -#define Name ## _output_allocate(TYPEMAP, RELEASE) \ -%typemap(in,numinputs=0) TYPEMAP($*1_ltype temp = 0) \ - "$1 = &temp;"; \ - \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { \ - if (*$1) { \ - $result = t_output_helper($result,SWIG_FromCharPtr(*$1));\ - RELEASE; \ - } \ -} \ +%define Name ## _output_allocate(TYPEMAP, RELEASE) +%typemap(in,numinputs=0) TYPEMAP($*1_ltype temp = 0) + "$1 = &temp;"; + +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { + if (*$1) { + $result = t_output_helper($result,SWIG_FromCharPtr(*$1)); + RELEASE; + } +} +%enddef /* @@ -238,17 +247,17 @@ * } */ -#define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE) \ -%typemap(in,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) \ - "$1 = &temp; $2 = &tempn;"; \ - \ -%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray)(TYPEMAP,SIZE) { \ - if (*$1) { \ - $result = t_output_helper($result,SWIG_FromCharArray(*$1,*$2)); \ - RELEASE; \ - } \ -} \ - +%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE) +%typemap(in,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) + "$1 = &temp; $2 = &tempn;"; + +%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray)(TYPEMAP,SIZE) { + if (*$1) { + $result = t_output_helper($result,SWIG_FromCharArray(*$1,*$2)); + RELEASE; + } +} +%enddef %enddef diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 070cfc3a5..dff2ad492 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -1072,6 +1072,7 @@ Preprocessor_parse(String *s) int start_line = 0; int allow = 1; int level = 0; + int dlevel = 0; int mask = 0; int start_level = 0; int cpp_lines = 0; @@ -1556,6 +1557,7 @@ Preprocessor_parse(String *s) state = 1; } else if (Cmp(decl,"%define") == 0) { /* Got a define directive */ + dlevel++; add_chunk(ns,chunk,allow); copy_location(s,chunk); Clear(value); @@ -1574,27 +1576,39 @@ Preprocessor_parse(String *s) case 150: Putc(c,value); if (c == '%') { + const char *ed = "enddef"; + const char *df = "define"; + char statement[7]; int i = 0; - char *d = "enddef"; - for (i = 0; i < 6; i++) { + for (i = 0; i < 6; ) { c = Getc(s); Putc(c,value); - if (c != d[i]) break; + statement[i++] = c; + if (strncmp(statement, ed, i) && strncmp(statement, df, i)) break; } c = Getc(s); Ungetc(c,s); if ((i == 6) && (isspace(c))) { - /* Got the macro */ - for (i = 0; i < 7; i++) { - Delitem(value,DOH_END); - } - if (allow) { - Seek(value,0,SEEK_SET); - Preprocessor_define(value,1); - } - Putc('\n',ns); - addline(ns,value,0); - state = 0; + if (strncmp(statement, df, i) == 0) { + ++dlevel; + } else { + if (strncmp(statement, ed, i) == 0) { + --dlevel; + if (!dlevel) { + /* Got the macro */ + for (i = 0; i < 7; i++) { + Delitem(value,DOH_END); + } + if (allow) { + Seek(value,0,SEEK_SET); + Preprocessor_define(value,1); + } + Putc('\n',ns); + addline(ns,value,0); + state = 0; + } + } + } } } break;