Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65a588b

Browse files
committed
Try to fix portability issue in enum renumbering (again).
The hack embodied in commit4ba61a4 no longer works after today's changeto allow DatumGetFloat4/Float4GetDatum to be inlined (commit14cca1b).Probably what's happening is that the faulty compilers are deciding thatthe now-inlined assignment is a no-op and so they're not required toround to float4 width.We had a bunch of similar issues earlier this year in the degree-basedtrig functions, and eventually settled on using volatile intermediatevariables as the least ugly method of forcing recalcitrant compilersto do what the C standard says (cf commit82311bc). Let's see ifthat method works here.Discussion: <4640.1472664476@sss.pgh.pa.us>
1 parent6792263 commit65a588b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

‎src/backend/catalog/pg_enum.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,28 +315,30 @@ AddEnumLabel(Oid enumTypeOid,
315315
newelemorder=nbr_en->enumsortorder+1;
316316
else
317317
{
318-
other_nbr_en= (Form_pg_enum)GETSTRUCT(existing[other_nbr_index]);
319-
newelemorder= (nbr_en->enumsortorder+
320-
other_nbr_en->enumsortorder) /2;
321-
322318
/*
323-
*On some machines, newelemorder may be in a register that's
324-
*wider than float4. We need to force it to be rounded to float4
325-
*precision before making the following comparisons, or we'll get
326-
*wrong results. (Such behavior violates the C standard, but
327-
*fixing the compilers is out of our reach.)
319+
*The midpoint value computed here has to be rounded to float4
320+
*precision, else our equality comparisons against the adjacent
321+
*values are meaningless. The most portable way of forcing that
322+
*to happen with non-C-standard-compliant compilers is to store
323+
*it into a volatile variable.
328324
*/
329-
newelemorder=DatumGetFloat4(Float4GetDatum(newelemorder));
325+
volatilefloat4midpoint;
330326

331-
if (newelemorder==nbr_en->enumsortorder||
332-
newelemorder==other_nbr_en->enumsortorder)
327+
other_nbr_en= (Form_pg_enum)GETSTRUCT(existing[other_nbr_index]);
328+
midpoint= (nbr_en->enumsortorder+
329+
other_nbr_en->enumsortorder) /2;
330+
331+
if (midpoint==nbr_en->enumsortorder||
332+
midpoint==other_nbr_en->enumsortorder)
333333
{
334334
RenumberEnumType(pg_enum,existing,nelems);
335335
/* Clean up and start over */
336336
pfree(existing);
337337
ReleaseCatCacheList(list);
338338
gotorestart;
339339
}
340+
341+
newelemorder=midpoint;
340342
}
341343
}
342344

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp