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

Commita97e091

Browse files
committed
Merge branch 'dhylands-int-bytes'
2 parentsf3c3010 +a75b02e commita97e091

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

‎py/obj.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
7474
#defineMP_OBJ_IS_TYPE(o,t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
7575
#defineMP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
7676
#defineMP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
77+
#defineMP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_QSTR(o) || (MP_OBJ_IS_OBJ(o) && ((mp_obj_base_t*)(o))->type->binary_op == mp_obj_str_binary_op))
7778
#defineMP_OBJ_IS_FUN(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type->binary_op == mp_obj_fun_binary_op))
7879

7980
#defineMP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)

‎py/objint.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include"smallint.h"
3939
#include"mpz.h"
4040
#include"objint.h"
41+
#include"objstr.h"
4142
#include"runtime0.h"
4243
#include"runtime.h"
4344

@@ -57,7 +58,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
5758
if (MP_OBJ_IS_INT(args[0])) {
5859
// already an int (small or long), just return it
5960
returnargs[0];
60-
}elseif (MP_OBJ_IS_STR(args[0])) {
61+
}elseif (MP_OBJ_IS_STR_OR_BYTES(args[0])) {
6162
// a string, parse it
6263
uintl;
6364
constchar*s=mp_obj_str_get_data(args[0],&l);

‎py/objstr.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
4949
STATICNORETURNvoidbad_implicit_conversion(mp_obj_tself_in);
5050
STATICNORETURNvoidarg_type_mixup();
5151

52-
STATICboolis_str_or_bytes(mp_obj_to) {
53-
returnMP_OBJ_IS_STR(o)||MP_OBJ_IS_TYPE(o,&mp_type_bytes);
54-
}
55-
5652
/******************************************************************************/
5753
/* str */
5854

@@ -251,6 +247,9 @@ STATIC const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byt
251247
returnNULL;
252248
}
253249

250+
// Note: this function is used to check if an object is a str or bytes, which
251+
// works because both those types use it as their binary_op method. Revisit
252+
// MP_OBJ_IS_STR_OR_BYTES if this fact changes.
254253
mp_obj_tmp_obj_str_binary_op(intop,mp_obj_tlhs_in,mp_obj_trhs_in) {
255254
GET_STR_DATA_LEN(lhs_in,lhs_data,lhs_len);
256255
mp_obj_type_t*lhs_type=mp_obj_get_type(lhs_in);
@@ -388,7 +387,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
388387
}
389388

390389
STATICmp_obj_tstr_join(mp_obj_tself_in,mp_obj_targ) {
391-
assert(is_str_or_bytes(self_in));
390+
assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
392391
constmp_obj_type_t*self_type=mp_obj_get_type(self_in);
393392

394393
// get separation string
@@ -660,7 +659,7 @@ enum { LSTRIP, RSTRIP, STRIP };
660659

661660
STATICmp_obj_tstr_uni_strip(inttype,uintn_args,constmp_obj_t*args) {
662661
assert(1 <=n_args&&n_args <=2);
663-
assert(is_str_or_bytes(args[0]));
662+
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
664663
constmp_obj_type_t*self_type=mp_obj_get_type(args[0]);
665664

666665
constbyte*chars_to_del;
@@ -1477,7 +1476,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
14771476
}
14781477

14791478
STATICmp_obj_tstr_partitioner(mp_obj_tself_in,mp_obj_targ,mp_int_tdirection) {
1480-
if (!is_str_or_bytes(self_in)) {
1479+
if (!MP_OBJ_IS_STR_OR_BYTES(self_in)) {
14811480
assert(0);
14821481
}
14831482
mp_obj_type_t*self_type=mp_obj_get_type(self_in);
@@ -1877,7 +1876,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) {
18771876
}
18781877

18791878
constchar*mp_obj_str_get_data(mp_obj_tself_in,uint*len) {
1880-
if (is_str_or_bytes(self_in)) {
1879+
if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {
18811880
GET_STR_DATA_LEN(self_in,s,l);
18821881
*len=l;
18831882
return (constchar*)s;

‎tests/basics/int1.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
print(int('\t 0o12',8))
4848
print(int('0o12\t ',8))
4949
print(int(b"12",10))
50+
print(int(b"12"))
5051

5152

5253
deftest(value,base):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp