From 8d404a41cf356b457a813b4d8f626ddaeeaaa630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 25 Jan 2012 22:15:01 -0600 Subject: [PATCH] update to latest SWI. --- os/pl-buffer.c | 12 +++++++----- os/pl-buffer.h | 14 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/os/pl-buffer.c b/os/pl-buffer.c index 5197b497c..89a39543b 100644 --- a/os/pl-buffer.c +++ b/os/pl-buffer.c @@ -19,18 +19,18 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "pl-incl.h" -void +int growBuffer(Buffer b, size_t minfree) { size_t osz = b->max - b->base, sz = osz; size_t top = b->top - b->base; if ( b->max - b->top >= (int)minfree ) - return; + return TRUE; if ( sz < 512 ) sz = 512; /* minimum reasonable size */ @@ -40,12 +40,12 @@ growBuffer(Buffer b, size_t minfree) if ( b->base != b->static_buffer ) { b->base = realloc(b->base, sz); if ( !b->base ) - outOfCore(); + return FALSE; } else /* from static buffer */ { char *new; if ( !(new = malloc(sz)) ) - outOfCore(); + return FALSE; memcpy(new, b->static_buffer, osz); b->base = new; @@ -53,6 +53,8 @@ growBuffer(Buffer b, size_t minfree) b->top = b->base + top; b->max = b->base + sz; + + return TRUE; } diff --git a/os/pl-buffer.h b/os/pl-buffer.h index 763ecf599..a629bf969 100644 --- a/os/pl-buffer.h +++ b/os/pl-buffer.h @@ -19,7 +19,7 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef BUFFER_H_INCLUDED @@ -39,14 +39,16 @@ typedef struct char * top; /* pointer to top */ char * max; /* current location */ char static_buffer[sizeof(char *)]; -} buffer, *Buffer; +} MAY_ALIAS buffer, *Buffer; -void growBuffer(Buffer b, size_t minfree); +int growBuffer(Buffer b, size_t minfree); #define addBuffer(b, obj, type) \ do \ { if ( (b)->top + sizeof(type) > (b)->max ) \ - growBuffer((Buffer)b, sizeof(type)); \ + { if ( !growBuffer((Buffer)b, sizeof(type)) ) \ + outOfCore(); \ + } \ *((type *)(b)->top) = obj; \ (b)->top += sizeof(type); \ } while(0) @@ -57,7 +59,9 @@ void growBuffer(Buffer b, size_t minfree); size_t _len = _tms * sizeof(type); \ type *_d, *_s = (type *)ptr; \ if ( (b)->top + _len > (b)->max ) \ - growBuffer((Buffer)b, _len); \ + { if ( !growBuffer((Buffer)b, _len) ) \ + outOfCore(); \ + } \ _d = (type *)(b)->top; \ while ( _tms-- ) \ *_d++ = *_s++; \