/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 src/baseobject.c

  • Committer: Gustav Hartvigsson
  • Date: 2013-09-04 16:49:28 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130904164928-q0clz7tyrshgnfuv
Fixed a few problems.
Added a test. (it should core-dump, no werries!).

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
}
87
87
 
88
88
/**
 
89
 * This fuction is used to set the get_refcount method.
 
90
 * 
 
91
 * DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
 
92
 */
 
93
void s_base_object_set_get_refcount_method (SBaseObjectInstance * self, int (* method)(SBaseObjectInstance *)) {
 
94
  SBaseObjectClass * klass = s_base_object_get_class (self);
 
95
  klass->get_refcount = method;
 
96
}
 
97
 
 
98
/**
89
99
 * This fuction is used to set the to_string method.
90
100
 */
91
101
void s_base_object_set_to_string_method (SBaseObjectInstance * self, char * (*method)(SBaseObjectInstance *)) {
155
165
 * It returns the current reference count.
156
166
 */
157
167
int s_base_object_unref (SBaseObjectInstance * self) {
158
 
  return self->base_class->unref (self);
 
168
  unsigned int ret = self->base_class->unref (self);
 
169
  return ret;
159
170
}
160
171
 
161
172
/**
164
175
 * Returns the current reference count.
165
176
 */
166
177
int s_base_object_ref (SBaseObjectInstance * self) {
167
 
  return self->base_class->ref (self);
 
178
  unsigned int ret = self->base_class->ref (self);
 
179
  return ret;
168
180
}
169
181
 
170
182
/**
171
183
 * This function returns the current reference count without chaning it.
172
184
 */
173
185
int s_base_object_get_refcount (SBaseObjectInstance * self) {
174
 
  return self->base_class->get_refcount (self);
 
186
  fprintf(stdout, "Moo!\n");
 
187
  unsigned int ret = self->base_class->get_refcount (self);
 
188
  return ret;
175
189
}
176
190
 
177
191
/**
181
195
 * Note: The string that is returned must be freed.
182
196
 */
183
197
char * s_base_object_to_string (SBaseObjectInstance * self) {
184
 
  return self->base_class->to_string (self);
 
198
  char * ret = self->base_class->to_string (self);
 
199
  return ret;
185
200
}
186
201
 
187
202
/* -----------------
204
219
 
205
220
int method_base_unref (SBaseObjectInstance * self) {
206
221
  self->refcount = self->refcount - 1;
207
 
  if (self->refcount <= 0) {
 
222
  if (self->refcount == 0) {
208
223
    self->base_class->deinitize (self);
209
224
    return 0;
210
225
  }
212
227
}
213
228
 
214
229
int method_base_get_refcount (SBaseObjectInstance * self) {
 
230
    fprintf(stdout, "Moo Moo!\n");
215
231
  return self->refcount;
216
232
}
217
233