Browse Source

Bugfix + adds python_if.* files

Yann Weber 4 years ago
parent
commit
e64bad9cf3
4 changed files with 132 additions and 0 deletions
  1. 8
    0
      python_if.c
  2. 81
    0
      python_if.h
  3. 40
    0
      rpn_ifs.c
  4. 3
    0
      rpn_ifs.h

+ 8
- 0
python_if.c View File

@@ -0,0 +1,8 @@
1
+#include "python_if.h"
2
+
3
+int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds)
4
+{
5
+	/**@todo Need a C function returning RPNExpr (or must take
6
+	RPNExpr as arguments... */
7
+}
8
+

+ 81
- 0
python_if.h View File

@@ -0,0 +1,81 @@
1
+/*
2
+ * Copyright (C) 2020 Weber Yann
3
+ * 
4
+ * This file is part of pyrpn.
5
+ * 
6
+ * pyrpn is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * any later version.
10
+ * 
11
+ * pyrpn is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ * 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with pyrpn.  If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+#ifndef _PYTHON_IF_H__
20
+#define _PYTHON_IF_H__
21
+
22
+#include "config.h"
23
+
24
+#include <errno.h>
25
+
26
+#define PY_SSIZE_T_CLEAN
27
+#include <Python.h>
28
+#include "structmember.h"
29
+
30
+#include "rpn_if.h"
31
+#incdlue "pyton_rpnexpr.h"
32
+
33
+/**@defgroup python_if RPN Iterated Function Python class
34
+ * @ingroup python_module
35
+ * @brief Exposed Python class : RPNIterExpr
36
+ *
37
+ * Iterated expression are composed of RPN expressions, they are able to
38
+ * iterate taking their parameters from a memory array and setting back values
39
+ * in it on each iteration.
40
+ *
41
+ * @see ifs_if
42
+ */
43
+
44
+/**@file python_if.h
45
+ * @brief Python RPNIterExpr type headers
46
+ * @ingroup python_if
47
+ *
48
+ * This file is the header of the RPNIterExpr Python class
49
+ */
50
+
51
+/**@brief RPNIterExpr Python class methods list
52
+ * @ingroup python_if */
53
+extern PyMethodDef RPNIterExpr_methods[];
54
+/**@brief RPNIterExpr Python class members list
55
+ * @ingroup python_if */
56
+extern PyMemberDef RPNIterExpr_members[];
57
+/**@brief RPNIterExpr Python class type definition
58
+ * @ingroup python_if */
59
+extern PyTypeObject RPNIterExprType;
60
+
61
+/**@brief Structure holding RPNIterExpr objects
62
+ * @ingroup python_if */
63
+typedef struct
64
+{
65
+	PyObject_VAR_HEAD;
66
+	
67
+	/**@brief Pointer on @ref rpn_if_s */
68
+	rpn_if_t *rif;
69
+} PyRPNIterExpr_t;
70
+
71
+/**@brief RpnIterExpr constructor
72
+ * @param self New RPNExpr instance
73
+ * @param args Positional arguments list
74
+ * @param kwds Keywords arguments dict
75
+ * @return 0 if no error else -1
76
+ * @ingroup python_if
77
+ */
78
+int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds);
79
+
80
+#endif
81
+

+ 40
- 0
rpn_ifs.c View File

@@ -107,3 +107,43 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight)
107 107
 	return res;
108 108
 }
109 109
 
110
+int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx)
111
+{
112
+	size_t sz_mv;
113
+#ifdef DEBUG
114
+	if(if_idx >= rifs->if_sz)
115
+	{
116
+		dprintf(2, "Error, wrong IF index given when attempt to delete from IFS");
117
+		errno = EINVAL;
118
+		return -1;
119
+	}
120
+#endif
121
+
122
+	rpn_if_free(rifs->rpn_if[rifs->if_sz - 1]);
123
+	if(if_idx < rifs->if_sz - 1)
124
+	{
125
+		sz_mv = rifs->if_sz - if_idx;
126
+		memmove(rifs->rpn_if + if_idx, rifs->rpn_if + if_idx + 1, sz_mv);
127
+		memmove(rifs->weight + if_idx, rifs->weight + if_idx + 1, sz_mv);
128
+	}
129
+
130
+	rifs->if_sz--;
131
+	rifs->flat_sz -= rifs->params.rpn_sz;
132
+	return 0;
133
+}
134
+
135
+int rpn_ifs_weight_update(rpn_ifs_t *rifs)
136
+{
137
+	return 1;
138
+}
139
+
140
+rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)
141
+{
142
+	return NULL;
143
+}
144
+
145
+int rpn_ifs_step(rpn_ifs_t *rifs)
146
+{
147
+	return 1;
148
+}
149
+

+ 3
- 0
rpn_ifs.h View File

@@ -21,6 +21,8 @@
21 21
 
22 22
 #include "config.h"
23 23
 
24
+#include <string.h>
25
+
24 26
 #include "rpn_jit.h"
25 27
 #include "rpn_if.h"
26 28
 
@@ -101,6 +103,7 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight);
101 103
  * @param rifs The iterated function system
102 104
  * @param if_idx The iterated function index in the system
103 105
  * @return -1 if error else 0
106
+ * @note Update sizes but do not calls realloc
104 107
  */
105 108
 int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
106 109
 

Loading…
Cancel
Save