Browse Source

Commenting libs/cturmit.h

Yann Weber 6 years ago
parent
commit
eb3feb7705
2 changed files with 75 additions and 45 deletions
  1. 1
    7
      libs/cturmit.c
  2. 74
    38
      libs/cturmit.h

+ 1
- 7
libs/cturmit.c View File

@@ -277,18 +277,12 @@ PyObject* CTurmit_call(PyObject *func, PyObject *args, PyObject *kwds)
277 277
 				err_msg);
278 278
 			Py_RETURN_NONE;
279 279
 		}
280
-                Py_DECREF(arg);
280
+		Py_DECREF(arg);
281 281
 	}
282 282
 	res = turmit_exec(self->turmit, exec_args);
283 283
 	return PyLong_FromUnsignedLongLong(res);
284 284
 }
285 285
 
286
-Py_ssize_t
287
-CTurmit_len(CTurmit *self)
288
-{
289
-	return self->len;
290
-}
291
-
292 286
 PyObject* CTurmit__push(CTurmit* self, PyObject *args)
293 287
 {
294 288
 	char err_msg[128];

+ 74
- 38
libs/cturmit.h View File

@@ -3,49 +3,33 @@
3 3
 
4 4
 #include "turmit.h"
5 5
 
6
-/**
7
- * @todo search for decref and memory leaks :/
8
- */
9
-
10
-typedef struct
11
-{
12
-	PyObject VAR_HEAD;
13
-	
14
-	Py_ssize_t len;
15
-	turmit_t *turmit;
16
-} CTurmit;
6
+/** @brief Python module containing CTurmit python class */
17 7
 
18 8
 static PyModuleDef cturmitmodule = {
19 9
 	PyModuleDef_HEAD_INIT,
20 10
 	"cturmit",
21
-	"Module that implements turmits in C",
11
+	"Module implementing turmits in C",
22 12
 	-1,
23 13
 	NULL, NULL, NULL, NULL, NULL
24
-};
14
+}; /*<! Module description */
25 15
 
16
+/*
17
+	class CTurmit definitions
18
+*/
19
+
20
+typedef struct
21
+{
22
+	PyObject VAR_HEAD;
23
+	
24
+	turmit_t *turmit; /*<! Ref to a turmit_t from libs/turmit.h */
25
+} CTurmit; /*<! CTurmit struct */
26 26
 
27 27
 static PyMemberDef CTurmit_members[] = {
28
-	{"len", T_PYSSIZET, offsetof(CTurmit, len), 0,
29
-		"Expression len"},
30
-	/*
31
-	   {"heap_sz", T_PYSSIZET, offsetof(CTurmit, heap_sz), 0,
32
-	   "Item heap counter"},
33
-	 */
34 28
 	{NULL}  /* Sentinel */
35
-};
29
+}; /*<! CTurmit member attribute description */
36 30
 
37
-/*
38
-	Magic methods
39
-*/
40
-Py_ssize_t CTurmit_len(CTurmit*);
41 31
 
42
-static PyMappingMethods CTurmit_asmapping[] = {{
43
-	(void*)CTurmit_len,
44
-}};
45
-
46
-/*
47
-	Other methods
48
-*/
32
+/* Other methods */
49 33
 #define TURMIT_PYOP(NAME) PyObject* CTurmit_op_##NAME(CTurmit* self) {\
50 34
 	turmit_op_##NAME(self->turmit);\
51 35
 	Py_RETURN_NONE;\
@@ -53,8 +37,22 @@ static PyMappingMethods CTurmit_asmapping[] = {{
53 37
 #define TURMIT_PYOPDEF(NAME) {#NAME, (PyCFunction)CTurmit_op_##NAME, \
54 38
 	METH_NOARGS, NULL}
55 39
 
40
+/** @brief Push a python integer on the CTurmit stack
41
+ * @param self the CTurmit instance
42
+ * @param PyObject* list of *args arguments. Should contain a single integer
43
+ * argument to be pushed on the stack
44
+ * @return Python None
45
+ * @throws TypeError if bad arguments
46
+ */
56 47
 PyObject* CTurmit__push(CTurmit* self, PyObject *args);
48
+/**@brief Pop a python integer from the CTurmit stack
49
+ * @return a python integer returned from PyLong_FromUnsignedLongLong()
50
+ */
57 51
 PyObject* CTurmit__pop(CTurmit* self);
52
+/* Adding method to call turmit_t operations on the stack
53
+ * @param self CTurmit* (see TURMIT_PYOP macro) the method takes no args
54
+ * except self
55
+ */
58 56
 TURMIT_PYOP(mem_sz)
59 57
 TURMIT_PYOP(add)
60 58
 TURMIT_PYOP(sub)
@@ -94,10 +92,28 @@ static PyMethodDef CTurmit_methods[] = {
94 92
 	TURMIT_PYOPDEF(jz),
95 93
 	TURMIT_PYOPDEF(jcmp),
96 94
 	{NULL}  /* Sentinel */
97
-};
95
+}; /*<! Static CTurmit method mapping */
96
+
97
+/*
98
+	Getter & setter definition
99
+
100
+	Note : no setter, this methods are implemented for read only access
101
+	to some @ref turmit_t attributes
102
+*/
98 103
 
