static _INLINE unsigned int _check_times(unsigned x, unsigned y) {
  unsigned long long whole_ans = 
    ((unsigned long long) x)*((unsigned long long)y);
  unsigned word_ans = (unsigned)whole_ans;
  if(word_ans < whole_ans || word_ans > MAX_MALLOC_SIZE)
    _throw_badalloc();
  return word_ans;
}
示例#2
0
struct _fat_ptr
Cstring_to_string (Cstring s)
{
  struct _fat_ptr str;

  if (s == NULL)
    str.base = str.curr = str.last_plus_one = NULL;
  else
    {
      int sz = strlen (s) + 1;
      str.curr = (char *)_cycalloc_atomic (sz);
      if (str.curr == NULL)
        _throw_badalloc ();
      str.base = str.curr;
      str.last_plus_one = str.curr + sz;

      // Copy the string in case the C code frees it or mangles it
      str.curr[--sz] = '\0';
      while (--sz >= 0)
        str.curr[sz] = s[sz];
    }
  return str;
}