cvsuser     02/07/14 03:12:42

  Modified:    .        debug.c embed.c
  Log:
  Fix some compile warnings and make the code that tries to read a bytecode
  file in one piece actually do so.
  
  Revision  Changes    Path
  1.15      +8 -7      parrot/debug.c
  
  Index: debug.c
  ===================================================================
  RCS file: /cvs/public/parrot/debug.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- debug.c   13 Jul 2002 22:41:25 -0000      1.14
  +++ debug.c   14 Jul 2002 10:12:42 -0000      1.15
  @@ -2,7 +2,7 @@
    * debug.c
    *
    * CVS Info
  - *    $Id: debug.c,v 1.14 2002/07/13 22:41:25 tom Exp $
  + *    $Id: debug.c,v 1.15 2002/07/14 10:12:42 tom Exp $
    * Overview:
    *    Parrot debugger
    * History:
  @@ -255,22 +255,23 @@
       /* If no line number was specified set it at the current line */
       if (command && *command) {
           ln = atol(command);
  +        
           /* Move to the line where we will set the break point */
           line = pdb->file->line;
           for (i = 1; ((i < ln) && (line->next)); i++)
               line = line->next;
  +   
  +        /* Abort if the line number provided doesn't exists */
  +        if (!line->next) {
  +            fprintf(stderr,"Can't set a breakpoint at line number %li\n",ln);
  +            return;
  +        }
       }
       else {
           /* Get the line to set it */
           line = pdb->file->line;
           while (line->opcode != pdb->cur_opcode)
               line = line->next;
  -    }
  -   
  -    /* Abort if the line number provided doesn't exists */
  -    if (!line->next) {
  -        fprintf(stderr,"Can't set a breakpoint at line number %li\n",ln);
  -        return;
       }
           
       /* Skip lines that are not related to an opcode */
  
  
  
  1.31      +16 -10    parrot/embed.c
  
  Index: embed.c
  ===================================================================
  RCS file: /cvs/public/parrot/embed.c,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -w -r1.30 -r1.31
  --- embed.c   4 Jul 2002 20:39:44 -0000       1.30
  +++ embed.c   14 Jul 2002 10:12:42 -0000      1.31
  @@ -1,7 +1,7 @@
   /* embed.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: embed.c,v 1.30 2002/07/04 20:39:44 mrjoltcola Exp $
  + *     $Id: embed.c,v 1.31 2002/07/14 10:12:42 tom Exp $
    *  Overview:
    *     The Parrot embedding interface.
    *  Data Structure and Algorithms:
  @@ -64,12 +64,14 @@
       struct stat file_stat;
   #endif
   #ifdef HAS_HEADER_SYSMMAN
  -    int fd;
  +    int fd = -1;
   #endif    
   
       if (filename == NULL || strcmp(filename, "-") == 0) {
           /* read from STDIN */
           io = PIO_STDIN(interpreter);
  +        /* read 1k at a time */
  +        program_size = 0;
       } else {
   #ifdef HAS_HEADER_SYSSTAT
           /* if we have stat(), get the actual file size so we can read it
  @@ -106,10 +108,12 @@
   
       /* if we've opened a file (or stdin) with PIO, read it in */
       if (io != NULL) {
  +        size_t chunk_size;
           char *cursor;
           INTVAL read_result;
           
  -        program_code = (char *)malloc(program_size + 1024);
  +        chunk_size = program_size > 0 ? program_size : 1024;
  +        program_code = (char *)malloc(chunk_size);
           program_size = 0;
           if (NULL == program_code) {
               fprintf(stderr,
  @@ -118,10 +122,11 @@
           }
           cursor = (char *)program_code;
   
  -        while ((read_result = PIO_read(interpreter, io, cursor, 1024)) > 0) {
  +        while ((read_result = PIO_read(interpreter, io, cursor, chunk_size)) > 0) {
               program_size += read_result;
  +            chunk_size = 1024;
               program_code =
  -                realloc(program_code, program_size + 1024);
  +                realloc(program_code, program_size + chunk_size);
   
               if (NULL == program_code) {
                   fprintf(stderr,
  @@ -151,8 +156,7 @@
           }
   
           program_code =
  -            mmap(0, program_size, PROT_READ, MAP_SHARED, fd,
  -                 (off_t)0);
  +            mmap(0, program_size, PROT_READ, MAP_SHARED, fd, (off_t)0);
   
           if (!program_code) {
               fprintf(stderr, "Parrot VM: Can't read file %s, code %i.\n",
  @@ -174,8 +178,10 @@
       }
   
   #ifdef HAS_HEADER_SYSMMAN
  -    munmap(program_code, (size_t)program_size);
  +    if (fd >= 0) {
  +        munmap(program_code, program_size);
       close(fd);
  +    }
   #endif
   
       return pf;
  
  
  


Reply via email to