104
+/**@brief Returns current value on the top of the stack
105
+ * @note mapped as "shead" attribute
106
+ * @retrun a python int
107
+ */
99 108
 PyObject* CTurmit_get_shead(CTurmit *self, void *ref);
109
+/**@brief Returns current position of the stack head
110
+ * @note mapped as "_cur" attribute
111
+ * @retrun a python int
112
+ */
100 113
 PyObject* CTurmit_get__cur(CTurmit *self, void *ref);
114
+/**@brief Returns a python representation of the stack
115
+ *@return a python list containing python int
116
+ */
101 117
 PyObject* CTurmit_get__stack(CTurmit *self, void *ref);
102 118
 
103 119
 static struct PyGetSetDef CTurmit_getset[] = {
@@ -105,14 +121,27 @@ static struct PyGetSetDef CTurmit_getset[] = {
105 121
 	{"_cur", (getter)CTurmit_get__cur, NULL, NULL, NULL},
106 122
 	{"_stack", (getter)CTurmit_get__stack, NULL, NULL, NULL},
107 123
 	{NULL}  /* Sentinel */
108
-};
109
-
124
+};/*<! Getter mapping */
125
+
126
+/**@brief Utility method that handle CTurmit instanciation copying an existing
127
+ * CTurmit instance
128
+ * @param self Python self CTurmit, the CTurmit to copy
129
+ * @param t the destination CTurmit
130
+ * @return 0 if no error else -1
131
+ * @todo set error to throw python exception if error
132
+ */
110 133
 static int _CTurmit_copy_init(CTurmit *self, CTurmit *t);
111 134
 
135
+/**@brief Python CTurmit.__new__() method
136
+ * @param type Python type
137
+ * @param args Python *args positional args list
138
+ * @param kwds Python **kwargs named args dict
139
+ * @return a CTurmit with memory allocated for the instance
140
+ */
112 141
 static PyObject *
113 142
 CTurmit_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
114 143
 
115
-/**@brief CTurmit __init__ function
144
+/**@brief CTurmit.__init__(self, stack_size=8, max_int=0x10000, prog="", turmit=None) method
116 145
  * @param CTurmit* self
117 146
  * @param PyObject* can contain an interger representing stack size
118 147
  * @param Pyobject* contains kwargs. Can be : stack_size, max_int, prog
@@ -120,14 +149,21 @@ CTurmit_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
120 149
 static int
121 150
 CTurmit_init(CTurmit *self, PyObject *args, PyObject *kwds);
122 151
 
152
+/**@brief CTurmit.__del__(self) method
153
+ * @param self The CTurmit instance
154
+ */
123 155
 void
124 156
 CTurmit_dealloc(CTurmit *self);
125 157
 
158
+/**@brief CTurmit.__call__(self, x, y, r, g, b) method
159
+ * @param args python positional arguments list
160
+ * @param kwds python named arguments dict
161
+ */
126 162
 PyObject* CTurmit_call(PyObject *func, PyObject *args, PyObject *kwds);
127 163
 
128 164
 static PyTypeObject CTurmitType = {
129 165
 	PyVarObject_HEAD_INIT(NULL, 0)
130
-		"cturmit.CTurmit",			/* tp_name */
166
+	"cturmit.CTurmit",				/* tp_name */
131 167
 	sizeof(CTurmit),				/* tp_basicsize */
132 168
 	0,						/* tp_itemsize */
133 169
 	(destructor)CTurmit_dealloc,			/* tp_dealloc */
@@ -138,7 +174,7 @@ static PyTypeObject CTurmitType = {
138 174
 	0,						/* tp_repr */
139 175
 	0,						/* tp_as_number */
140 176
 	0,						/* tp_as_sequence */
141
-	CTurmit_asmapping,				/* tp_as_mapping */
177
+	0,						/* tp_as_mapping */
142 178
 	0,						/* tp_hash  */
143 179
 	CTurmit_call,					/* tp_call */
144 180
 	0,						/* tp_str */
@@ -164,6 +200,6 @@ static PyTypeObject CTurmitType = {
164 200
 	(initproc)CTurmit_init,				/* tp_init */
165 201
 	0,						/* tp_alloc */
166 202
 	CTurmit_new,					/* tp_new */
167
-};
203
+}; /*<! CTurmit object mapping */
168 204
 
169 205
 

Loading…
Cancel
Save