示例#1
0
void*
libspectrum_realloc_n( void *ptr, size_t nmemb, size_t size )
{
  if( nmemb > SIZE_MAX / size ) abort();

  return libspectrum_realloc( ptr, nmemb * size );
}
示例#2
0
static int machine_add_machine( int (*init_function)( fuse_machine_info *machine ) )
{
  fuse_machine_info *machine;
  int error;

  machine_count++;

  machine_types =
    libspectrum_realloc( machine_types,
                         machine_count * sizeof( fuse_machine_info* ) );

  machine_types[ machine_count - 1 ] = malloc( sizeof( fuse_machine_info ) );
  if( !machine_types[ machine_count - 1 ] ) {
    ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ );
    return 1;
  }

  machine = machine_types[ machine_count - 1 ];

  error = init_function( machine ); if( error ) return error;

  machine_set_const_timings( machine );

  machine->capabilities = libspectrum_machine_capabilities( machine->machine );

  return 0;
}
示例#3
0
/* write a pulse of pulse_length bits into the tape_buffer */
static void
write_pulse( libspectrum_dword pulse_length )
{
  int i;
  size_t target_size = rle_state.length + pulse_length/8;

  if( rle_state.tape_length <= target_size ) {
    rle_state.tape_length = target_size * 2;
    rle_state.tape_buffer = libspectrum_realloc( rle_state.tape_buffer,
                                                 rle_state.tape_length );
  }

  for( i = pulse_length; i > 0; i-- ) {
    if( rle_state.level ) 
      *(rle_state.tape_buffer + rle_state.length) |=
        1 << (7 - rle_state.bits_used);
    rle_state.bits_used++;

    if( rle_state.bits_used == 8 ) {
      rle_state.length++;
      *(rle_state.tape_buffer + rle_state.length) = 0;
      rle_state.bits_used = 0;
    }
  }

  rle_state.level = !rle_state.level;
}
示例#4
0
static struct border_change_t *
alloc_change(void)
{
  static int border_changes_size = 0;

  if( border_changes_size == border_changes_last ) {
    border_changes_size += 10;
    border_changes = libspectrum_realloc( border_changes,
                                          border_changes_size *
                                            sizeof( struct border_change_t )
                                        );
  }
  return border_changes + border_changes_last++; 
}
示例#5
0
static void
expand_array( GArray *array, guint len )
{
  size_t new_size = array->len + len;
  gchar *new_data;

  if( new_size < 2 * array->allocated ) new_size = 2 * array->allocated;
  if( new_size < 8 ) new_size = 8;

  new_data = libspectrum_realloc( array->data, new_size * array->element_size );

  array->data = new_data;
  array->allocated = new_size;
}
示例#6
0
int
widget_text_finish( widget_finish_state finished )
{
  if( finished == WIDGET_FINISHED_OK ) {

    widget_text_text =
      libspectrum_realloc( widget_text_text, strlen( text ) + 1 );

    strcpy( widget_text_text, text );
  } else {
    free( widget_text_text );
    widget_text_text = NULL;
  }

  return 0;
}