Skip to content

Commit 2bcc37e

Browse files
committed
Re-run sync script with latest mypy master
1 parent 3f0c469 commit 2bcc37e

File tree

16 files changed

+1304
-47
lines changed

16 files changed

+1304
-47
lines changed

lib-rt/CPy.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ PyObject *CPy_Encode(PyObject *obj, PyObject *encoding, PyObject *errors);
770770
Py_ssize_t CPyStr_Count(PyObject *unicode, PyObject *substring, CPyTagged start);
771771
Py_ssize_t CPyStr_CountFull(PyObject *unicode, PyObject *substring, CPyTagged start, CPyTagged end);
772772
CPyTagged CPyStr_Ord(PyObject *obj);
773+
PyObject *CPyStr_Multiply(PyObject *str, CPyTagged count);
773774

774775

775776
// Bytes operations
@@ -781,6 +782,8 @@ CPyTagged CPyBytes_GetItem(PyObject *o, CPyTagged index);
781782
PyObject *CPyBytes_Concat(PyObject *a, PyObject *b);
782783
PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter);
783784
CPyTagged CPyBytes_Ord(PyObject *obj);
785+
PyObject *CPyBytes_Multiply(PyObject *bytes, CPyTagged count);
786+
PyObject *CPyBytes_Translate(PyObject *bytes, PyObject *table);
784787

785788

786789
int CPyBytes_Compare(PyObject *left, PyObject *right);
@@ -958,6 +961,26 @@ static inline int CPyObject_GenericSetAttr(PyObject *self, PyObject *name, PyObj
958961
return _PyObject_GenericSetAttrWithDict(self, name, value, NULL);
959962
}
960963

964+
PyObject *CPy_SetupObject(PyObject *type);
965+
966+
typedef struct {
967+
PyCMethodObject func;
968+
969+
PyObject *func_name;
970+
PyObject *func_code;
971+
} CPyFunction;
972+
973+
PyObject* CPyFunction_New(PyObject *module, const char *filename, const char *funcname,
974+
PyCFunction func, int func_flags, const char *func_doc,
975+
int first_line, int code_flags);
976+
PyObject* CPyFunction_get_name(PyObject *op, void *context);
977+
int CPyFunction_set_name(PyObject *op, PyObject *value, void *context);
978+
PyObject* CPyFunction_get_code(PyObject *op, void *context);
979+
PyObject* CPyFunction_get_defaults(PyObject *op, void *context);
980+
PyObject* CPyFunction_get_kwdefaults(PyObject *op, void *context);
981+
PyObject* CPyFunction_get_annotations(PyObject *op, void *context);
982+
int CPyFunction_set_annotations(PyObject *op, PyObject *value, void *context);
983+
961984
#if CPY_3_11_FEATURES
962985
PyObject *CPy_GetName(PyObject *obj);
963986
#endif

lib-rt/base64/arch/avx/codec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "../ssse3/dec_loop.c"
2525

2626
#if BASE64_AVX_USE_ASM
27-
# include "enc_loop_asm.c"
27+
# include "./enc_loop_asm.c"
2828
#else
2929
# include "../ssse3/enc_translate.c"
3030
# include "../ssse3/enc_reshuffle.c"

lib-rt/base64/arch/avx2/codec.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
# endif
2121
#endif
2222

23-
#include "dec_reshuffle.c"
24-
#include "dec_loop.c"
23+
#include "./dec_reshuffle.c"
24+
#include "./dec_loop.c"
2525

2626
#if BASE64_AVX2_USE_ASM
27-
# include "enc_loop_asm.c"
27+
# include "./enc_loop_asm.c"
2828
#else
29-
# include "enc_translate.c"
30-
# include "enc_reshuffle.c"
31-
# include "enc_loop.c"
29+
# include "./enc_translate.c"
30+
# include "./enc_reshuffle.c"
31+
# include "./enc_loop.c"
3232
#endif
3333

3434
#endif // HAVE_AVX2

lib-rt/base64/config.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
#ifndef BASE64_CONFIG_H
22
#define BASE64_CONFIG_H
33

