Bugfix + adds python_if.* files
This commit is contained in:
parent
c9afb5d5f2
commit
e64bad9cf3
4 changed files with 132 additions and 0 deletions
8
python_if.c
Normal file
8
python_if.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "python_if.h"
|
||||
|
||||
int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
/**@todo Need a C function returning RPNExpr (or must take
|
||||
RPNExpr as arguments... */
|
||||
}
|
||||
|
||||
81
python_if.h
Normal file
81
python_if.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Weber Yann
|
||||
*
|
||||
* This file is part of pyrpn.
|
||||
*
|
||||
* pyrpn is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* pyrpn is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _PYTHON_IF_H__
|
||||
#define _PYTHON_IF_H__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "structmember.h"
|
||||
|
||||
#include "rpn_if.h"
|
||||
#incdlue "pyton_rpnexpr.h"
|
||||
|
||||
/**@defgroup python_if RPN Iterated Function Python class
|
||||
* @ingroup python_module
|
||||
* @brief Exposed Python class : RPNIterExpr
|
||||
*
|
||||
* Iterated expression are composed of RPN expressions, they are able to
|
||||
* iterate taking their parameters from a memory array and setting back values
|
||||
* in it on each iteration.
|
||||
*
|
||||
* @see ifs_if
|
||||
*/
|
||||
|
||||
/**@file python_if.h
|
||||
* @brief Python RPNIterExpr type headers
|
||||
* @ingroup python_if
|
||||
*
|
||||
* This file is the header of the RPNIterExpr Python class
|
||||
*/
|
||||
|
||||
/**@brief RPNIterExpr Python class methods list
|
||||
* @ingroup python_if */
|
||||
extern PyMethodDef RPNIterExpr_methods[];
|
||||
/**@brief RPNIterExpr Python class members list
|
||||
* @ingroup python_if */
|
||||
extern PyMemberDef RPNIterExpr_members[];
|
||||
/**@brief RPNIterExpr Python class type definition
|
||||
* @ingroup python_if */
|
||||
extern PyTypeObject RPNIterExprType;
|
||||
|
||||
/**@brief Structure holding RPNIterExpr objects
|
||||
* @ingroup python_if */
|
||||
typedef struct
|
||||
{
|
||||
PyObject_VAR_HEAD;
|
||||
|
||||
/**@brief Pointer on @ref rpn_if_s */
|
||||
rpn_if_t *rif;
|
||||
} PyRPNIterExpr_t;
|
||||
|
||||
/**@brief RpnIterExpr constructor
|
||||
* @param self New RPNExpr instance
|
||||
* @param args Positional arguments list
|
||||
* @param kwds Keywords arguments dict
|
||||
* @return 0 if no error else -1
|
||||
* @ingroup python_if
|
||||
*/
|
||||
int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds);
|
||||
|
||||
#endif
|
||||
|
||||
40
rpn_ifs.c
40
rpn_ifs.c
|
|
@ -107,3 +107,43 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight)
|
|||
return res;
|
||||
}
|
||||
|
||||
int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx)
|
||||
{
|
||||
size_t sz_mv;
|
||||
#ifdef DEBUG
|
||||
if(if_idx >= rifs->if_sz)
|
||||
{
|
||||
dprintf(2, "Error, wrong IF index given when attempt to delete from IFS");
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
rpn_if_free(rifs->rpn_if[rifs->if_sz - 1]);
|
||||
if(if_idx < rifs->if_sz - 1)
|
||||
{
|
||||
sz_mv = rifs->if_sz - if_idx;
|
||||
memmove(rifs->rpn_if + if_idx, rifs->rpn_if + if_idx + 1, sz_mv);
|
||||
memmove(rifs->weight + if_idx, rifs->weight + if_idx + 1, sz_mv);
|
||||
}
|
||||
|
||||
rifs->if_sz--;
|
||||
rifs->flat_sz -= rifs->params.rpn_sz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rpn_ifs_weight_update(rpn_ifs_t *rifs)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rpn_ifs_step(rpn_ifs_t *rifs)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "rpn_jit.h"
|
||||
#include "rpn_if.h"
|
||||
|
||||
|
|
@ -101,6 +103,7 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight);
|
|||
* @param rifs The iterated function system
|
||||
* @param if_idx The iterated function index in the system
|
||||
* @return -1 if error else 0
|
||||
* @note Update sizes but do not calls realloc
|
||||
*/
|
||||
int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue