py/parsenum: Use size_t to count bytes, and int for type of base arg.
size_t is the proper type to count number of bytes in a string. The base argument does not need to be a full mp_uint_t, int is enough.
This commit is contained in:
parent
99fc0d120a
commit
dddb98db8b
|
@ -28,6 +28,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/parsenumbase.h"
|
||||
#include "py/parsenum.h"
|
||||
#include "py/smallint.h"
|
||||
|
||||
|
@ -45,7 +46,7 @@ STATIC NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) {
|
|||
nlr_raise(exc);
|
||||
}
|
||||
|
||||
mp_obj_t mp_parse_num_integer(const char *restrict str_, mp_uint_t len, mp_uint_t base, mp_lexer_t *lex) {
|
||||
mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, mp_lexer_t *lex) {
|
||||
const byte *restrict str = (const byte *)str_;
|
||||
const byte *restrict top = str + len;
|
||||
bool neg = false;
|
||||
|
@ -169,7 +170,7 @@ typedef enum {
|
|||
PARSE_DEC_IN_EXP,
|
||||
} parse_dec_in_t;
|
||||
|
||||
mp_obj_t mp_parse_num_decimal(const char *str, mp_uint_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex) {
|
||||
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
const char *top = str + len;
|
||||
mp_float_t dec_val = 0;
|
||||
|
|
|
@ -30,10 +30,8 @@
|
|||
#include "py/lexer.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base);
|
||||
|
||||
// these functions raise a SyntaxError if lex!=NULL, else a ValueError
|
||||
mp_obj_t mp_parse_num_integer(const char *restrict str, mp_uint_t len, mp_uint_t base, mp_lexer_t *lex);
|
||||
mp_obj_t mp_parse_num_decimal(const char *str, mp_uint_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex);
|
||||
mp_obj_t mp_parse_num_integer(const char *restrict str, size_t len, int base, mp_lexer_t *lex);
|
||||
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
// find real radix base, and strip preceding '0x', '0o' and '0b'
|
||||
// puts base in *base, and returns number of bytes to skip the prefix
|
||||
mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base) {
|
||||
size_t mp_parse_num_base(const char *str, size_t len, int *base) {
|
||||
const byte *p = (const byte*)str;
|
||||
if (len <= 1) {
|
||||
goto no_prefix;
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef __MICROPY_INCLUDED_PY_PARSENUM_H__
|
||||
#define __MICROPY_INCLUDED_PY_PARSENUM_H__
|
||||
#ifndef __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
|
||||
#define __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base);
|
||||
size_t mp_parse_num_base(const char *str, size_t len, int *base);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__
|
||||
#endif // __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
|
||||
|
|
Loading…
Reference in New Issue