You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficserver.apache.org by zwoop <gi...@git.apache.org> on 2017/02/03 20:40:04 UTC

[GitHub] trafficserver issue #1418: Consistently use ink_atoi() (or one of the equiva...

GitHub user zwoop opened an issue:

    https://github.com/apache/trafficserver/issues/1418

    Consistently use ink_atoi() (or one of the equivalent functions we provide)

    (This is moved from https://issues.apache.org/jira/browse/TS-1773).
    
    Right now, we have a hotchpotch of various "string to integer" conversions happening in the core. We have a main one, ink_atoi() / ink_atoui64(). We should unify the code around this, such that we do not use atoi/strtol and other implementations.
    
    @SolidWallOfCode Also suggests that we make these APIs a little more feature rich, including:
    
    - Can take a pointer and length, not require null termination of input string
    - Returns the number of characters parsed, or a pointer to the first unparsed character (like strtol)
    - Works with 64 bit numbers
    
    
    I think we already have most of this covered with the existing implementations in ParseRules.cc:
    
    ```C
    int64_t ink_atoi64(const char *);
    uint64_t ink_atoui64(const char *);
    int64_t ink_atoi64(const char *, int);
    ink_atoi(const char *str);
    ink_atoi(const char *str, int len)
    ink_atoui(const char *str)
    ```
    
    So, what I think is left doing here is (as the original Jira suggested):
    
    1. Go through the entire core code base, and find usage of string-to-int conversions (such as ::atoi, ::strtol, and possibly other implementations), and change them to use one of the above APIs as appropriate.
    1. Optional: @SolidWallOfCode Expresses a wish to refactor the implementations in ParseRules.cc / ParseRules.h, such that there is less code duplication (i.e. refactor with a single shared base function or some such).
    1. Optional: Expose two generic, public APIs to ts/ts.h.
    
    These could/should be three different pull requests IMO.
    
    #2 is where we sort of got lost I think. But @SolidWallOfCode posted a suggested public API, that covers all potential use cases in a single, nice C-API (edited here for correctness on the naming):
    
    ```C
    int64_t TSatoi(const const* src, size_t n, const char** end, int radix);
    uint64_t TSatou(const const* src, size_t n, const char** end, int radix);
    ```
    
    The implementation (in InkAPI.cc) for these two APIs would simply be wrappers over the existing ink_atoi() based APIs.

----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---