2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-09-01 14:13:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-27 20:10:08 +00:00
|
|
|
|
|
|
|
/** \file blender/python/generic/py_capi_utils.h
|
|
|
|
* \ingroup pygen
|
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __PY_CAPI_UTILS_H__
|
|
|
|
#define __PY_CAPI_UTILS_H__
|
2010-09-01 14:13:48 +00:00
|
|
|
|
2017-08-21 19:03:32 +02:00
|
|
|
#include "BLI_sys_types.h"
|
2017-09-19 20:16:05 +10:00
|
|
|
#include "BLI_utildefines_variadic.h"
|
2017-08-21 19:03:32 +02:00
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
void PyC_ObSpit(const char *name, PyObject *var);
|
2010-09-01 14:13:48 +00:00
|
|
|
void PyC_LineSpit(void);
|
2012-07-19 10:23:25 +00:00
|
|
|
void PyC_StackSpit(void);
|
2010-09-01 14:13:48 +00:00
|
|
|
PyObject * PyC_ExceptionBuffer(void);
|
2015-05-18 09:12:26 +10:00
|
|
|
PyObject * PyC_ExceptionBuffer_Simple(void);
|
2010-09-01 14:13:48 +00:00
|
|
|
PyObject * PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
|
2013-01-04 03:47:37 +00:00
|
|
|
PyObject * PyC_FrozenSetFromStrings(const char **strings);
|
2011-09-15 10:43:55 +00:00
|
|
|
PyObject * PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...);
|
2010-09-01 14:13:48 +00:00
|
|
|
void PyC_FileAndNum(const char **filename, int *lineno);
|
2011-10-20 00:48:00 +00:00
|
|
|
void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */
|
2015-07-29 09:31:53 +10:00
|
|
|
int PyC_AsArray_FAST(
|
|
|
|
void *array, PyObject *value_fast, const Py_ssize_t length,
|
|
|
|
const PyTypeObject *type, const bool is_double, const char *error_prefix);
|
|
|
|
int PyC_AsArray(
|
|
|
|
void *array, PyObject *value, const Py_ssize_t length,
|
|
|
|
const PyTypeObject *type, const bool is_double, const char *error_prefix);
|
2017-08-22 18:02:58 +10:00
|
|
|
|
|
|
|
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len);
|
|
|
|
PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len);
|
|
|
|
PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len);
|
|
|
|
PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len);
|
|
|
|
|
|
|
|
#define PyC_Tuple_Pack_F32(...) \
|
2017-08-23 20:04:26 +10:00
|
|
|
PyC_Tuple_PackArray_F32(((const float []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
|
2017-08-22 18:02:58 +10:00
|
|
|
#define PyC_Tuple_Pack_I32(...) \
|
2017-08-23 20:04:26 +10:00
|
|
|
PyC_Tuple_PackArray_I32(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
|
2017-08-22 18:02:58 +10:00
|
|
|
#define PyC_Tuple_Pack_I32FromBool(...) \
|
2017-08-23 20:04:26 +10:00
|
|
|
PyC_Tuple_PackArray_I32FromBool(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
|
2017-08-22 18:02:58 +10:00
|
|
|
#define PyC_Tuple_Pack_Bool(...) \
|
2017-08-23 20:04:26 +10:00
|
|
|
PyC_Tuple_PackArray_Bool(((const bool []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
|
2017-08-22 18:02:58 +10:00
|
|
|
|
2014-01-06 16:46:00 +11:00
|
|
|
void PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
|
2015-01-06 16:42:22 +11:00
|
|
|
void PyC_List_Fill(PyObject *list, PyObject *value);
|
2010-09-01 14:13:48 +00:00
|
|
|
|
|
|
|
/* follow http://www.python.org/dev/peps/pep-0383/ */
|
2011-10-22 10:49:35 +00:00
|
|
|
PyObject * PyC_UnicodeFromByte(const char *str);
|
|
|
|
PyObject * PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
|
|
|
|
const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
|
2016-07-31 16:52:44 +10:00
|
|
|
const char * PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
|
2010-09-01 14:13:48 +00:00
|
|
|
|
2010-09-18 15:30:03 +00:00
|
|
|
/* name namespace function for bpy & bge */
|
|
|
|
PyObject * PyC_DefaultNameSpace(const char *filename);
|
2010-09-19 14:02:45 +00:00
|
|
|
void PyC_RunQuicky(const char *filepath, int n, ...);
|
2011-02-01 12:37:53 +00:00
|
|
|
|
|
|
|
void PyC_MainModule_Backup(PyObject **main_mod);
|
|
|
|
void PyC_MainModule_Restore(PyObject *main_mod);
|
2011-03-25 04:36:10 +00:00
|
|
|
|
2011-04-18 08:27:50 +00:00
|
|
|
void PyC_SetHomePath(const char *py_path_bundle);
|
|
|
|
|
2013-09-18 23:21:24 +00:00
|
|
|
bool PyC_IsInterpreterActive(void);
|
2011-07-09 17:41:39 +00:00
|
|
|
|
2012-02-20 22:04:29 +00:00
|
|
|
void *PyC_RNA_AsPointer(PyObject *value, const char *type_name);
|
|
|
|
|
2012-02-22 09:15:46 +00:00
|
|
|
/* flag / set --- interchange */
|
|
|
|
typedef struct PyC_FlagSet {
|
|
|
|
int value;
|
|
|
|
const char *identifier;
|
|
|
|
} PyC_FlagSet;
|
|
|
|
|
|
|
|
char *PyC_FlagSet_AsString(PyC_FlagSet *item);
|
2017-03-18 09:39:36 +11:00
|
|
|
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value);
|
|
|
|
int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix);
|
2012-02-22 09:15:46 +00:00
|
|
|
int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix);
|
|
|
|
PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag);
|
|
|
|
|
2017-03-18 09:39:36 +11:00
|
|
|
bool PyC_RunString_AsNumber(const char *expr, const char *filename, double *r_value);
|
2017-03-18 12:19:03 +11:00
|
|
|
bool PyC_RunString_AsString(const char *expr, const char *filename, char **r_value);
|
2014-06-17 16:03:40 +02:00
|
|
|
|
2015-08-03 20:00:16 +10:00
|
|
|
int PyC_ParseBool(PyObject *o, void *p);
|
|
|
|
|
2017-08-20 15:39:08 +10:00
|
|
|
|
|
|
|
/* Integer parsing (with overflow checks), -1 on error. */
|
|
|
|
int PyC_Long_AsBool(PyObject *value);
|
|
|
|
int8_t PyC_Long_AsI8(PyObject *value);
|
|
|
|
int16_t PyC_Long_AsI16(PyObject *value);
|
|
|
|
#if 0 /* inline */
|
|
|
|
int32_t PyC_Long_AsI32(PyObject *value);
|
|
|
|
int64_t PyC_Long_AsI64(PyObject *value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint8_t PyC_Long_AsU8(PyObject *value);
|
|
|
|
uint16_t PyC_Long_AsU16(PyObject *value);
|
|
|
|
uint32_t PyC_Long_AsU32(PyObject *value);
|
|
|
|
#if 0 /* inline */
|
|
|
|
uint64_t PyC_Long_AsU64(PyObject *value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* inline so type signatures match as expected */
|
2017-08-20 21:14:33 +10:00
|
|
|
Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value) { return (int32_t)_PyLong_AsInt(value); }
|
|
|
|
Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLong_AsLongLong(value); }
|
|
|
|
Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); }
|
2017-08-20 15:39:08 +10:00
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#endif /* __PY_CAPI_UTILS_H__ */
|