@@ -75,6 +75,15 @@ def _reference_unicode_escape(args):
75
75
return _codecs .unicode_escape_encode (args [0 ])[0 ]
76
76
77
77
78
+ def _reference_fromformat (args ):
79
+ fmt = args [0 ]
80
+ fmt_args = args [1 :]
81
+ # replace specifiers
82
+ for s in ["%ld" , "%li" , "%lu" , "%lld" , "%lli" , "%llu" ]:
83
+ fmt = fmt .replace (s , "%d" )
84
+ return fmt % fmt_args
85
+
86
+
78
87
class CustomString (str ):
79
88
pass
80
89
@@ -128,7 +137,7 @@ def compile_module(self, name):
128
137
)
129
138
130
139
test_PyUnicode_FromFormat0 = CPyExtFunction (
131
- lambda args : args [ 0 ] % tuple ( args [ 1 :]) ,
140
+ _reference_fromformat ,
132
141
lambda : (
133
142
("hello, world!" ,),
134
143
),
@@ -143,19 +152,17 @@ def compile_module(self, name):
143
152
cmpfunc = unhandled_error_compare
144
153
)
145
154
146
- test_PyUnicode_FromFormat3 = CPyExtFunction (
147
- lambda args : args [ 0 ] % tuple ( args [ 1 :]) ,
155
+ test_PyUnicode_FromFormat4 = CPyExtFunction (
156
+ _reference_fromformat ,
148
157
lambda : (
149
- ("word0: %s; word1: %s; int: %d" , "hello" , "world" , 1234 ),
158
+ ("word0: %s; word1: %s; int: %d; long long: %lld" , "hello" , "world" , 1234 , 1234 ),
159
+ ("word0: %s; word1: %s; int: %d; long long: %lld" , "hello" , "world" , 1234 , (1 << 44 )+ 123 ),
150
160
),
151
- code = """PyObject* wrap_PyUnicode_FromFormat3(char* fmt, char* arg0, char* arg1, int n) {
152
- return PyUnicode_FromFormat(fmt, arg0, arg1, n);
153
- }
154
- """ ,
161
+ code = "typedef long long longlong_t;" ,
155
162
resultspec = "O" ,
156
- argspec = 'sssi ' ,
157
- arguments = ["char* fmt" , "char* arg0" , "char* arg1" , "int n" ],
158
- callfunction = "wrap_PyUnicode_FromFormat3 " ,
163
+ argspec = 'sssiL ' ,
164
+ arguments = ["char* fmt" , "char* arg0" , "char* arg1" , "int n" , "longlong_t l" ],
165
+ callfunction = "PyUnicode_FromFormat " ,
159
166
cmpfunc = unhandled_error_compare
160
167
)
161
168
0 commit comments