Branch: Tag:

2003-11-09

2003-11-09 01:10:15 by Martin Stjernholm <mast@lysator.liu.se>

Made the interface for the global dynamic buffer reentrant.

Rev: src/apply_low.h:1.25
Rev: src/array.c:1.151
Rev: src/dynamic_buffer.c:1.24
Rev: src/dynamic_buffer.h:1.19
Rev: src/error.c:1.117
Rev: src/interpret.c:1.337
Rev: src/interpret_functions.h:1.161
Rev: src/las.c:1.341
Rev: src/mapping.c:1.173
Rev: src/modules/sprintf/sprintf.c:1.115
Rev: src/multiset.c:1.79
Rev: src/pike_types.c:1.224
Rev: src/program.c:1.530
Rev: src/stralloc.c:1.160
Rev: src/svalue.c:1.179

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: dynamic_buffer.c,v 1.23 2003/04/02 19:22:43 mast Exp $ + || $Id: dynamic_buffer.c,v 1.24 2003/11/09 01:10:13 mast Exp $   */      #include "global.h"
11:   #include "pike_error.h"   #include "pike_memory.h"    - RCSID("$Id: dynamic_buffer.c,v 1.23 2003/04/02 19:22:43 mast Exp $"); + RCSID("$Id: dynamic_buffer.c,v 1.24 2003/11/09 01:10:13 mast Exp $");    - static dynamic_buffer buff; + dynamic_buffer pike_global_buffer;      PMOD_EXPORT char *low_make_buf_space(size_t space, dynamic_buffer *buf)   {
92:   #endif   }    - PMOD_EXPORT dynbuf_string complex_free_buf(void) + PMOD_EXPORT dynbuf_string complex_free_buf(dynamic_buffer *old_buf)   {    dynbuf_string tmp; -  if(!buff.s.str) return buff.s; +  if(!pike_global_buffer.s.str) return pike_global_buffer.s;    my_putchar(0); -  buff.s.len--; -  tmp=buff.s; -  buff.s.str=0; +  pike_global_buffer.s.len--; +  tmp=pike_global_buffer.s; +  pike_global_buffer = *old_buf;    return tmp;   }   
109:    buf->s.str=0;   }    - PMOD_EXPORT char *simple_free_buf(void) + PMOD_EXPORT char *simple_free_buf(dynamic_buffer *old_buf)   { -  if(!buff.s.str) return 0; -  return complex_free_buf().str; +  if(!pike_global_buffer.s.str) return 0; +  return complex_free_buf(old_buf).str;   }      PMOD_EXPORT struct pike_string *debug_low_free_buf(dynamic_buffer *buf)
126:    return q;   }    - PMOD_EXPORT struct pike_string *debug_free_buf(void) { return low_free_buf(&buff); } - PMOD_EXPORT char *make_buf_space(INT32 space) { return low_make_buf_space(space,&buff); } - PMOD_EXPORT void my_putchar(int b) { low_my_putchar(b,&buff); } - PMOD_EXPORT void my_binary_strcat(const char *b, ptrdiff_t l) { low_my_binary_strcat(b,l,&buff); } - PMOD_EXPORT void my_strcat(const char *b) { my_binary_strcat(b,strlen(b)); } - PMOD_EXPORT void initialize_global_buf(void) { buff.s.str = NULL; } - PMOD_EXPORT void init_buf(void) { low_reinit_buf(&buff); } - PMOD_EXPORT void init_buf_with_string(dynbuf_string s) { low_init_buf_with_string(s,&buff); } + PMOD_EXPORT struct pike_string *debug_free_buf(dynamic_buffer *old_buf) + { +  struct pike_string *res = low_free_buf(&pike_global_buffer); +  pike_global_buffer = *old_buf; +  return res; + } +  + PMOD_EXPORT char *make_buf_space(INT32 space) + { +  return low_make_buf_space(space,&pike_global_buffer); + } +  + PMOD_EXPORT void my_putchar(int b) + { +  low_my_putchar(b,&pike_global_buffer); + } +  + PMOD_EXPORT void my_binary_strcat(const char *b, ptrdiff_t l) + { +  low_my_binary_strcat(b,l,&pike_global_buffer); + } +  + PMOD_EXPORT void my_strcat(const char *b) + { +  my_binary_strcat(b,strlen(b)); + } +  + PMOD_EXPORT void init_buf(dynamic_buffer *old_buf) + { +  *old_buf = pike_global_buffer; +  pike_global_buffer.s.str = NULL; +  initialize_buf(&pike_global_buffer); + } +  + PMOD_EXPORT void init_buf_with_string(dynamic_buffer *old_buf, dynbuf_string s) + { +  *old_buf = pike_global_buffer; +  pike_global_buffer.s.str = NULL; +  low_init_buf_with_string(s,&pike_global_buffer); + } +  + PMOD_EXPORT void save_buffer (dynamic_buffer *save_buf) + { +  *save_buf = pike_global_buffer; +  pike_global_buffer.s.str = NULL; + } +  + PMOD_EXPORT void restore_buffer (dynamic_buffer *save_buf) + { + #ifdef PIKE_DEBUG +  if (pike_global_buffer.s.str) +  Pike_fatal ("Global buffer already in use.\n"); + #endif +  pike_global_buffer = *save_buf; + } +  + #if 0   PMOD_EXPORT char *debug_return_buf(void)   {    my_putchar(0); -  return buff.s.str; +  return pike_global_buffer.s.str;   } - /* int my_get_buf_size() { return buff->s.len; } */ + #endif +  + /* int my_get_buf_size() { return pike_global_buffer->s.len; } */