/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/Matrix.c

  • Committer: Gustav Hartvigsson
  • Date: 2016-02-01 14:29:35 UTC
  • mfrom: (121.1.4 simpletypesystem_gc)
  • Revision ID: gustav.hartvigsson@gmail.com-20160201142935-tz7ef63id2g3yfof
* Merged GC branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
s_matrix_new (size_t width,
14
14
              size_t height,
15
15
              SMatrixRowInformation * row_information) {
16
 
  SMatrix * self = malloc (sizeof (SMatrix));
17
 
  self->matrix = calloc (height * width, sizeof (spointer *));
 
16
  SMatrix * self = s_malloc (sizeof (SMatrix));
 
17
  self->matrix = s_calloc (height * width, sizeof (spointer *));
18
18
  
19
19
  self->height = height;
20
20
  self->width = width;
29
29
s_matrix_free (SMatrix * self, sboolean free_data) {
30
30
  if (free_data) {
31
31
    for (int i = 0; i<= self->height * self->width; i++) {
32
 
      free (self->matrix[i]);
 
32
      s_free (self->matrix[i]);
33
33
    }
34
34
  }
35
 
  free (self->matrix);
36
 
  free (self);
 
35
  s_free (self->matrix);
 
36
  s_free (self);
37
37
}
38
38
 
39
39
 
69
69
void
70
70
s_matrix_set (SMatrix * self, size_t x, size_t y, spointer data) {
71
71
  if (x >= self->height) {
72
 
    spointer new_matrix = realloc (self->matrix,
 
72
    spointer new_matrix = s_realloc (self->matrix,
73
73
                                   sizeof (spointer) *
74
74
                                   round_up (x + self->width, self->width));
75
75
    if (new_matrix) {
90
90
s_matrix_get_tuple (SMatrix * self, size_t x) {
91
91
  spointer * tuple = NULL;
92
92
  if ((x < self->height) && (x < self->last_tuple)){
93
 
    tuple = calloc (self->width, sizeof (spointer));
 
93
    tuple = s_calloc (self->width, sizeof (spointer));
94
94
    for (int i = 0; i <= self->width; i++) {
95
95
      tuple[i] = s_matrix_get (self, x, i);
96
96
    }
113
113
  for (size_t i = 0; i <= self->width; i++) {
114
114
    s_matrix_set (self, new_x_pos, i, tuple[i]);
115
115
  }
116
 
  free (tuple);
 
116
  s_free (tuple);
117
117
  self->last_tuple = new_x_pos;
118
118
}
119
119
 
123
123
  for (size_t i = 0; i <= self->height; i++) {
124
124
    spointer * tuple = s_matrix_get_tuple (self, i);
125
125
    callback (self, tuple, data);
126
 
    free (tuple);
 
126
    s_free (tuple);
127
127
  }
128
128
}