~ubuntu-branches/ubuntu/trusty/luajit/trusty

« back to all changes in this revision

Viewing changes to src/lib_string.c

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Tassi
  • Date: 2011-05-09 23:14:21 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110509231421-zdcnqbqk5h6iryxr
Tags: 2.0.0~beta7+dfsg-1
New upstream release with arm support

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
LJLIB_ASM(string_char)
63
63
{
64
 
  int i, nargs = cast_int(L->top - L->base);
 
64
  int i, nargs = (int)(L->top - L->base);
65
65
  char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, (size_t)nargs);
66
66
  for (i = 1; i <= nargs; i++) {
67
67
    int32_t k = lj_lib_checkint(L, i);
702
702
  form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
703
703
}
704
704
 
 
705
static unsigned LUA_INTFRM_T num2intfrm(lua_State *L, int arg)
 
706
{
 
707
  if (sizeof(LUA_INTFRM_T) == 4) {
 
708
    return (LUA_INTFRM_T)lj_lib_checkbit(L, arg);
 
709
  } else {
 
710
    cTValue *o;
 
711
    lj_lib_checknumber(L, arg);
 
712
    o = L->base+arg-1;
 
713
    if (tvisint(o))
 
714
      return (LUA_INTFRM_T)intV(o);
 
715
    else
 
716
      return (LUA_INTFRM_T)numV(o);
 
717
  }
 
718
}
 
719
 
 
720
static unsigned LUA_INTFRM_T num2uintfrm(lua_State *L, int arg)
 
721
{
 
722
  if (sizeof(LUA_INTFRM_T) == 4) {
 
723
    return (unsigned LUA_INTFRM_T)lj_lib_checkbit(L, arg);
 
724
  } else {
 
725
    cTValue *o;
 
726
    lj_lib_checknumber(L, arg);
 
727
    o = L->base+arg-1;
 
728
    if (tvisint(o))
 
729
      return (unsigned LUA_INTFRM_T)intV(o);
 
730
    else if ((int32_t)o->u32.hi < 0)
 
731
      return (unsigned LUA_INTFRM_T)(LUA_INTFRM_T)numV(o);
 
732
    else
 
733
      return (unsigned LUA_INTFRM_T)numV(o);
 
734
  }
 
735
}
 
736
 
705
737
LJLIB_CF(string_format)
706
738
{
707
739
  int arg = 1;
726
758
        break;
727
759
      case 'd':  case 'i':
728
760
        addintlen(form);
729
 
        sprintf(buff, form, (LUA_INTFRM_T)lj_lib_checknum(L, arg));
 
761
        sprintf(buff, form, num2intfrm(L, arg));
730
762
        break;
731
763
      case 'o':  case 'u':  case 'x':  case 'X':
732
764
        addintlen(form);
733
 
        sprintf(buff, form, (unsigned LUA_INTFRM_T)lj_lib_checknum(L, arg));
 
765
        sprintf(buff, form, num2uintfrm(L, arg));
734
766
        break;
735
767
      case 'e':  case 'E': case 'f': case 'g': case 'G': {
736
768
        TValue tv;
737
769
        tv.n = lj_lib_checknum(L, arg);
738
770
        if (LJ_UNLIKELY((tv.u32.hi << 1) >= 0xffe00000)) {
739
771
          /* Canonicalize output of non-finite values. */
740
 
          char *p, nbuf[LUAI_MAXNUMBER2STR];
 
772
          char *p, nbuf[LJ_STR_NUMBUF];
741
773
          size_t len = lj_str_bufnum(nbuf, &tv);
742
774
          if (strfrmt[-1] == 'E' || strfrmt[-1] == 'G') {
743
775
            nbuf[len-3] = nbuf[len-3] - 0x20;
801
833
  g = G(L);
802
834
  setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt));
803
835
  settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1));
804
 
  mt->nomm = cast_byte(~(1u<<MM_index));
 
836
  mt->nomm = (uint8_t)(~(1u<<MM_index));
805
837
  return 1;
806
838
}
807
839