Skip to content

Commit 48303da

Browse files
committed
eyalroz-printf: Add new wrap v6.2.0
Signed-off-by: Alexander Voronov <[email protected]>
1 parent b022818 commit 48303da

File tree

6 files changed

+361
-0
lines changed

6 files changed

+361
-0
lines changed

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,14 @@
839839
"2.2.5-1"
840840
]
841841
},
842+
"eyalroz-printf": {
843+
"dependency_names": [
844+
"eyalroz-printf"
845+
],
846+
"versions": [
847+
"6.2.0-1"
848+
]
849+
},
842850
"facil": {
843851
"dependency_names": [
844852
"facil"

subprojects/eyalroz-printf.wrap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[wrap-file]
2+
directory = eyalroz-printf-6.2.0
3+
source_url = https://github.com/eyalroz/printf/archive/refs/tags/v6.2.0.zip
4+
source_filename = eyalroz-printf-6.2.0.zip
5+
source_hash = 42f40b07cf1012d7a69e2c34d44b118dc3a70530f3e2b591962cfe7a7c133fc7
6+
patch_directory = eyalroz-printf
7+
lead_directory_missing = true
8+
9+
[provide]
10+
dependency_names = eyalroz-printf
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
project(
2+
'eyalroz-printf',
3+
'c',
4+
'cpp',
5+
license: 'MIT',
6+
meson_version: '>=1.0.0',
7+
version: '6.2.0',
8+
default_options: [
9+
'b_staticpic=false',
10+
'c_std=c99',
11+
'default_library=static', # For shared support we need to somehow provide putchar_ implementation
12+
],
13+
)
14+
15+
subdir('printf-6.2.0')
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
option(
2+
'tests',
3+
description: 'Build test programs for the library',
4+
type: 'boolean',
5+
value: false,
6+
)
7+
option(
8+
'test_with_non_standard_format_strings',
9+
description: 'Include tests using non-standard-compliant format strings',
10+
type: 'boolean',
11+
)
12+
13+
option(
14+
'support_decimal_specifiers',
15+
description: 'Support decimal notation floating-point conversion specifiers (%f,%F)',
16+
type: 'boolean',
17+
)
18+
option(
19+
'support_exponential_specifiers',
20+
description: 'Support exponential floating point format conversion specifiers (%e,%E,%g,%G)',
21+
type: 'boolean',
22+
)
23+
option(
24+
'support_writeback_specifier',
25+
description: 'Support the length write-back specifier (%n)',
26+
type: 'boolean',
27+
)
28+
option(
29+
'support_msvc_style_integer_specifiers',
30+
description: 'Support the I + bit size integer specifiers (%I8, %I16, %I32, %I64) as in Microsoft Visual C++',
31+
type: 'boolean',
32+
)
33+
option(
34+
'support_long_long',
35+
description: 'Support long long integral types (allows for the ll length modifier and affects %p)',
36+
type: 'boolean',
37+
)
38+
option(
39+
'use_double_internally',
40+
description: 'Use the C `double` type - typically 64-bit in size - for internal floating-point arithmetic',
41+
type: 'boolean',
42+
)
43+
option(
44+
'check_for_nul_in_format_specifier',
45+
description: 'Be defensive in the undefined-behavior case of a format specifier not ending before the string ends',
46+
type: 'boolean',
47+
)
48+
49+
option(
50+
'integer_buffer_size',
51+
description: 'Integer to string conversion buffer size',
52+
type: 'integer',
53+
min: 0,
54+
value: 32,
55+
)
56+
option(
57+
'decimal_buffer_size',
58+
description: 'Floating-point to decimal conversion buffer size',
59+
type: 'integer',
60+
min: 0,
61+
value: 32,
62+
)
63+
option(
64+
'default_float_precision',
65+
description: 'Default precision when printing floating-point values',
66+
type: 'integer',
67+
min: 0,
68+
value: 6,
69+
)
70+
option(
71+
'max_integral_digits_for_decimal',
72+
description: 'Maximum number of integral-part digits of a floating-point value for which printing with %f uses decimal (non-exponential) notation',
73+
type: 'integer',
74+
min: 0,
75+
value: 9,
76+
)
77+
option(
78+
'log10_taylor_terms',
79+
description: 'The number of terms in a Taylor series expansion of log_10(x) to use for approximation',
80+
type: 'integer',
81+
min: 0,
82+
value: 4,
83+
)
84+
85+
option(
86+
'alias_standard_function_names',
87+
description: 'Alias the standard library function names (printf, sprintf etc.) to the library\'s functions - concretely, via a macro, or not at all',
88+
type: 'combo',
89+
choices: ['none', 'hard', 'soft'],
90+
value: 'none',
91+
)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
cc = meson.get_compiler('c')
2+
## Checks related to the 'j', 'z' and 't' size modifiers
3+
sizeof_long = cc.sizeof('long')
4+
sizeof_long_long = cc.sizeof('long long')
5+
acceptable_jzt_type_sizes = [sizeof_long, sizeof_long_long]
6+
types = ['intmax_t', 'size_t', 'ptrdiff_t']
7+
foreach type : types
8+
type_size = cc.sizeof(
9+
type,
10+
prefix: ['#include <stdint.h>'],
11+
)
12+
if type_size not in acceptable_jzt_type_sizes
13+
error(
14+
f'sizeof(@type@) is @type_size@, which is neither sizeof(long) (@sizeof_long@) nor sizeof(long long) (@sizeof_long_long@). Please contact the library maintainers with your platform details.',
15+
)
16+
endif
17+
endforeach
18+
19+
private_c_args = []
20+
public_c_args = []
21+
lib_config = {}
22+
if cc.get_argument_syntax() == 'gcc'
23+
private_c_args += ['-Wall', '-Wextra', '-pedantic', '-Wconversion']
24+
elif cc.get_argument_syntax() == 'msvc'
25+
private_c_args += '/W4'
26+
endif
27+
if get_option('alias_standard_function_names') != 'none'
28+
option_val_upper = get_option('alias_standard_function_names').to_upper()
29+
public_c_args += f'-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES_@option_val_upper@=1'
30+
if cc.get_argument_syntax() == 'gcc'
31+
public_c_args += '-fno-builtin-printf'
32+
endif
33+
34+
if get_option('alias_standard_function_names') == 'hard'
35+
lib_config += {
36+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
37+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 1,
38+
}
39+
else
40+
lib_config += {
41+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 1,
42+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
43+
}
44+
endif
45+
else
46+
lib_config += {
47+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
48+
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
49+
}
50+
endif
51+
private_c_args += '-DPRINTF_INCLUDE_CONFIG_H'
52+
53+
bool_option_names = [
54+
'support_decimal_specifiers',
55+
'support_exponential_specifiers',
56+
'support_msvc_style_integer_specifiers',
57+
'support_writeback_specifier',
58+
'support_long_long',
59+
'use_double_internally',
60+
'check_for_nul_in_format_specifier',
61+
]
62+
foreach option_name : bool_option_names
63+
lib_config += {
64+
'PRINTF_' + option_name.to_upper(): get_option(option_name).to_int(),
65+
}
66+
endforeach
67+
int_option_names = ['integer_buffer_size', 'decimal_buffer_size']
68+
foreach option_name : int_option_names
69+
lib_config += {
70+
'PRINTF_' + option_name.to_upper(): get_option(option_name),
71+
}
72+
endforeach
73+
int_option_names_wo_prefix = [
74+
'default_float_precision',
75+
'max_integral_digits_for_decimal',
76+
'log10_taylor_terms',
77+
]
78+
foreach option_name : int_option_names_wo_prefix
79+
lib_config += {
80+
option_name.to_upper(): get_option(option_name),
81+
}
82+
endforeach
83+
84+
cfg_header_file = configure_file(
85+
input: 'printf_config.h.in',
86+
configuration: lib_config,
87+
format: 'cmake@',
88+
output: 'printf_config.h',
89+
)
90+
eyalroz_printf_lib = library(
91+
'eyalroz-printf',
92+
'src/printf/printf.c',
93+
cfg_header_file,
94+
include_directories: 'src',
95+
c_args: [private_c_args, public_c_args],
96+
)
97+
eyalroz_printf_dep = declare_dependency(
98+
include_directories: 'src',
99+
link_with: eyalroz_printf_lib,
100+
compile_args: [public_c_args],
101+
)
102+
meson.override_dependency('eyalroz-printf', eyalroz_printf_dep)
103+
104+
if get_option('tests')
105+
subdir('test')
106+
endif
107+
108+
# Prints the sizes of the different sections of the ELF file: text, dat, vss etc.
109+
size_prog = find_program('size')
110+
if size_prog.found()
111+
custom_target(
112+
'printf-sizes',
113+
command: [size_prog, '-A', '-t', eyalroz_printf_lib],
114+
capture: true,
115+
output: 'printf_sizes.txt',
116+
)
117+
endif
118+
119+
# Produces lists of the symbols, and C++demangled symbols, inside the library
120+
nm_prog = find_program('nm')
121+
if nm_prog.found()
122+
lib_path = eyalroz_printf_lib.full_path()
123+
sh_cmd = 'nm --numeric-sort --print-size ' + lib_path + ' > @OUTDIR@/printf_symbols.txt'
124+
filt_prog = find_program('c++filt')
125+
if filt_prog.found()
126+
sh_cmd += ' && nm --numeric-sort ' + lib_path + ' | c++filt > @OUTDIR@/printf_cpp_symbols.txt'
127+
endif
128+
custom_target(
129+
'printf-symbols',
130+
command: ['sh', '-c', sh_cmd],
131+
depends: eyalroz_printf_lib,
132+
output: ['printf_symbols.txt', 'printf_cpp_symbols.txt'],
133+
)
134+
endif
135+
136+
# Dissassembles the compiled library into an .list file
137+
objdump_prog = find_program('objdump')
138+
if objdump_prog.found()
139+
custom_target(
140+
'printf-lst',
141+
command: [
142+
objdump_prog,
143+
'--disassemble',
144+
'--line-numbers',
145+
'-S',
146+
eyalroz_printf_lib,
147+
],
148+
capture: true,
149+
output: 'printf.list',
150+
)
151+
endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
common_msvc_args = ['/W4']
2+
common_gcc_args = [
3+
'-g',
4+
'-Wall',
5+
'-Wextra',
6+
'-pedantic',
7+
'-Wundef',
8+
'-Wsign-conversion',
9+
'-Wuninitialized',
10+
'-Wshadow',
11+
'-Wunreachable-code',
12+
'-Wswitch-default',
13+
'-Wswitch',
14+
'-Wcast-align',
15+
'-Wmissing-include-dirs',
16+
'-Winit-self',
17+
'-Wdouble-promotion',
18+
'-gdwarf-2',
19+
'-fno-exceptions',
20+
'-ffunction-sections',
21+
'-fdata-sections',
22+
'-fverbose-asm',
23+
'-Wunused-parameter',
24+
]
25+
tests_c_args = []
26+
if cc.get_argument_syntax() == 'msvc'
27+
tests_c_args += [common_msvc_args, '/std:c11']
28+
elif cc.get_argument_syntax() == 'gcc'
29+
tests_c_args += [common_gcc_args, '-std=c11']
30+
tests_c_args += '-Wstrict-prototypes'
31+
if cc.get_id() == 'gcc'
32+
tests_c_args += '-ffat-lto-objects'
33+
endif
34+
endif
35+
tests_cpp_args = []
36+
cxx = meson.get_compiler('cpp')
37+
if cxx.get_argument_syntax() == 'msvc'
38+
tests_cpp_args += [common_msvc_args, '/std:c++11']
39+
elif cxx.get_argument_syntax() == 'gcc'
40+
tests_cpp_args += [common_gcc_args, '-std=c++11']
41+
if cxx.get_id() == 'gcc'
42+
tests_cpp_args += '-ffat-lto-objects'
43+
endif
44+
endif
45+
46+
aliasing_opt = []
47+
if cc.get_argument_syntax() == 'gcc'
48+
aliasing_opt += '-fno-builtin-printf'
49+
endif
50+
aliasing_exe = executable(
51+
'aliasing',
52+
'aliasing.c',
53+
cfg_header_file,
54+
c_args: [aliasing_opt, tests_c_args],
55+
dependencies: [eyalroz_printf_dep],
56+
include_directories: '..',
57+
)
58+
test('printf.aliasing', aliasing_exe)
59+
60+
61+
non_std_fmt_define = []
62+
if get_option('test_with_non_standard_format_strings')
63+
non_std_fmt_define += '-DTEST_WITH_NON_STANDARD_FORMAT_STRINGS'
64+
endif
65+
66+
autotest_exe = executable(
67+
'autotest',
68+
'autotest.cpp',
69+
cfg_header_file,
70+
cpp_args: [non_std_fmt_define, tests_cpp_args],
71+
implicit_include_directories: false,
72+
include_directories: '..',
73+
dependencies: eyalroz_printf_dep,
74+
)
75+
# Not running autotest by default - it's randomized after all.
76+
77+
if get_option('alias_standard_function_names') != 'soft'
78+
test_suite_exe = executable(
79+
'test_suite',
80+
'test_suite.cpp',
81+
cfg_header_file,
82+
cpp_args: ['-DPRINTF_INCLUDE_CONFIG_H', non_std_fmt_define, tests_cpp_args],
83+
include_directories: ['..', '../src'],
84+
)
85+
test('printf.test_suite', test_suite_exe)
86+
endif

0 commit comments

Comments
 (0)