Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aaeef4d

Browse files
committed
GNUmakefile.in - remove backend/utils/Gen_fmgrtab.sh on distclean
varlena.c - part of Thomas' most recent patch
1 parent 75e2370 commit aaeef4d

File tree

2 files changed

+84
-40
lines changed

2 files changed

+84
-40
lines changed

src/GNUmakefile.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.10 1997/02/28 18:45:17 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.11 1997/04/09 08:29:17 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

@@ -79,6 +79,7 @@ distclean: clean
7979
bin/psql/Makefile \
8080
bin/pg_dump/Makefile \
8181
include/config.h \
82+
backend/utils/Gen_fmgrtab.sh \
8283
include/os.h
8384

8485

src/backend/utils/adt/varlena.c

+82-39
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.12 1997/04/02 18:13:24 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.13 1997/04/09 08:29:35 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -285,44 +285,75 @@ textne(struct varlena *arg1, struct varlena *arg2)
285285
return((bool) !texteq(arg1, arg2));
286286
}
287287

288+
/* text_lt()
289+
* Comparison function for text strings.
290+
* Includes locale support, but must copy strings to temporary memory
291+
* to allow null-termination for inputs to strcoll().
292+
* XXX HACK code for textlen() indicates that there can be embedded nulls
293+
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
294+
*/
288295
bool
289296
text_lt(struct varlena *arg1, struct varlena *arg2)
290297
{
298+
bool result;
299+
300+
int cval;
291301
int len;
292302
#ifdef UNSIGNED_CHAR_TEXT
293303
unsigned
294304
#endif
295305
char *a1p, *a2p;
296306

297307
if (arg1 == NULL || arg2 == NULL)
298-
return((bool) 0);
308+
return((bool) FALSE);
299309

300-
a1p = (unsigned char *)VARDATA(arg1);
301-
a2p = (unsigned char *)VARDATA(arg2);
310+
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
302311

303-
if ((len = arg1->vl_len) > arg2->vl_len)
304-
len = arg2->vl_len;
305-
len -= sizeof(int32);
306-
307-
while (len != 0 && *a1p == *a2p)
308-
{
309-
a1p++;
310-
a2p++;
311-
len--;
312-
}
313-
if (len)
314312
#ifdef USE_LOCALE
315-
return (bool) (strcoll(a2p,a1p));
313+
if (!PointerIsValid(a1p = PALLOC(len+1))
314+
|| !PointerIsValid(a2p = PALLOC(len+1))) {
315+
elog(WARN,"Unable to allocate memory for text comparison",NULL);
316+
return(FALSE);
317+
};
318+
319+
memcpy(a1p, VARDATA(arg1), len);
320+
*(a1p+len) = '\0';
321+
memcpy(a2p, VARDATA(arg2), len);
322+
*(a2p+len) = '\0';
323+
324+
cval = strcoll(a1p,a2p);
325+
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2))));
326+
327+
PFREE(a1p);
328+
PFREE(a2p);
329+
330+
return(result);
316331
#else
317-
return (bool) (*a1p < *a2p);
332+
a1p = (unsigned char *)VARDATA(arg1);
333+
a2p = (unsigned char *)VARDATA(arg2);
334+
335+
while (len != 0 && *a1p == *a2p) {
336+
a1p++;
337+
a2p++;
338+
len--;
339+
};
340+
return((bool) (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2))));
318341
#endif
319-
else
320-
return (bool) (arg1->vl_len < arg2->vl_len);
321-
}
322-
342+
} /* text_lt() */
343+
344+
/* text_le()
345+
* Comparison function for text strings.
346+
* Includes locale support, but must copy strings to temporary memory
347+
* to allow null-termination for inputs to strcoll().
348+
* XXX HACK code for textlen() indicates that there can be embedded nulls
349+
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
350+
*/
323351
bool
324352
text_le(struct varlena *arg1, struct varlena *arg2)
325353
{
354+
bool result;
355+
356+
int cval;
326357
int len;
327358
#ifdef UNSIGNED_CHAR_TEXT
328359
unsigned
@@ -332,28 +363,40 @@ text_le(struct varlena *arg1, struct varlena *arg2)
332363
if (arg1 == NULL || arg2 == NULL)
333364
return((bool) 0);
334365

335-
a1p = (unsigned char *)VARDATA(arg1);
336-
a2p = (unsigned char *)VARDATA(arg2);
366+
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
337367

338-
if ((len = arg1->vl_len) > arg2->vl_len)
339-
len = arg2->vl_len;
340-
len -= sizeof(int32); /* varlena! */
341-
342-
while (len != 0 && *a1p == *a2p)
343-
{
344-
a1p++;
345-
a2p++;
346-
len--;
347-
}
348-
if (len)
349368
#ifdef USE_LOCALE
350-
return (bool) (strcoll(a2p,a1p));
369+
if (!PointerIsValid(a1p = PALLOC(len+1))
370+
|| !PointerIsValid(a2p = PALLOC(len+1))) {
371+
elog(WARN,"Unable to allocate memory for text comparison",NULL);
372+
return(FALSE);
373+
};
374+
375+
memcpy(a1p, VARDATA(arg1), len);
376+
*(a1p+len) = '\0';
377+
memcpy(a2p, VARDATA(arg2), len);
378+
*(a2p+len) = '\0';
379+
380+
cval = strcoll(a1p,a2p);
381+
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2))));
382+
383+
PFREE(a1p);
384+
PFREE(a2p);
385+
386+
return(result);
351387
#else
352-
return (bool) (*a1p < *a2p);
388+
a1p = (unsigned char *)VARDATA(arg1);
389+
a2p = (unsigned char *)VARDATA(arg2);
390+
391+
while (len != 0 && *a1p == *a2p) {
392+
a1p++;
393+
a2p++;
394+
len--;
395+
};
396+
397+
return((bool) (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2))));
353398
#endif
354-
else
355-
return ((bool) VARSIZE(arg1) <= VARSIZE(arg2));
356-
}
399+
} /* text_le() */
357400

358401
bool
359402
text_gt(struct varlena *arg1, struct varlena *arg2)

0 commit comments

Comments
 (0)