bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
1 |
/*
|
2 |
Copyright (c) 2013-2014 Gustav Hartvigsson
|
|
3 |
||
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
|
6 |
in the Software without restriction, including without limitation the rights
|
|
7 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 |
copies of the Software, and to permit persons to whom the Software is
|
|
9 |
furnished to do so, subject to the following conditions:
|
|
10 |
||
11 |
The above copyright notice and this permission notice shall be included in
|
|
12 |
all copies or substantial portions of the Software.
|
|
13 |
||
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 |
THE SOFTWARE.
|
|
21 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
22 |
|
23 |
#include "Error.h" |
|
24 |
#include <stdlib.h> |
|
25 |
#include <string.h> |
|
26 |
#include <stdio.h> |
|
|
22
by Gustav Hartvigsson
* Made code compile |
27 |
#include <assert.h> |
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
28 |
#include "utils.h" |
29 |
||
30 |
||
31 |
struct SErrorPrivate { |
|
|
81
by Gustav Hartvigsson
* Re arranged members of structs to prevent struct fragmentation and padding. |
32 |
schar * message; |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
33 |
SErrorType error_type; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
34 |
};
|
35 |
||
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
36 |
schar * |
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
37 |
error_to_string_method (SObject * self); |
38 |
void
|
|
39 |
error_free_method (SError * self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
40 |
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
41 |
SError * |
42 |
s_error_new (SErrorType error, char * message) { |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
43 |
SError * self = malloc (sizeof (SError)); |
44 |
SErrorClass * klass = malloc (sizeof (SErrorClass)); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
45 |
self->priv = malloc (sizeof (SErrorPrivate)); |
46 |
|
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
47 |
s_object_set_class (S_OBJECT (self), S_OBJECT_CLASS (klass)); |
48 |
s_object_initialize (S_OBJECT (self), "Error"); |
|
49 |
s_object_set_to_string_method (S_OBJECT (self), error_to_string_method); |
|
50 |
s_object_set_free_method (S_OBJECT (self), METHOD(error_free_method)); |
|
51 |
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
52 |
self->priv->message = s_string_new (message); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
53 |
self->priv->error_type = error; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
54 |
return self; |
55 |
}
|
|
56 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
57 |
void
|
58 |
s_error_free (SError * self) { |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
59 |
s_object_free (S_OBJECT (self)); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
60 |
}
|
61 |
||
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
62 |
schar * |
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
63 |
error_to_string_method (SObject * obj) { |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
64 |
SError * self = S_ERROR (obj); |
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
65 |
schar * ret_val = NULL; |
66 |
schar * error_type_str = NULL; |
|
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
67 |
error_type_str = s_string_new (SErrorTypeName[self->priv->error_type]); |
68 |
|
|
69 |
ret_val = s_string_new_fmt ("Error: %s, Message: %s", error_type_str, self->priv->message); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
70 |
free (error_type_str); |
71 |
return ret_val; |
|
72 |
}
|
|
73 |
||
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
74 |
void
|
75 |
error_free_method (SError * self) { |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
76 |
free (self->priv->message); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
77 |
free (self->priv); |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
78 |
SErrorClass * klass = S_ERROR_CLASS (s_object_get_class (S_OBJECT (self))); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
79 |
free (klass); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
80 |
free (self); |
81 |
}
|
|
82 |
||
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
83 |
schar * |
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
84 |
s_error_get_name (SErrorType k) { |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
85 |
return SErrorTypeName[k]; |
86 |
}
|
|
87 |