|
@@ -78,80 +78,37 @@ PyObject* rpnif_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds)
|
78
|
78
|
|
79
|
79
|
int rpnif_init(PyObject *self, PyObject *args, PyObject *kwds)
|
80
|
80
|
{
|
81
|
|
- PyRPNExpr_t *expr_self;
|
82
|
|
- char *names[] = {"expression", "args_count", "stack_size", NULL};
|
|
81
|
+ /**@todo TODO write the function */
|
|
82
|
+ PyRPNIterExpr_t *expr_self;
|
|
83
|
+ char *names[] = {"pos_flag", "res_flag", "lim", "value", "stack_size", NULL};
|
|
84
|
+ unsigned short pos_flag, res_flag, stack_size;
|
|
85
|
+ PyObject *lim, *value;
|
83
|
86
|
char err_str[256];
|
84
|
|
- const char *expr;
|
85
|
|
- long long int args_count, stack_size;
|
86
|
87
|
|
87
|
|
- expr_self = (PyRPNExpr_t*)self;
|
|
88
|
+ expr_self = (PyRPNIterExpr_t*)self;
|
88
|
89
|
|
89
|
90
|
stack_size = 16;
|
90
|
|
- expr_self->rpn = NULL;
|
91
|
|
-
|
92
|
|
- if(!PyArg_ParseTupleAndKeywords(args, kwds, "sL|L:RPNExpr.__init__", names, &expr,
|
93
|
|
- &args_count, &stack_size))
|
94
|
|
- {
|
95
|
|
- return -1;
|
96
|
|
- }
|
97
|
|
-
|
98
|
|
- if(strlen(expr) == 0)
|
99
|
|
- {
|
100
|
|
- PyErr_SetString(PyExc_ValueError,
|
101
|
|
- "RpnExpr.__init__() expect expression argument to be not empty");
|
102
|
|
- return -1;
|
103
|
|
- }
|
|
91
|
+ value = lim = NULL;
|
|
92
|
+ expr_self->rif = NULL;
|
104
|
93
|
|
105
|
|
- if(args_count < 0 || args_count > 255)
|
|
94
|
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "HHO|OH:RPNIterExpr.__init__", names,
|
|
95
|
+ &pos_flag, &res_flag, lim, value, &stack_size))
|
106
|
96
|
{
|
107
|
|
- snprintf(err_str, 128,
|
108
|
|
- "Argument count should be in [4..255] but %lld given",
|
109
|
|
- args_count);
|
110
|
|
- PyErr_SetString(PyExc_ValueError, err_str);
|
111
|
97
|
return -1;
|
112
|
98
|
}
|
113
|
99
|
|
|
100
|
+ // Args checking
|
114
|
101
|
if(stack_size < 4 || stack_size > 255)
|
115
|
102
|
{
|
116
|
103
|
snprintf(err_str, 128,
|
117
|
|
- "Stack size should be in [0..255] but %lld given",
|
|
104
|
+ "Stack size should be in [0..255] but %u given",
|
118
|
105
|
stack_size);
|
119
|
106
|
PyErr_SetString(PyExc_ValueError, err_str);
|
120
|
107
|
return -1;
|
121
|
108
|
}
|
|
109
|
+ //Check & convert lim
|
122
|
110
|
|
123
|
|
- expr_self->rpn = malloc(sizeof(rpn_expr_t));
|
124
|
|
- if(!expr_self->rpn)
|
125
|
|
- {
|
126
|
|
- snprintf(err_str, 256,
|
127
|
|
- "Expression memory allocation error : %s",
|
128
|
|
- strerror(errno));
|
129
|
|
- }
|
130
|
|
- bzero(expr_self->rpn, sizeof(rpn_expr_t));
|
131
|
|
-
|
132
|
|
- if(rpn_expr_init(expr_self->rpn, stack_size, args_count) < 0)
|
133
|
|
- {
|
134
|
|
- snprintf(err_str, 256,
|
135
|
|
- "Expression init error : %s",
|
136
|
|
- expr_self->rpn->err_reason);
|
137
|
|
- PyErr_SetString(PyExc_ValueError, err_str);
|
138
|
|
- return -1;
|
139
|
|
- }
|
140
|
|
-
|
141
|
|
- expr_self->args = malloc(sizeof(rpn_value_t) * args_count);
|
142
|
|
- if(!expr_self->args)
|
143
|
|
- {
|
144
|
|
- snprintf(err_str, 256,
|
145
|
|
- "Error allocating arguments memory : %s",
|
146
|
|
- strerror(errno));
|
147
|
|
- return -1;
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- if(rpn_expr_compile(expr_self->rpn, expr))
|
151
|
|
- {
|
152
|
|
- PyErr_SetString(PyExc_ValueError, expr_self->rpn->err_reason);
|
153
|
|
- return -1;
|
154
|
|
- }
|
|
111
|
+ //Check & convert value
|
155
|
112
|
|
156
|
113
|
return 0;
|
157
|
114
|
}
|
|
@@ -170,21 +127,25 @@ void rpnif_del(PyObject *self)
|
170
|
127
|
|
171
|
128
|
PyObject* rpnif_str(PyObject *self)
|
172
|
129
|
{
|
|
130
|
+ /**@todo TODO write the function */
|
173
|
131
|
Py_RETURN_NONE;
|
174
|
132
|
}
|
175
|
133
|
|
176
|
134
|
PyObject* rpnif_repr(PyObject *self)
|
177
|
135
|
{
|
|
136
|
+ /**@todo TODO write the function */
|
178
|
137
|
Py_RETURN_NONE;
|
179
|
138
|
}
|
180
|
139
|
|
181
|
140
|
PyObject* rpnif_getstate(PyObject *self, PyObject *noargs)
|
182
|
141
|
{
|
|
142
|
+ /**@todo TODO write the function */
|
183
|
143
|
Py_RETURN_NONE;
|
184
|
144
|
}
|
185
|
145
|
|
186
|
146
|
PyObject* rpnif_setstate(PyObject *self, PyObject *state_bytes)
|
187
|
147
|
{
|
|
148
|
+ /**@todo TODO write the function */
|
188
|
149
|
Py_RETURN_NONE;
|
189
|
150
|
}
|
190
|
151
|
|