4-
#define BASE64_WITH_SSSE3 0
5-
#define HAVE_SSSE3 BASE64_WITH_SSSE3
6-
7-
#define BASE64_WITH_SSE41 0
8-
#define HAVE_SSE41 BASE64_WITH_SSE41
9-
10-
#if defined(__x86_64__) || defined(_M_X64)
11-
#define BASE64_WITH_SSE42 1
12-
#else
13-
#define BASE64_WITH_SSE42 0
4+
#if !defined(__APPLE__) && ((defined(__x86_64__) && defined(__LP64__)) || defined(_M_X64))
5+
#define HAVE_SSSE3 1
6+
#define HAVE_SSE41 1
7+
#define HAVE_SSE42 1
8+
#define HAVE_AVX 1
9+
#define HAVE_AVX2 1
10+
#define HAVE_AVX512 0
1411
#endif
1512

16-
#define HAVE_SSE42 BASE64_WITH_SSE42
17-
18-
#define BASE64_WITH_AVX 0
19-
#define HAVE_AVX BASE64_WITH_AVX
20-
21-
#define BASE64_WITH_AVX2 0
22-
#define HAVE_AVX2 BASE64_WITH_AVX2
23-
24-
#define BASE64_WITH_AVX512 0
25-
#define HAVE_AVX512 BASE64_WITH_AVX512
26-
2713
#define BASE64_WITH_NEON32 0
2814
#define HAVE_NEON32 BASE64_WITH_NEON32
2915

lib-rt/bytes_ops.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,61 @@ CPyTagged CPyBytes_Ord(PyObject *obj) {
162162
PyErr_SetString(PyExc_TypeError, "ord() expects a character");
163163
return CPY_INT_TAG;
164164
}
165+
166+
PyObject *CPyBytes_Multiply(PyObject *bytes, CPyTagged count) {
167+
Py_ssize_t temp_count = CPyTagged_AsSsize_t(count);
168+
if (temp_count == -1 && PyErr_Occurred()) {
169+
PyErr_SetString(PyExc_OverflowError, CPYTHON_LARGE_INT_ERRMSG);
170+
return NULL;
171+
}
172+
return PySequence_Repeat(bytes, temp_count);
173+
}
174+
175+
PyObject *CPyBytes_Translate(PyObject *bytes, PyObject *table) {
176+
// Fast path: exact bytes object with exact bytes table
177+
if (PyBytes_CheckExact(bytes) && PyBytes_CheckExact(table)) {
178+
Py_ssize_t table_len = PyBytes_GET_SIZE(table);
179+
if (table_len != 256) {
180+
PyErr_SetString(PyExc_ValueError,
181+
"translation table must be 256 characters long");
182+
return NULL;
183+
}
184+
185+
Py_ssize_t len = PyBytes_GET_SIZE(bytes);
186+
const char *input = PyBytes_AS_STRING(bytes);
187+
const char *trans_table = PyBytes_AS_STRING(table);
188+
189+
PyObject *result = PyBytes_FromStringAndSize(NULL, len);
190+
if (result == NULL) {
191+
return NULL;
192+
}
193+
194+
char *output = PyBytes_AS_STRING(result);
195+
bool changed = false;
196+
197+
// Without a loop unrolling hint performance can be worse than CPython
198+
CPY_UNROLL_LOOP(4)
199+
for (Py_ssize_t i = len; --i >= 0;) {
200+
char c = *input++;
201+
if ((*output++ = trans_table[(unsigned char)c]) != c)
202+
changed = true;
203+
}
204+
205+
// If nothing changed, discard result and return the original object
206+
if (!changed) {
207+
Py_DECREF(result);
208+
Py_INCREF(bytes);
209+
return bytes;
210+
}
211+
212+
return result;
213+
}
214+
215+
// Fallback to Python method call for non-exact types or non-standard tables
216+
_Py_IDENTIFIER(translate);
217+
PyObject *name = _PyUnicode_FromId(&PyId_translate);
218+
if (name == NULL) {
219+
return NULL;
220+
}
221+
return PyObject_CallMethodOneArg(bytes, name, table);
222+
}

0 commit comments

Comments
 (0)