Changeset 5414

Show
Ignore:
Timestamp:
10/26/09 05:52:07 (4 years ago)
Author:
nbd
Message:

nixio: store stats and other number information as integer, which works better when lua number support is downgraded from double to float

Location:
luci/trunk/libs/nixio/src
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/nixio/src/address.c

    r5061 r5414  
    324324 
    325325    lua_pushstring(L, addr.host); 
    326     lua_pushnumber(L, addr.port); 
     326    lua_pushinteger(L, addr.port); 
    327327    return 2; 
    328328} 
     
    343343 
    344344    lua_pushstring(L, addr.host); 
    345     lua_pushnumber(L, addr.port); 
     345    lua_pushinteger(L, addr.port); 
    346346    return 2; 
    347347} 
     
    421421                    struct nixio__nds *stats = c->ifa_data; 
    422422 
    423                     lua_pushnumber(L, stats->rx_packets); 
     423                    lua_pushinteger(L, stats->rx_packets); 
    424424                    lua_setfield(L, -2, "rx_packets"); 
    425425 
    426                     lua_pushnumber(L, stats->tx_packets); 
     426                    lua_pushinteger(L, stats->tx_packets); 
    427427                    lua_setfield(L, -2, "tx_packets"); 
    428428 
    429                     lua_pushnumber(L, stats->rx_bytes); 
     429                    lua_pushinteger(L, stats->rx_bytes); 
    430430                    lua_setfield(L, -2, "rx_bytes"); 
    431431 
    432                     lua_pushnumber(L, stats->tx_bytes); 
     432                    lua_pushinteger(L, stats->tx_bytes); 
    433433                    lua_setfield(L, -2, "tx_bytes"); 
    434434 
    435                     lua_pushnumber(L, stats->rx_errors); 
     435                    lua_pushinteger(L, stats->rx_errors); 
    436436                    lua_setfield(L, -2, "rx_errors"); 
    437437 
    438                     lua_pushnumber(L, stats->tx_errors); 
     438                    lua_pushinteger(L, stats->tx_errors); 
    439439                    lua_setfield(L, -2, "tx_errors"); 
    440440 
    441                     lua_pushnumber(L, stats->rx_dropped); 
     441                    lua_pushinteger(L, stats->rx_dropped); 
    442442                    lua_setfield(L, -2, "rx_dropped"); 
    443443 
    444                     lua_pushnumber(L, stats->tx_dropped); 
     444                    lua_pushinteger(L, stats->tx_dropped); 
    445445                    lua_setfield(L, -2, "tx_dropped"); 
    446446 
    447                     lua_pushnumber(L, stats->multicast); 
     447                    lua_pushinteger(L, stats->multicast); 
    448448                    lua_setfield(L, -2, "multicast"); 
    449449 
    450                     lua_pushnumber(L, stats->collisions); 
     450                    lua_pushinteger(L, stats->collisions); 
    451451                    lua_setfield(L, -2, "collisions"); 
    452452                } else { 
  • luci/trunk/libs/nixio/src/binary.c

    r4756 r5414  
    9898    size_t len; 
    9999    const char *buffer = luaL_checklstring(L, 1, &len); 
    100     uint32_t value = luaL_optnumber(L, 2, 0); 
     100    uint32_t value = luaL_optinteger(L, 2, 0); 
    101101 
    102102    value = ~value; 
  • luci/trunk/libs/nixio/src/bind.c

    r4437 r5414  
    262262    if (!nixio__addr_parse(&addr, (struct sockaddr *)&saddr)) { 
    263263        lua_pushstring(L, addr.host); 
    264         lua_pushnumber(L, addr.port); 
     264        lua_pushinteger(L, addr.port); 
    265265        return 3; 
    266266    } else { 
  • luci/trunk/libs/nixio/src/bit.c

    r5064 r5414  
    2222 
    2323/* 52 bit maximum precision */ 
    24 #define NIXIO_BIT_BMAX 52 
    25 #define NIXIO_BIT_NMAX 0xfffffffffffff 
     24#define NIXIO_BIT_BMAX 32 
     25#define NIXIO_BIT_NMAX 0xffffffff 
    2626 
    2727#define NIXIO_BIT_XOP(BIT_XOP)                      \ 
    28     uint64_t oper = luaL_checknumber(L, 1);         \ 
     28    uint64_t oper = luaL_checkinteger(L, 1);            \ 
    2929    const int args = lua_gettop(L);                 \ 
    3030                                                    \ 
    3131    for (int i = 2; i <= args; i++) {               \ 
    32         uint64_t oper2 = luaL_checknumber(L, i);    \ 
     32        uint64_t oper2 = luaL_checkinteger(L, i);   \ 
    3333        oper BIT_XOP oper2;                         \ 
    3434    }                                               \ 
    3535                                                    \ 
    36     lua_pushnumber(L, oper);                        \ 
     36    lua_pushinteger(L, oper);                       \ 
    3737    return 1;                                       \ 
    3838 
     
    5555 
    5656static int nixio_bit_not(lua_State *L) { 
    57     lua_pushnumber(L, (~((uint64_t)luaL_checknumber(L, 1))) & NIXIO_BIT_NMAX); 
     57    lua_pushinteger(L, (~((uint64_t)luaL_checkinteger(L, 1))) & NIXIO_BIT_NMAX); 
    5858    return 1; 
    5959} 
    6060 
    6161static int nixio_bit_shl(lua_State *L) { 
    62     uint64_t oper = luaL_checknumber(L, 1); 
     62    uint64_t oper = luaL_checkinteger(L, 1); 
    6363    oper <<= luaL_checkinteger(L, 2); 
    6464    if (oper > NIXIO_BIT_NMAX) { 
    6565        return luaL_error(L, "arithmetic overflow"); 
    6666    } else { 
    67         lua_pushnumber(L, oper); 
     67        lua_pushinteger(L, oper); 
    6868        return 1; 
    6969    } 
     
    7171 
    7272static int nixio_bit_ashr(lua_State *L) { 
    73     int64_t oper = luaL_checknumber(L, 1); 
    74     lua_pushnumber(L, oper >> luaL_checkinteger(L, 2)); 
     73    int64_t oper = luaL_checkinteger(L, 1); 
     74    lua_pushinteger(L, oper >> luaL_checkinteger(L, 2)); 
    7575    return 1; 
    7676} 
    7777 
    7878static int nixio_bit_shr(lua_State *L) { 
    79     uint64_t oper = luaL_checknumber(L, 1); 
    80     lua_pushnumber(L, oper >> luaL_checkinteger(L, 2)); 
     79    uint64_t oper = luaL_checkinteger(L, 1); 
     80    lua_pushinteger(L, oper >> luaL_checkinteger(L, 2)); 
    8181    return 1; 
    8282} 
     
    8787 
    8888static int nixio_bit_check(lua_State *L) { 
    89     uint64_t oper  = luaL_checknumber(L, 1); 
    90     uint64_t oper2 = luaL_checknumber(L, 2); 
     89    uint64_t oper  = luaL_checkinteger(L, 1); 
     90    uint64_t oper2 = luaL_checkinteger(L, 2); 
    9191    lua_pushboolean(L, (oper & oper2) == oper2); 
    9292    return 1; 
     
    9494 
    9595static int nixio_bit_cast(lua_State *L) { 
    96     lua_pushnumber(L, ((uint64_t)luaL_checknumber(L, 1)) & NIXIO_BIT_NMAX); 
     96    lua_pushinteger(L, ((uint64_t)luaL_checkinteger(L, 1)) & NIXIO_BIT_NMAX); 
    9797    return 1; 
    9898} 
    9999 
    100100static int nixio_bit_swap(lua_State *L) { 
    101     uint64_t op = luaL_checknumber(L, 1); 
     101    uint64_t op = luaL_checkinteger(L, 1); 
    102102    op = (op >> 24) | ((op >> 8) & 0xff00) | ((op & 0xff00) << 8) | (op << 24); 
    103     lua_pushnumber(L, op); 
     103    lua_pushinteger(L, op); 
    104104    return 1; 
    105105} 
     
    127127    lua_newtable(L); 
    128128    luaL_register(L, NULL, R); 
    129     lua_pushnumber(L, NIXIO_BIT_BMAX); 
     129    lua_pushinteger(L, NIXIO_BIT_BMAX); 
    130130    lua_setfield(L, -2, "bits"); 
    131     lua_pushnumber(L, NIXIO_BIT_NMAX); 
     131    lua_pushinteger(L, NIXIO_BIT_NMAX); 
    132132    lua_setfield(L, -2, "max"); 
    133133    lua_setfield(L, -2, "bit"); 
  • luci/trunk/libs/nixio/src/file.c

    r5106 r5414  
    227227static int nixio_file_seek(lua_State *L) { 
    228228    int fd = nixio__checkfd(L, 1); 
    229     off_t len = (off_t)luaL_checknumber(L, 2); 
     229    off_t len = (off_t)luaL_checkinteger(L, 2); 
    230230    int whence; 
    231231    const char *whstr = luaL_optlstring(L, 3, "set", NULL); 
     
    243243        return nixio__perror(L); 
    244244    } else { 
    245         lua_pushnumber(L, len); 
     245        lua_pushinteger(L, len); 
    246246        return 1; 
    247247    } 
     
    254254        return nixio__perror(L); 
    255255    } else { 
    256         lua_pushnumber(L, pos); 
     256        lua_pushinteger(L, pos); 
    257257        return 1; 
    258258    } 
     
    292292    int fd = nixio__checkfd(L, 1); 
    293293    const char *flag = luaL_checkstring(L, 2); 
    294     off_t len = (off_t)luaL_optnumber(L, 3, 0); 
     294    off_t len = (off_t)luaL_optinteger(L, 3, 0); 
    295295    int stat; 
    296296 
  • luci/trunk/libs/nixio/src/fs.c

    r4887 r5414  
    8484            return mode; 
    8585        } 
    86     } else if (lua_isnumber(L, idx)) { 
     86    } else if (lua_isinteger(L, idx)) { 
    8787        int decmode = lua_tointeger(L, idx); 
    8888        int s = (decmode % 10000)   / 1000; 
     
    258258        return nixio__pstatus(L, !utimes(path, NULL)); 
    259259    } else { 
    260         double atime = luaL_checknumber(L, 2); 
    261         double mtime = luaL_optnumber(L, 3, atime); 
     260        double atime = luaL_checkinteger(L, 2); 
     261        double mtime = luaL_optinteger(L, 3, atime); 
    262262        struct timeval times[2]; 
    263263 
    264264        times[0].tv_sec = atime; 
    265         times[0].tv_usec = (long)((atime - (int64_t)atime) * 1000000); 
     265        times[0].tv_usec = 0; 
    266266        times[1].tv_sec = mtime; 
    267         times[1].tv_usec = (long)((mtime - (int64_t)mtime) * 1000000); 
     267        times[1].tv_usec = 0; 
    268268 
    269269        return nixio__pstatus(L, !utimes(path, times)); 
     
    318318    lua_setfield(L, -2, "rdev"); 
    319319 
    320     lua_pushnumber(L, buf->st_size); 
     320    lua_pushinteger(L, buf->st_size); 
    321321    lua_setfield(L, -2, "size"); 
    322322 
     
    470470    lua_createtable(L, 0, 12); 
    471471 
    472     lua_pushnumber(L, buf->f_bavail); 
     472    lua_pushinteger(L, buf->f_bavail); 
    473473    lua_setfield(L, -2, "bavail"); 
    474474 
    475     lua_pushnumber(L, buf->f_bfree); 
     475    lua_pushinteger(L, buf->f_bfree); 
    476476    lua_setfield(L, -2, "bfree"); 
    477477 
    478     lua_pushnumber(L, buf->f_blocks); 
     478    lua_pushinteger(L, buf->f_blocks); 
    479479    lua_setfield(L, -2, "blocks"); 
    480480 
    481     lua_pushnumber(L, buf->f_bsize); 
     481    lua_pushinteger(L, buf->f_bsize); 
    482482    lua_setfield(L, -2, "bsize"); 
    483483 
    484     lua_pushnumber(L, buf->f_frsize); 
     484    lua_pushinteger(L, buf->f_frsize); 
    485485    lua_setfield(L, -2, "frsize"); 
    486486 
    487     lua_pushnumber(L, buf->f_favail); 
     487    lua_pushinteger(L, buf->f_favail); 
    488488    lua_setfield(L, -2, "favail"); 
    489489 
    490     lua_pushnumber(L, buf->f_ffree); 
     490    lua_pushinteger(L, buf->f_ffree); 
    491491    lua_setfield(L, -2, "ffree"); 
    492492 
    493     lua_pushnumber(L, buf->f_files); 
     493    lua_pushinteger(L, buf->f_files); 
    494494    lua_setfield(L, -2, "files"); 
    495495 
    496     lua_pushnumber(L, buf->f_flag); 
     496    lua_pushinteger(L, buf->f_flag); 
    497497    lua_setfield(L, -2, "flag"); 
    498498 
    499     lua_pushnumber(L, buf->f_fsid); 
     499    lua_pushinteger(L, buf->f_fsid); 
    500500    lua_setfield(L, -2, "fsid"); 
    501501 
    502     lua_pushnumber(L, buf->f_namemax); 
     502    lua_pushinteger(L, buf->f_namemax); 
    503503    lua_setfield(L, -2, "namemax"); 
    504504 
  • luci/trunk/libs/nixio/src/io.c

    r4437 r5414  
    142142            if (!nixio__addr_parse(&naddr, (struct sockaddr *)&addrobj)) { 
    143143                lua_pushstring(L, naddr.host); 
    144                 lua_pushnumber(L, naddr.port); 
     144                lua_pushinteger(L, naddr.port); 
    145145                return 3; 
    146146            } else { 
  • luci/trunk/libs/nixio/src/nixio.c

    r4440 r5414  
    148148 
    149149    /* module version */ 
    150     lua_pushnumber(L, VERSION); 
     150    lua_pushinteger(L, VERSION); 
    151151    lua_setfield(L, -2, "version"); 
    152152 
  • luci/trunk/libs/nixio/src/process.c

    r4437 r5414  
    226226    } else { 
    227227        lua_createtable(L, 0, 4); 
    228         lua_pushnumber(L, buf.tms_cstime); 
     228        lua_pushinteger(L, buf.tms_cstime); 
    229229        lua_setfield(L, -2, "cstime"); 
    230230 
    231         lua_pushnumber(L, buf.tms_cutime); 
     231        lua_pushinteger(L, buf.tms_cutime); 
    232232        lua_setfield(L, -2, "cutime"); 
    233233 
    234         lua_pushnumber(L, buf.tms_stime); 
     234        lua_pushinteger(L, buf.tms_stime); 
    235235        lua_setfield(L, -2, "stime"); 
    236236 
    237         lua_pushnumber(L, buf.tms_utime); 
     237        lua_pushinteger(L, buf.tms_utime); 
    238238        lua_setfield(L, -2, "utime"); 
    239239 
     
    366366    lua_createtable(L, 0, 12); 
    367367 
    368     lua_pushnumber(L, info.bufferram); 
     368    lua_pushinteger(L, info.bufferram); 
    369369    lua_setfield(L, -2, "bufferram"); 
    370370 
    371     lua_pushnumber(L, info.freehigh); 
     371    lua_pushinteger(L, info.freehigh); 
    372372    lua_setfield(L, -2, "freehigh"); 
    373373 
    374     lua_pushnumber(L, info.freeram); 
     374    lua_pushinteger(L, info.freeram); 
    375375    lua_setfield(L, -2, "freeram"); 
    376376 
    377     lua_pushnumber(L, info.freeswap); 
     377    lua_pushinteger(L, info.freeswap); 
    378378    lua_setfield(L, -2, "freeswap"); 
    379379 
    380380    lua_createtable(L, 0, 3); 
    381381    for (int i=0; i<3; i++) { 
    382         lua_pushnumber(L, info.loads[i] / 65536.); 
     382        lua_pushinteger(L, info.loads[i] / 65536.); 
    383383        lua_rawseti(L, -2, i+1); 
    384384    } 
    385385    lua_setfield(L, -2, "loads"); 
    386386 
    387     lua_pushnumber(L, info.mem_unit); 
     387    lua_pushinteger(L, info.mem_unit); 
    388388    lua_setfield(L, -2, "mem_unit"); 
    389389 
    390     lua_pushnumber(L, info.procs); 
     390    lua_pushinteger(L, info.procs); 
    391391    lua_setfield(L, -2, "procs"); 
    392392 
    393     lua_pushnumber(L, info.sharedram); 
     393    lua_pushinteger(L, info.sharedram); 
    394394    lua_setfield(L, -2, "sharedram"); 
    395395 
    396     lua_pushnumber(L, info.totalhigh); 
     396    lua_pushinteger(L, info.totalhigh); 
    397397    lua_setfield(L, -2, "totalhigh"); 
    398398 
    399     lua_pushnumber(L, info.totalram); 
     399    lua_pushinteger(L, info.totalram); 
    400400    lua_setfield(L, -2, "totalram"); 
    401401 
    402     lua_pushnumber(L, info.totalswap); 
     402    lua_pushinteger(L, info.totalswap); 
    403403    lua_setfield(L, -2, "totalswap"); 
    404404 
    405     lua_pushnumber(L, info.uptime); 
     405    lua_pushinteger(L, info.uptime); 
    406406    lua_setfield(L, -2, "uptime"); 
    407407 
  • luci/trunk/libs/nixio/src/sockopt.c

    r4440 r5414  
    205205            } 
    206206            lua_pushstring(L, buf); 
    207             lua_pushnumber(L, val.ipv6mr_interface); 
     207            lua_pushinteger(L, val.ipv6mr_interface); 
    208208            return 2; 
    209209        } 
  • luci/trunk/libs/nixio/src/splice.c

    r5312 r5414  
    9191    } 
    9292 
    93     lua_pushnumber(L, spliced); 
     93    lua_pushinteger(L, spliced); 
    9494    return 1; 
    9595} 
     
    152152#endif 
    153153 
    154     lua_pushnumber(L, spliced); 
     154    lua_pushinteger(L, spliced); 
    155155    return 1; 
    156156} 
  • luci/trunk/libs/nixio/src/user.c

    r4437 r5414  
    7979    errno = 0; 
    8080    if (lua_isnumber(L, 1)) { 
    81         gr = getgrgid(lua_tonumber(L, 1)); 
     81        gr = getgrgid(lua_tointeger(L, 1)); 
    8282    } else if (lua_isstring(L, 1)) { 
    8383        gr = getgrnam(lua_tostring(L, 1)); 
     
    132132    errno = 0; 
    133133    if (lua_isnumber(L, 1)) { 
    134         pw = getpwuid(lua_tonumber(L, 1)); 
     134        pw = getpwuid(lua_tointeger(L, 1)); 
    135135    } else if (lua_isstring(L, 1)) { 
    136136        pw = getpwnam(lua_tostring(L, 1));