Ignore:
Timestamp:
Nov 6, 2005, 7:07:59 PM (18 years ago)
Author:
Sam Hocevar
Message:
  • fixed int size issues here and there
Location:
abuse/trunk/src/imlib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/include/specs.hpp

    r2 r7  
    77#include <fcntl.h>
    88#include <stdlib.h>
     9#include <stdint.h>
    910
    1011extern char *spec_types[];
     
    9697
    9798  // these read and writes, allways read/write Intel endian-ness
    98   unsigned short read_short();
    99   unsigned long read_long();
    100   unsigned char read_byte();
     99  uint16_t read_short();
     100  uint32_t read_long();
     101  uint8_t read_byte();
    101102  double read_double();
    102   void write_short(unsigned short x);
    103   void write_long(unsigned long x);
    104   void write_byte(unsigned char x);
     103  void write_short(uint16_t x);
     104  void write_long(uint32_t x);
     105  void write_byte(uint8_t x);
    105106  void write_double(double x);
    106107  void set_read_buffer_size(long size);
     
    193194                         char *link_filename=NULL);*/
    194195
    195 unsigned short read_short(FILE *fp);
    196 unsigned long read_long(FILE *fp);
    197 unsigned short read_other_long(FILE *fp);
    198 unsigned long read_other_short(FILE *fp);
    199 unsigned char read_byte(FILE *fp);
    200 
    201 void write_short(FILE *fp, unsigned short x);
    202 void write_long(FILE *fp, unsigned long x);
    203 void write_other_short(FILE *fp, unsigned short x);
    204 void write_other_long(FILE *fp, unsigned long x);
    205 void write_byte(FILE *fp, unsigned char x);
     196uint16_t read_short(FILE *fp);
     197uint32_t read_long(FILE *fp);
     198uint32_t read_other_long(FILE *fp);
     199uint16_t read_other_short(FILE *fp);
     200uint8_t read_byte(FILE *fp);
     201
     202void write_short(FILE *fp, uint16_t x);
     203void write_long(FILE *fp, uint32_t x);
     204void write_other_short(FILE *fp, uint16_t x);
     205void write_other_long(FILE *fp, uint32_t x);
     206void write_byte(FILE *fp, uint8_t x);
    206207
    207208void set_spec_main_file(char *filename, int Search_order);
  • abuse/trunk/src/imlib/include/system.h

    r2 r7  
    2626  // so apps can find unlink
    2727  #include <unistd.h>
     28  #include <stdint.h>
    2829#endif
    2930
    3031
    31 #define short_swap(x) (((((unsigned short) (x)))<<8)|((((unsigned short) (x)))>>8))
     32#define short_swap(x) (((((uint16_t) (x)))<<8)|((((uint16_t) (x)))>>8))
    3233#define long_swap(x) \
    33    ((( ((unsigned long)(x)) )>>24)|((( ((unsigned long)(x)) )&0x00ff0000)>>8)| \
    34    ((( ((unsigned long)(x)) )&0x0000ff00)<<8)|(( ((unsigned long)(x)) )<<24))
     34   ((( ((uint32_t)(x)) )>>24)|((( ((uint32_t)(x)) )&0x00ff0000)>>8)| \
     35   ((( ((uint32_t)(x)) )&0x0000ff00)<<8)|(( ((uint32_t)(x)) )<<24))
    3536
    3637#if defined BIG_ENDIANS
    37 #define LONG int
     38#define LONG int32_t
    3839#define int_to_intel(x) short_swap(x)
    3940#define int_to_local(x) int_to_intel(x)
     
    4344#define long_to_local(x) long_to_intel(x)
    4445#else
    45 #define LONG long
     46#define LONG int32_t
    4647#define int_to_intel(x) (x)
    4748#define int_to_local(x) (x)
  • abuse/trunk/src/imlib/jmalloc.cpp

    r4 r7  
    22#include <string.h>
    33#include <stdio.h>
     4#include <stdint.h>
    45
    56#include <specs.hpp>
    67//#include <new.h>
    78
     9#define MEM_CHECK
    810//#ifdef MEM_CHECK
    911//#define MEM_CLEAR
     
    1820
    1921#ifdef MEM_CHECK
    20 long break_mem_point=0;       // can be set in debugger, break mem fun will be called when this address is allocated
     22intptr_t break_mem_point=0;       // can be set in debugger, break mem fun will be called when this address is allocated
    2123void break_mem_fun()
    2224{
     
    3840struct small_block
    3941
    40   unsigned long size;                     // size of blocks...
    41   unsigned long alloc_list;               // bit field saying weither each block is allocated or not.
    42   small_block *next;                      // next small block of same size
     42  unsigned long size;             // size of blocks...
     43  uint32_t alloc_list;            // bit field saying weither each block is allocated or not.
     44  small_block *next;              // next small block of same size
    4345#ifdef MEM_CHECK
    4446  char *name[32];
     
    144146      while (s)
    145147      {
    146                                 for (x=0;x<32;x++)
    147                                   if (s->alloc_list&(1<<x))
    148                                     static_list[size]++;
    149                        
    150                                 s=s->next;
     148        for (x=0;x<32;x++)
     149          if (s->alloc_list&(1<<x))
     150            static_list[size]++;
     151
     152        s=s->next;
    151153      }
    152154
     
    154156      while (s)
    155157      {
    156                                 for (x=0;x<32;x++)
    157                                   if (s->alloc_list&(1<<x))
    158                                     cache_list[size]++;
    159                        
    160                                 s=s->next;
     158        for (x=0;x<32;x++)
     159          if (s->alloc_list&(1<<x))
     160            cache_list[size]++;
     161
     162        s=s->next;
    161163      }
    162164    }
     
    177179      for (int j=0;j<32;j++)
    178180      {
    179                                 if (s->alloc_list&bit)
    180                                 {
    181                                   void *next=(void *)(*(((long *)addr)));
    182                                   if ((long)next!=(long)s)
    183                                   {
    184                                     fprintf(stderr,"inspect : bad pointer\n");
    185                                     return ;       
    186                                   }
    187                                 }
    188                                 bit=bit<<1;
    189                                 addr+=s->size+4;
     181        if (s->alloc_list&bit)
     182        {
     183          void *next=(void *)(*(((intptr_t *)addr)));
     184          if ((intptr_t)next!=(intptr_t)s)
     185          {
     186            fprintf(stderr,"inspect : bad pointer\n");
     187            return ;       
     188          }
     189        }
     190        bit=bit<<1;
     191        addr+=s->size+4;
    190192      }
    191193    }
     
    215217    {     
    216218      fprintf(fp,"*** Small Block size = %d ***\n",i);     
    217       unsigned long bit=1;
    218       char *addr=((char *)(s+1));
    219       for (int j=0;j<32;j++)
    220       {
    221                                 fprintf(fp,"%p   ",addr);
    222                                 if (s->alloc_list&bit)
    223                                 {
    224 #ifdef MEM_CHECK
    225                                   fprintf(fp,"%s\n",s->name[j]);
    226 #else
    227                                   fprintf(fp,"allocated\n");
    228 #endif   
    229                                 } else fprintf(fp,"FREE\n");
    230                                 bit=bit<<1;
    231                                 addr+=s->size+4;
    232       }
    233     }
    234   }
    235 
    236 
    237   fprintf(fp,"************** CACHE SPACE ******************\n",block_size);
    238   i=0;
    239   for (f=cfirst;f;f=f->next,i++)
    240   {   
    241     fprintf(fp,"%4d   %p %4d      ",i,f,f->size);
    242 #ifdef MEM_CHECK
    243     if (f->size>0)
    244       fprintf(fp,"%s",f->name);
    245     else fprintf(fp,"FREE");
    246 #endif
    247     fprintf(fp,"\n");
    248   }   
    249   for (i=0;i<JM_SMALL_SIZE;i++)
    250   {
    251     for (small_block *s=cblocks[i];s;s=s->next)
    252     {     
    253       fprintf(fp,"*** Small Block size = %d ***\n",i);     
    254       unsigned long bit=1;
     219      uint32_t bit=1;
    255220      char *addr=((char *)(s+1));
    256221      for (int j=0;j<32;j++)
     
    270235    }
    271236  }
     237
     238
     239  fprintf(fp,"************** CACHE SPACE ******************\n",block_size);
     240  i=0;
     241  for (f=cfirst;f;f=f->next,i++)
     242  {   
     243    fprintf(fp,"%4d   %p %4d      ",i,f,f->size);
     244#ifdef MEM_CHECK
     245    if (f->size>0)
     246      fprintf(fp,"%s",f->name);
     247    else fprintf(fp,"FREE");
     248#endif
     249    fprintf(fp,"\n");
     250  }   
     251  for (i=0;i<JM_SMALL_SIZE;i++)
     252  {
     253    for (small_block *s=cblocks[i];s;s=s->next)
     254    {     
     255      fprintf(fp,"*** Small Block size = %d ***\n",i);     
     256      uint32_t bit=1;
     257      char *addr=((char *)(s+1));
     258      for (int j=0;j<32;j++)
     259      {
     260        fprintf(fp,"%p   ",addr);
     261        if (s->alloc_list&bit)
     262        {
     263#ifdef MEM_CHECK
     264          fprintf(fp,"%s\n",s->name[j]);
     265#else
     266          fprintf(fp,"allocated\n");
     267#endif   
     268        } else fprintf(fp,"FREE\n");
     269        bit=bit<<1;
     270        addr+=s->size+4;
     271      }
     272    }
     273  }
    272274}
    273275
    274276long block_manager::pointer_size(void *ptr)
    275277{
    276   void *next=(void *)(*(((long *)ptr)-1));
     278  void *next=(void *)(*(((intptr_t *)ptr)-1));
    277279  if (next>ptr)
    278280    return ((memory_node *)(((char *)ptr)-sizeof(memory_node)))->size;
     
    340342#ifdef MEM_CHECK
    341343      s->name[0]=strcpy((char *)malloc(strlen(name)+1),name);
    342       if ((long)s==break_mem_point)
     344      if ((intptr_t)s==break_mem_point)
    343345        break_mem_fun();
    344346#endif     
     
    361363
    362364#ifdef MEM_CHECK
    363           if ((long)addr==break_mem_point)
     365          if ((intptr_t)addr==break_mem_point)
    364366            break_mem_fun();
    365367#endif
     
    396398  s->name=strcpy((char *)malloc(strlen(name)+1),name);
    397399
    398   if ((long)s==break_mem_point)
     400  if ((intptr_t)s==break_mem_point)
    399401    break_mem_fun();
    400402
     
    425427      *addr=(long)s;
    426428#ifdef MEM_CHECK
    427       if ((long)s==break_mem_point)
     429      if ((intptr_t)s==break_mem_point)
    428430        break_mem_fun();
    429431#endif
     
    440442#ifdef MEM_CHECK
    441443          s->name[i]=strcpy((char *)malloc(strlen(name)+1),name);
    442           if ((long)s==break_mem_point)
     444          if ((intptr_t)s==break_mem_point)
    443445            break_mem_fun();
    444446#endif           
     
    473475#ifdef MEM_CHECK
    474476      nc->name=strcpy((char *)malloc(strlen(name)+1),name);     
    475       if ((long)nc==break_mem_point)
     477      if ((intptr_t)nc==break_mem_point)
    476478        break_mem_fun();
    477479#endif     
     
    499501#ifdef MEM_CHECK
    500502  s->name=strcpy((char *)malloc(strlen(name)+1),name);
    501   if ((long)s==break_mem_point)
     503  if ((intptr_t)s==break_mem_point)
    502504    break_mem_fun();
    503505#endif
     
    696698void jmalloc_init(long min_size)
    697699{
     700  fprintf(stderr,"Disabling memory manager, using libc instead\n");
     701  return;
     702
    698703  if (bmanage_total)
    699704    fprintf(stderr,"warning : jmalloc_init called twice\n");
     
    722727    if (mem)
    723728    {
    724                         bmanage[bmanage_total].init(mem,size,HI_BLOCK);
    725                         bmanage_total++;     
    726                         fprintf(stderr,"Added himem block (%d bytes)\n",size);
     729      bmanage[bmanage_total].init(mem,size,HI_BLOCK);
     730      bmanage_total++;     
     731      fprintf(stderr,"Added himem block (%d bytes)\n",size);
    727732    }
    728733
     
    732737    bmanage_total++;      */
    733738
    734 
    735 
    736739#ifdef __WATCOMC__
    737740    if (size!=jmalloc_max_size)
     
    739742      do
    740743      {
    741                                 size=low_memory_available();
    742                                 if (size>jmalloc_min_low_size+0x1000)              // save 64K for misc low memory needs
    743                                 {
    744                                   bmanage[bmanage_total].init(alloc_low_memory(size-jmalloc_min_low_size-0x1000),size-jmalloc_min_low_size-0x1000,LOW_BLOCK);
    745                                   bmanage_total++;
    746                                   fprintf(stderr,"Added low memory block (%d bytes)\n",size);
    747                                 }
     744        size=low_memory_available();
     745        if (size>jmalloc_min_low_size+0x1000)              // save 64K for misc low memory needs
     746        {
     747          bmanage[bmanage_total].init(alloc_low_memory(size-jmalloc_min_low_size-0x1000),size-jmalloc_min_low_size-0x1000,LOW_BLOCK);
     748          bmanage_total++;
     749          fprintf(stderr,"Added low memory block (%d bytes)\n",size);
     750        }
    748751      } while (size>jmalloc_min_low_size+0x1000);
    749752      if (size<jmalloc_min_low_size)
    750753      {
    751                                 fprintf(stderr,not_enough_low_memory_message,size,jmalloc_min_low_size);
    752                                 exit(0);
     754        fprintf(stderr,not_enough_low_memory_message,size,jmalloc_min_low_size);
     755        exit(0);
    753756      }
    754757    }
    755758#endif
    756759 
    757 
    758760    fprintf(stderr,"Memory available : %d\n",j_available());
    759761    if (j_available()<min_size)
     
    762764      exit(0);
    763765    }
    764 
    765766  }
    766767}
     
    796797      void *a;
    797798      if (alloc_space==ALLOC_SPACE_STATIC)
     799      {
    798800        a=bmanage[i].static_alloc(size,name);
     801      }
    799802      else
     803      {
    800804        a=bmanage[i].cache_alloc(size,name);
     805      }
    801806      if (a) return a;
    802807    }
  • abuse/trunk/src/imlib/specs.cpp

    r4 r7  
    44#include <stdio.h>
    55#include <stdlib.h>
     6#include <stdint.h>
    67#include <ctype.h>
    78#include <fcntl.h>
     
    2425                    "Invalid Type",             // 3
    2526                    "Image",                    // 4
    26                                         "Fore Tile",
     27                    "Fore Tile",
    2728                    "Back Tile",
    2829                    "Character",
    2930                    "8 Morph",
    3031                    "16 Morph",
    31                     "Grue objs",
    32                     "Extern WAV",
    33                     "DMX MUS",
    34                     "Patched morph",
    35                     "Normal file",
    36                     "Compress1 file",
    37                     "Vector Image",
    38                     "Light list",
    39                     "Grue fgmap",
    40                     "Grue bgmap",
    41                     "Data array",
    42                     "Character2",
    43                     "Particle",
    44                     "Extern lcache"
     32                    "Grue objs",
     33                    "Extern WAV",
     34                    "DMX MUS",
     35                    "Patched morph",
     36                    "Normal file",
     37                    "Compress1 file",
     38                    "Vector Image",
     39                    "Light list",
     40                    "Grue fgmap",
     41                    "Grue bgmap",
     42                    "Data array",
     43                    "Character2",
     44                    "Particle",
     45                    "Extern lcache"
    4546};
    4647
     
    420421      if (se)   
    421422      {
    422                                 start_offset=se->offset;
    423                                 current_offset = 0;
    424                                 file_length=se->size;
    425                                 rbuf_start=rbuf_end=0;
     423        start_offset=se->offset;
     424        current_offset = 0;
     425        file_length=se->size;
     426        rbuf_start=rbuf_end=0;
    426427      } else
    427428      {
    428                                 close(fd);
    429                                 fd=-1;
     429        close(fd);
     430        fd=-1;
    430431      }
    431432    } 
     
    548549int jFILE::unbuffered_seek(long offset, int whence) // whence=SEEK_SET, SEEK_CUR, SEEK_END, ret=0=success
    549550{
    550         long ret;
    551        
    552         if (fast_load_mode == 2)
    553         {
    554                 switch (whence)
    555                 {
     551  long ret;
     552
     553  if (fast_load_mode == 2)
     554  {
     555    switch (whence)
     556    {
    556557    case SEEK_SET :
    557         current_offset = start_offset+offset;
    558         break;
     558      current_offset = start_offset+offset;
     559      break;
    559560    case SEEK_END :
    560         current_offset = start_offset+file_length-offset;
    561         break;
     561      current_offset = start_offset+file_length-offset;
     562      break;
    562563    case SEEK_CUR :
    563         current_offset += offset;
    564         break;
     564      current_offset += offset;
     565      break;
    565566    default:
    566         ret = -1;
    567         break;
     567      ret = -1;
     568      break;
    568569    }
    569                 return current_offset;
    570         }
    571        
     570    return current_offset;
     571  }
     572
    572573  switch (whence)
    573574  {
     
    584585  if (ret>=0)
    585586  {
    586         current_offset = ret - start_offset;
    587         if (spec_main_fd == fd)
    588                 spec_main_offset = ret;
    589         return ret;
     587    current_offset = ret - start_offset;
     588    if (spec_main_fd == fd)
     589      spec_main_offset = ret;
     590    return ret;
    590591  }
    591592  else
    592           return -1;  // if a bad whence, then failure
    593 }
    594 
    595 
    596 unsigned char bFILE::read_byte()
    597 { unsigned char x;
     593    return -1;  // if a bad whence, then failure
     594}
     595
     596
     597uint8_t bFILE::read_byte()
     598{ uint8_t x;
    598599  read(&x,1);
    599600  return x;
    600601}
    601602
    602 unsigned short bFILE::read_short()
     603uint16_t bFILE::read_short()
    603604{
    604   unsigned short x;
     605  uint16_t x;
    605606  read(&x,2);
    606607  return int_to_local(x);
     
    608609
    609610
    610 unsigned long bFILE::read_long()
     611uint32_t bFILE::read_long()
    611612{
    612   unsigned long x;
     613  uint32_t x;
    613614  read(&x,4);
    614615  return long_to_local(x);
    615616}
    616617
    617 void bFILE::write_byte(unsigned char x)
     618void bFILE::write_byte(uint8_t x)
    618619{
    619620  write(&x,1);
    620621}
    621622
    622 void bFILE::write_short(unsigned short x)
     623void bFILE::write_short(uint16_t x)
    623624{
    624625  x=int_to_local(x);
     
    627628
    628629
    629 void bFILE::write_long(unsigned long x)
     630void bFILE::write_long(uint32_t x)
    630631{
    631632  x=long_to_local(x);
     
    912913}
    913914
    914 unsigned short read_short(FILE *fp)
    915 {
    916   unsigned short x;
     915uint16_t read_short(FILE *fp)
     916{
     917  uint16_t x;
    917918  fread(&x,1,2,fp);
    918919  return int_to_local(x);
    919920}
    920921
    921 unsigned long read_long(FILE *fp)
    922 {
    923   unsigned long x;
     922uint32_t read_long(FILE *fp)
     923{
     924  uint32_t x;
    924925  fread(&x,1,4,fp);
    925   return (long)long_to_local(x);
    926 }
    927 void write_short(FILE *fp, unsigned short x)
     926  return long_to_local(x);
     927}
     928void write_short(FILE *fp, uint16_t x)
    928929{
    929930  x=int_to_local(x);
     
    931932}
    932933
    933 void write_long(FILE *fp, unsigned long x)
     934void write_long(FILE *fp, uint32_t x)
    934935{
    935936  x=long_to_local(x);
     
    937938}
    938939
    939 unsigned char read_byte(FILE *fp) { return fgetc(fp)&0xff; }
    940 void write_byte(FILE *fp, unsigned char x) { fputc(x,fp); }
    941 
    942 unsigned short read_other_long(FILE *fp)
    943 {
    944   unsigned long x;
     940uint8_t read_byte(FILE *fp) { return fgetc(fp)&0xff; }
     941void write_byte(FILE *fp, uint8_t x) { fputc((unsigned char)x,fp); }
     942
     943uint32_t read_other_long(FILE *fp)
     944{
     945  uint32_t x;
    945946  fread(&x,1,4,fp);
    946947  return big_long_to_local(x);
    947948}
    948949
    949 unsigned long read_other_short(FILE *fp)
    950 {
    951   unsigned short x;
     950uint16_t read_other_short(FILE *fp)
     951{
     952  uint16_t x;
    952953  fread(&x,1,2,fp);
    953954  return big_short_to_local(x);
     
    955956
    956957
    957 void write_other_short(FILE *fp, unsigned short x)
     958void write_other_short(FILE *fp, uint16_t x)
    958959{
    959960  x=big_short_to_local(x);
     
    961962}
    962963
    963 void write_other_long(FILE *fp, unsigned long x)
     964void write_other_long(FILE *fp, uint32_t x)
    964965{
    965966  x=big_long_to_local(x);
Note: See TracChangeset for help on using the changeset viewer.