mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Another round of portability hacking on ECPG regression tests.
Removing the separate Windows expected-files in commit f1885386f
turns out to have been too optimistic: on most (but not all!) of our
Windows buildfarm members, the tests still print floats with three
exponent digits, because they're invoking the native printf()
not snprintf.c.
But rather than put back the extra expected-files, let's hack
the three tests in question so that they adjust float formatting
the same way snprintf.c does.
Discussion: https://postgr.es/m/18890.1539374107@sss.pgh.pa.us
			
			
This commit is contained in:
		
							
								
								
									
										29
									
								
								src/interfaces/ecpg/test/printf_hack.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/interfaces/ecpg/test/printf_hack.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
/*
 | 
			
		||||
 * print_double(x) has the same effect as printf("%g", x), but is intended
 | 
			
		||||
 * to produce the same formatting across all platforms.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
print_double(double x)
 | 
			
		||||
{
 | 
			
		||||
#ifdef WIN32
 | 
			
		||||
	/* Change Windows' 3-digit exponents to look like everyone else's */
 | 
			
		||||
	char		convert[128];
 | 
			
		||||
	int			vallen;
 | 
			
		||||
 | 
			
		||||
	sprintf(convert, "%g", x);
 | 
			
		||||
	vallen = strlen(convert);
 | 
			
		||||
 | 
			
		||||
	if (vallen >= 6 &&
 | 
			
		||||
		convert[vallen - 5] == 'e' &&
 | 
			
		||||
		convert[vallen - 3] == '0')
 | 
			
		||||
	{
 | 
			
		||||
		convert[vallen - 3] = convert[vallen - 2];
 | 
			
		||||
		convert[vallen - 2] = convert[vallen - 1];
 | 
			
		||||
		convert[vallen - 1] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	printf("%s", convert);
 | 
			
		||||
#else
 | 
			
		||||
	printf("%g", x);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user