=== Applying patches on top of PostgreSQL commit ID 9f4fd119b2cbb9a41ec0c19a8d6ec9b59b92c125 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sat Feb 14 23:18:22 UTC 2026 On branch cf/6454 nothing to commit, working tree clean === using 'git am' to apply patch ./v4-0001-Use-correct-collation-for-lowercasing.patch === Applying: Use correct collation for lowercasing .git/rebase-apply/patch:136: new blank line at EOF. + warning: 1 line adds whitespace errors. Using index info to reconstruct a base tree... M contrib/pg_trgm/Makefile M contrib/pg_trgm/meson.build M contrib/pg_trgm/trgm.h M contrib/pg_trgm/trgm_gist.c M contrib/pg_trgm/trgm_op.c M contrib/pg_trgm/trgm_regexp.c Falling back to patching base and 3-way merge... Auto-merging contrib/pg_trgm/trgm_regexp.c CONFLICT (content): Merge conflict in contrib/pg_trgm/trgm_regexp.c Auto-merging contrib/pg_trgm/trgm_op.c CONFLICT (content): Merge conflict in contrib/pg_trgm/trgm_op.c Auto-merging contrib/pg_trgm/trgm_gist.c Auto-merging contrib/pg_trgm/trgm.h Auto-merging contrib/pg_trgm/meson.build Auto-merging contrib/pg_trgm/Makefile CONFLICT (content): Merge conflict in contrib/pg_trgm/Makefile error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Use correct collation for lowercasing When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M contrib/pg_trgm/Makefile M contrib/pg_trgm/meson.build M contrib/pg_trgm/trgm.h M contrib/pg_trgm/trgm_gin.c M contrib/pg_trgm/trgm_gist.c M contrib/pg_trgm/trgm_op.c M contrib/pg_trgm/trgm_regexp.c Removing contrib/pg_trgm/expected/pg_trgm_collation.out Removing contrib/pg_trgm/expected/pg_trgm_collation_1.out Removing contrib/pg_trgm/sql/pg_trgm_collation.sql === using patch(1) to apply patch ./v4-0001-Use-correct-collation-for-lowercasing.patch === patching file contrib/pg_trgm/Makefile Hunk #1 FAILED at 14. 1 out of 1 hunk FAILED -- saving rejects to file contrib/pg_trgm/Makefile.rej patching file contrib/pg_trgm/expected/pg_trgm_collation.out patching file contrib/pg_trgm/expected/pg_trgm_collation_1.out patching file contrib/pg_trgm/meson.build Hunk #1 succeeded at 42 with fuzz 1 (offset 1 line). patching file contrib/pg_trgm/sql/pg_trgm_collation.sql patching file contrib/pg_trgm/trgm.h patching file contrib/pg_trgm/trgm_gin.c patching file contrib/pg_trgm/trgm_gist.c patching file contrib/pg_trgm/trgm_op.c Hunk #1 FAILED at 324. Hunk #2 FAILED at 352. Hunk #3 succeeded at 553 with fuzz 1 (offset 148 lines). Hunk #4 FAILED at 415. Hunk #5 succeeded at 814 (offset 143 lines). Hunk #6 FAILED at 697. Hunk #7 succeeded at 1043 with fuzz 1 (offset 128 lines). Hunk #8 FAILED at 948. Hunk #9 succeeded at 1134 (offset 127 lines). Hunk #10 succeeded at 1301 (offset 127 lines). Hunk #11 succeeded at 1323 (offset 127 lines). Hunk #12 succeeded at 1339 (offset 127 lines). Hunk #13 succeeded at 1349 (offset 127 lines). Hunk #14 succeeded at 1360 (offset 127 lines). Hunk #15 succeeded at 1377 (offset 127 lines). Hunk #16 succeeded at 1393 (offset 127 lines). Hunk #17 succeeded at 1409 (offset 127 lines). Hunk #18 succeeded at 1425 (offset 127 lines). Hunk #19 succeeded at 1441 (offset 127 lines). Hunk #20 succeeded at 1458 (offset 127 lines). Hunk #21 succeeded at 1475 (offset 127 lines). Hunk #22 succeeded at 1491 (offset 127 lines). 5 out of 22 hunks FAILED -- saving rejects to file contrib/pg_trgm/trgm_op.c.rej patching file contrib/pg_trgm/trgm_regexp.c Hunk #1 FAILED at 479. Hunk #6 FAILED at 808. Hunk #7 FAILED at 825. Hunk #8 FAILED at 857. 4 out of 8 hunks FAILED -- saving rejects to file contrib/pg_trgm/trgm_regexp.c.rej Unstaged changes after reset: M contrib/pg_trgm/meson.build M contrib/pg_trgm/trgm.h M contrib/pg_trgm/trgm_gin.c M contrib/pg_trgm/trgm_gist.c M contrib/pg_trgm/trgm_op.c M contrib/pg_trgm/trgm_regexp.c Removing contrib/pg_trgm/Makefile.rej Removing contrib/pg_trgm/expected/pg_trgm_collation.out Removing contrib/pg_trgm/expected/pg_trgm_collation_1.out Removing contrib/pg_trgm/sql/pg_trgm_collation.sql Removing contrib/pg_trgm/trgm_op.c.rej Removing contrib/pg_trgm/trgm_regexp.c.rej === using 'git apply' to apply patch ./v4-0001-Use-correct-collation-for-lowercasing.patch === Applied patch to 'contrib/pg_trgm/Makefile' with conflicts. Falling back to direct application... Falling back to direct application... Applied patch to 'contrib/pg_trgm/meson.build' cleanly. Falling back to direct application... /work/patches/./v4-0001-Use-correct-collation-for-lowercasing.patch:145: new blank line at EOF. + Applied patch to 'contrib/pg_trgm/trgm.h' cleanly. Applied patch to 'contrib/pg_trgm/trgm_gin.c' cleanly. Applied patch to 'contrib/pg_trgm/trgm_gist.c' cleanly. Applied patch to 'contrib/pg_trgm/trgm_op.c' with conflicts. Applied patch to 'contrib/pg_trgm/trgm_regexp.c' with conflicts. U contrib/pg_trgm/Makefile U contrib/pg_trgm/trgm_op.c U contrib/pg_trgm/trgm_regexp.c warning: 1 line adds whitespace errors. diff --cc contrib/pg_trgm/Makefile index c1756993ec7,1450f2aaea7..00000000000 --- a/contrib/pg_trgm/Makefile +++ b/contrib/pg_trgm/Makefile @@@ -14,7 -14,7 +14,11 @@@ DATA = pg_trgm--1.5--1.6.sql pg_trgm--1 pg_trgm--1.0--1.1.sql PGFILEDESC = "pg_trgm - trigram matching" ++<<<<<<< ours +REGRESS = pg_trgm pg_utf8_trgm pg_word_trgm pg_strict_word_trgm ++======= + REGRESS = pg_trgm pg_word_trgm pg_strict_word_trgm pg_trgm_collation ++>>>>>>> theirs ifdef USE_PGXS PG_CONFIG = pg_config diff --cc contrib/pg_trgm/trgm_op.c index 5fba594b61f,d4c75caeff9..00000000000 --- a/contrib/pg_trgm/trgm_op.c +++ b/contrib/pg_trgm/trgm_op.c @@@ -442,46 -317,30 +442,51 @@@ done /* * Make array of trigrams without sorting and removing duplicate items. * - * trg: where to return the array of trigrams. + * dst: where to return the array of trigrams. * str: source string, of length slen bytes. - * bounds: where to return bounds of trigrams (if needed). - * - * Returns length of the generated array. + * bounds_p: where to return bounds of trigrams (if needed). */ ++<<<<<<< ours +static void +generate_trgm_only(growable_trgm_array *dst, char *str, int slen, TrgmBound **bounds_p) ++======= + static int + generate_trgm_only(trgm *trg, char *str, int slen, Oid collation, TrgmBound *bounds) ++>>>>>>> theirs { - trgm *tptr; + size_t buflen; char *buf; - int charlen, - bytelen; + int bytelen; char *bword, *eword; + TrgmBound *bounds = NULL; + int bounds_allocated = 0; - if (slen + LPADDING + RPADDING < 3 || slen == 0) - return 0; + init_trgm_array(dst, slen); - tptr = trg; + /* + * If requested, allocate an array for the bounds, with the same size as + * the trigram array. + */ + if (bounds_p) + { + bounds_allocated = dst->allocated; + bounds = *bounds_p = palloc0_array(TrgmBound, bounds_allocated); + } - /* Allocate a buffer for case-folded, blank-padded words */ - buf = (char *) palloc(slen * pg_database_encoding_max_length() + 4); + if (slen + LPADDING + RPADDING < 3 || slen == 0) + return; + /* + * Allocate a buffer for case-folded, blank-padded words. + * + * As an initial guess, allocate a buffer large enough to hold the + * original string with padding, which is always enough when compiled with + * !IGNORECASE. If the case-folding produces a string longer than the + * original, we'll grow the buffer. + */ + buflen = (size_t) slen + 4; + buf = (char *) palloc(buflen); if (LPADDING > 0) { *buf = ' '; @@@ -490,37 -349,19 +495,42 @@@ } eword = str; - while ((bword = find_word(eword, slen - (eword - str), &eword, &charlen)) != NULL) + while ((bword = find_word(eword, slen - (eword - str), &eword)) != NULL) { + int oldlen; + + /* Convert word to lower case before extracting trigrams from it */ #ifdef IGNORECASE ++<<<<<<< ours + { + char *lowered; + + lowered = str_tolower(bword, eword - bword, DEFAULT_COLLATION_OID); + bytelen = strlen(lowered); + + /* grow the buffer if necessary */ + if (bytelen > buflen - 4) + { + pfree(buf); + buflen = (size_t) bytelen + 4; + buf = (char *) palloc(buflen); + if (LPADDING > 0) + { + *buf = ' '; + if (LPADDING > 1) + *(buf + 1) = ' '; + } + } + memcpy(buf + LPADDING, lowered, bytelen); + pfree(lowered); + } ++======= + bword = str_tolower(bword, eword - bword, collation); + bytelen = strlen(bword); ++>>>>>>> theirs #else bytelen = eword - bword; -#endif - memcpy(buf + LPADDING, bword, bytelen); - -#ifdef IGNORECASE - pfree(bword); #endif buf[LPADDING + bytelen] = ' '; @@@ -553,17 -405,22 +563,26 @@@ * Returns the sorted array of unique trigrams. */ TRGM * - generate_trgm(char *str, int slen) + generate_trgm(char *str, int slen, Oid collation) { TRGM *trg; + growable_trgm_array arr; int len; - protect_out_of_mem(slen); - - trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) * 3); + generate_trgm_only(&arr, str, slen, NULL); + len = arr.length; + trg = arr.datum; trg->flag = ARRKEY; ++<<<<<<< ours ++======= + len = generate_trgm_only(GETARR(trg), str, slen, collation, NULL); + SET_VARSIZE(trg, CALCGTSIZE(ARRKEY, len)); + + if (len == 0) + return trg; + ++>>>>>>> theirs /* * Make trigrams unique. */ @@@ -828,16 -685,22 +847,21 @@@ calc_word_similarity(char *str1, int sl ulen1; int *trg2indexes; float4 result; - TrgmBound *bounds; - - protect_out_of_mem(slen1 + slen2); + TrgmBound *bounds = NULL; /* Make positional trigrams */ - trg1 = (trgm *) palloc(sizeof(trgm) * (slen1 / 2 + 1) * 3); - trg2 = (trgm *) palloc(sizeof(trgm) * (slen2 / 2 + 1) * 3); - if (flags & WORD_SIMILARITY_STRICT) - bounds = (TrgmBound *) palloc0(sizeof(TrgmBound) * (slen2 / 2 + 1) * 3); - else - bounds = NULL; ++<<<<<<< ours + generate_trgm_only(&trg1, str1, slen1, NULL); + len1 = trg1.length; + generate_trgm_only(&trg2, str2, slen2, (flags & WORD_SIMILARITY_STRICT) ? &bounds : NULL); + len2 = trg2.length; ++======= + len1 = generate_trgm_only(trg1, str1, slen1, collation, NULL); + len2 = generate_trgm_only(trg2, str2, slen2, collation, bounds); ++>>>>>>> theirs - ptrg = make_positional_trgm(trg1, len1, trg2, len2); + ptrg = make_positional_trgm(GETARR(trg1.datum), len1, GETARR(trg2.datum), len2); len = len1 + len2; qsort(ptrg, len, sizeof(pos_trgm), comp_ptrgm); @@@ -1043,12 -915,14 +1067,12 @@@ get_wildcard_part(const char *str, int * " a", "bcd" would be extracted. */ TRGM * - generate_wildcard_trgm(const char *str, int slen) + generate_wildcard_trgm(const char *str, int slen, Oid collation) { TRGM *trg; - char *buf, - *buf2; - trgm *tptr; + growable_trgm_array arr; + char *buf; int len, - charlen, bytelen; const char *eword; @@@ -1070,15 -945,13 +1094,20 @@@ */ eword = str; while ((eword = get_wildcard_part(eword, slen - (eword - str), - buf, &bytelen, &charlen)) != NULL) + buf, &bytelen)) != NULL) { + char *word; + #ifdef IGNORECASE ++<<<<<<< ours + word = str_tolower(buf, bytelen, DEFAULT_COLLATION_OID); + bytelen = strlen(word); ++======= + buf2 = str_tolower(buf, bytelen, collation); + bytelen = strlen(buf2); ++>>>>>>> theirs #else - buf2 = buf; + word = buf; #endif /* diff --cc contrib/pg_trgm/trgm_regexp.c index efee4cf5fb4,cdd04fa01ad..00000000000 --- a/contrib/pg_trgm/trgm_regexp.c +++ b/contrib/pg_trgm/trgm_regexp.c @@@ -479,11 -479,11 +479,16 @@@ typedef struc /* prototypes for private functions */ static TRGM *createTrgmNFAInternal(regex_t *regex, TrgmPackedGraph **graph, - MemoryContext rcontext); + MemoryContext rcontext, Oid collation); static void RE_compile(regex_t *regex, text *text_re, int cflags, Oid collation); ++<<<<<<< ours +static void getColorInfo(regex_t *regex, TrgmNFA *trgmNFA); +static int convertPgWchar(pg_wchar c, trgm_mb_char *result); ++======= + static void getColorInfo(regex_t *regex, TrgmNFA *trgmNFA, Oid collation); + static bool convertPgWchar(pg_wchar c, trgm_mb_char *result, Oid collation); ++>>>>>>> theirs static void transformGraph(TrgmNFA *trgmNFA); static void processState(TrgmNFA *trgmNFA, TrgmState *state); static void addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key); @@@ -807,11 -807,10 +812,15 @@@ getColorInfo(regex_t *regex, TrgmNFA *t for (j = 0; j < charsCount; j++) { trgm_mb_char c; + int clen = convertPgWchar(chars[j], &c); ++<<<<<<< ours + if (!clen) ++======= + if (!convertPgWchar(chars[j], &c, collation)) ++>>>>>>> theirs continue; /* ok to ignore it altogether */ - if (ISWORDCHR(c.bytes)) + if (ISWORDCHR(c.bytes, clen)) colorInfo->wordChars[colorInfo->wordCharsCount++] = c; else colorInfo->containsNonWord = true; @@@ -823,11 -822,10 +832,16 @@@ /* * Convert pg_wchar to multibyte format. - * Returns false if the character should be ignored completely. + * Returns 0 if the character should be ignored completely, else returns its + * byte length. */ ++<<<<<<< ours +static int +convertPgWchar(pg_wchar c, trgm_mb_char *result) ++======= + static bool + convertPgWchar(pg_wchar c, trgm_mb_char *result, Oid collation) ++>>>>>>> theirs { /* "s" has enough space for a multibyte character and a trailing NUL */ char s[MAX_MULTIBYTE_CHAR_LEN + 1]; @@@ -860,7 -857,7 +874,11 @@@ */ #ifdef IGNORECASE { ++<<<<<<< ours + char *lowerCased = str_tolower(s, clen, DEFAULT_COLLATION_OID); ++======= + char *lowerCased = str_tolower(s, strlen(s), collation); ++>>>>>>> theirs if (strcmp(lowerCased, s) != 0) {