Changeset 5011


Ignore:
Timestamp:
Aug 22, 2006, 1:08:03 AM (18 years ago)
Author:
Gary Byers
Message:

Try not to use sprintf() (at least not for printing integers), since it seems
to need access to pthread data (and calling print_lisp_object() from GDB
might fail if %gs is pointing at the lisp TCR.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lisp-kernel/x86_print.c

    r4025 r5011  
    6464}
    6565
    66 char numbuf[64];
     66char numbuf[64], *digits = "012456789ABCDEF";
     67
     68
     69void
     70sprint_unsigned_decimal_aux(natural n, Boolean first)
     71{
     72  if (n == 0) {
     73    if (first) {
     74      add_char('0');
     75    }
     76  } else {
     77    sprint_unsigned_decimal_aux(n/10, false);
     78    add_char(digits[n%10]);
     79  }
     80}
     81
     82void
     83sprint_unsigned_decimal(natural n)
     84{
     85  sprint_unsigned_decimal_aux(n, true);
     86}
    6787
    6888void
    6989sprint_signed_decimal(signed_natural n)
    7090{
    71   sprintf(numbuf, "%ld", n);
    72   add_c_string(numbuf);
    73 }
    74 
    75 void
    76 sprint_unsigned_decimal(natural n)
    77 {
    78   sprintf(numbuf, "%lu", n);
    79   add_c_string(numbuf);
    80 }
     91  if (n < 0) {
     92    add_char('-');
     93    n = -n;
     94  }
     95  sprint_unsigned_decimal(n);
     96}
     97
    8198
    8299void
    83100sprint_unsigned_hex(natural n)
    84101{
    85 #if WORD_SIZE==64
    86   sprintf(numbuf, "#x%016lx", n);
     102  int i,
     103    ndigits =
     104#if WORD_SIZE == 64
     105    16
    87106#else
    88   sprintf(numbuf, "#x%08lx", n);
     107    8
    89108#endif
    90   add_c_string(numbuf);
     109    ;
     110
     111  add_c_string("#0x");
     112  for (i = 0; i < ndigits; i++) {
     113    add_char(digits[(n>>(4*(ndigits-(i+1))))&15]);
     114  }
    91115}
    92116
     
    210234  sprint_unsigned_decimal(elements);
    211235  add_c_string("-element vector subtag = ");
    212   sprintf(numbuf, "%02X @", subtag);
    213   add_c_string(numbuf);
     236  add_char(digits[subtag>>4]);
     237  add_char(digits[subtag&15]);
     238  add_c_string(" @");
    214239  sprint_unsigned_hex(o);
    215240  add_c_string(" (");
Note: See TracChangeset for help on using the changeset viewer.