| 
									
										
										
										
											2012-11-27 13:45:28 +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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2012 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file blender/python/bmesh/bmesh_py_ops_call.c
 | 
					
						
							|  |  |  |  *  \ingroup pybmesh | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file provides __call__ aka BPy_BMO_call for | 
					
						
							| 
									
										
										
										
											2015-09-14 02:21:15 +10:00
										 |  |  |  * the bmesh operator and has been given its own file | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  |  * because argument conversion is involved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../mathutils/mathutils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh_py_ops_call.h"  /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh_py_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | #include "../generic/python_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:51:27 +02:00
										 |  |  | BLI_STATIC_ASSERT(sizeof(PyC_FlagSet) == sizeof(BMO_FlagSet), "size mismatch"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | static int bpy_bm_op_as_py_error(BMesh *bm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (BMO_error_occurred(bm)) { | 
					
						
							| 
									
										
										
										
											2013-02-13 04:55:05 +00:00
										 |  |  | 		/* note: we could have multiple errors */ | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 		const char *errmsg; | 
					
						
							|  |  |  | 		if (BMO_error_get(bm, &errmsg, NULL)) { | 
					
						
							|  |  |  | 			PyErr_Format(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			             "bmesh operator: %.200s", | 
					
						
							|  |  |  | 			             errmsg); | 
					
						
							| 
									
										
										
										
											2013-02-13 04:55:05 +00:00
										 |  |  | 			BMO_error_clear(bm); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \brief Utility function to check BMVert/BMEdge/BMFace's | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param value | 
					
						
							|  |  |  |  * \param bm Check the \a value against this. | 
					
						
							|  |  |  |  * \param htype Test \a value matches this type. | 
					
						
							|  |  |  |  * \param descr Description text. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-04-25 20:15:20 +10:00
										 |  |  | static int bpy_slot_from_py_elem_check( | 
					
						
							|  |  |  |         BPy_BMElem *value, BMesh *bm, const char htype, | 
					
						
							|  |  |  |         /* for error messages */ | 
					
						
							|  |  |  |         const char *opname, const char *slot_name, const char *descr) | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!BPy_BMElem_Check(value) || | 
					
						
							|  |  |  | 	    !(value->ele->head.htype & htype)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s, expected a %.200s not *.200s", | 
					
						
							|  |  |  | 		             opname, slot_name, descr, | 
					
						
							|  |  |  | 		             BPy_BMElem_StringFromHType(htype), | 
					
						
							|  |  |  | 		             Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (value->bm == NULL) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s invalidated element", | 
					
						
							|  |  |  | 		             opname, slot_name, descr); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (value->bm != bm) {  /* we may want to make this check optional by setting 'bm' to NULL */ | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s invalidated element", | 
					
						
							|  |  |  | 		             opname, slot_name, descr); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * \brief Utility function to check BMVertSeq/BMEdgeSeq/BMFaceSeq's | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param value Caller must check its a BMeshSeq | 
					
						
							|  |  |  |  * \param bm Check the \a value against this. | 
					
						
							|  |  |  |  * \param htype_py The type(s) of \a value. | 
					
						
							|  |  |  |  * \param htype_bmo The type(s) supported by the target slot. | 
					
						
							|  |  |  |  * \param descr Description text. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-04-25 20:15:20 +10:00
										 |  |  | static int bpy_slot_from_py_elemseq_check( | 
					
						
							|  |  |  |         BPy_BMGeneric *value, BMesh *bm, | 
					
						
							|  |  |  |         const char htype_py, const char htype_bmo, | 
					
						
							|  |  |  |         /* for error messages */ | 
					
						
							|  |  |  |         const char *opname, const char *slot_name, const char *descr) | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (value->bm == NULL) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s, invalidated sequence", | 
					
						
							|  |  |  | 		             opname, slot_name, descr); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (value->bm != bm) {  /* we may want to make this check optional by setting 'bm' to NULL */ | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s, invalidated sequence", | 
					
						
							|  |  |  | 		             opname, slot_name, descr); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if ((htype_py & htype_bmo) == 0) { | 
					
						
							|  |  |  | 		char str_bmo[32]; | 
					
						
							|  |  |  | 		char str_py[32]; | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "%.200s: keyword \"%.200s\" %.200s, expected " | 
					
						
							|  |  |  | 		             "a sequence of %.200s not %.200s", | 
					
						
							|  |  |  | 		             opname, slot_name, descr, | 
					
						
							|  |  |  | 		             BPy_BMElem_StringFromHType_ex(htype_bmo, str_bmo), | 
					
						
							|  |  |  | 		             BPy_BMElem_StringFromHType_ex(htype_py,  str_py)); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  |  * Use for giving py args to an operator. | 
					
						
							| 
									
										
										
										
											2012-11-27 13:45:28 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-04-25 20:15:20 +10:00
										 |  |  | static int bpy_slot_from_py( | 
					
						
							|  |  |  |         BMesh *bm, BMOperator *bmop, BMOpSlot *slot, PyObject *value, | 
					
						
							|  |  |  |         /* the are just for exception messages */ | 
					
						
							|  |  |  |         const char *opname, const char *slot_name) | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 	switch (slot->slot_type) { | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_BOOL: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 			const int param = PyC_Long_AsBool(value); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 			if (param == -1) { | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 				             "%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s", | 
					
						
							|  |  |  | 				             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				BMO_SLOT_AS_BOOL(slot) = param; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_INT: | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-27 15:51:27 +02:00
										 |  |  | 			if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) { | 
					
						
							|  |  |  | 				int enum_val = -1; | 
					
						
							|  |  |  | 				PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_flags; | 
					
						
							|  |  |  | 				const char *enum_str = _PyUnicode_AsString(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (enum_str == NULL) { | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 					             "%.200s: keyword \"%.200s\" expected a string, not %.200s", | 
					
						
							|  |  |  | 					             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (PyC_FlagSet_ValueFromID(items, enum_str, &enum_val, slot_name) == -1) { | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				BMO_SLOT_AS_INT(slot) = enum_val; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) { | 
					
						
							|  |  |  | 				int flag = 0; | 
					
						
							|  |  |  | 				PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_flags; | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:51:27 +02:00
										 |  |  | 				if (PyC_FlagSet_ToBitfield(items, value, &flag, slot_name) == -1) { | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				BMO_SLOT_AS_INT(slot) = flag; | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2018-08-27 15:51:27 +02:00
										 |  |  | 				const int param = PyC_Long_AsI32(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (param == -1 && PyErr_Occurred()) { | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 					             "%.200s: keyword \"%.200s\" expected an int, not %.200s", | 
					
						
							|  |  |  | 					             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					BMO_SLOT_AS_INT(slot) = param; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_FLT: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			float param = PyFloat_AsDouble(value); | 
					
						
							|  |  |  | 			if (param == -1 && PyErr_Occurred()) { | 
					
						
							|  |  |  | 				PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 				             "%.200s: keyword \"%.200s\" expected a float, not %.200s", | 
					
						
							|  |  |  | 				             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				BMO_SLOT_AS_FLOAT(slot) = param; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_MAT: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
 | 
					
						
							|  |  |  | 			 * not the caller! */ | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 			MatrixObject *pymat; | 
					
						
							|  |  |  | 			if (!Matrix_ParseAny(value, &pymat)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-09-04 14:23:39 +10:00
										 |  |  | 			const ushort size = pymat->num_col; | 
					
						
							|  |  |  | 			if ((size != pymat->num_row) || (!ELEM(size, 3, 4))) { | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 				             "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix", | 
					
						
							|  |  |  | 				             opname, slot_name); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 			BMO_slot_mat_set(bmop, bmop->slots_in, slot_name, pymat->matrix, size); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_VEC: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* passing slot name here is a bit non-descriptive */ | 
					
						
							|  |  |  | 			if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) { | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_ELEMENT_BUF: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 				if (bpy_slot_from_py_elem_check((BPy_BMElem *)value, bm, (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							|  |  |  | 				                                opname, slot_name, "single element") == -1) | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				BMO_slot_buffer_from_single(bmop, slot, &((BPy_BMElem *)value)->ele->head); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				/* there are many ways we could interpret arguments, for now...
 | 
					
						
							|  |  |  | 				 * - verts/edges/faces from the mesh direct, | 
					
						
							|  |  |  | 				 *   this way the operator takes every item. | 
					
						
							|  |  |  | 				 * - `TODO` a plain python sequence (list) of elements. | 
					
						
							|  |  |  | 				 * - `TODO`  an iterator. eg. | 
					
						
							|  |  |  | 				 *   face.verts | 
					
						
							|  |  |  | 				 * - `TODO`  (type, flag) pair, eg. | 
					
						
							|  |  |  | 				 *   ('VERT', {'TAG'}) | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (BPy_BMVertSeq_Check(value)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm, | 
					
						
							|  |  |  | 					                                   BM_VERT, (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							|  |  |  | 					                                   opname, slot_name, "element buffer") == -1) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_VERT); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (BPy_BMEdgeSeq_Check(value)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm, | 
					
						
							|  |  |  | 					                                   BM_EDGE, (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							|  |  |  | 					                                   opname, slot_name, "element buffer") == -1) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_EDGE); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (BPy_BMFaceSeq_Check(value)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm, | 
					
						
							|  |  |  | 					                                   BM_FACE, (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							|  |  |  | 					                                   opname, slot_name, "element buffer") == -1) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_FACE); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				else if (BPy_BMElemSeq_Check(value)) { | 
					
						
							|  |  |  | 					BMIter iter; | 
					
						
							|  |  |  | 					BMHeader *ele; | 
					
						
							|  |  |  | 					int tot; | 
					
						
							|  |  |  | 					unsigned int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm, | 
					
						
							|  |  |  | 					                                   bm_iter_itype_htype_map[((BPy_BMElemSeq *)value)->itype], | 
					
						
							|  |  |  | 					                                   (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							|  |  |  | 					                                   opname, slot_name, "element buffer") == -1) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					/* this will loop over all elements which is a shame but
 | 
					
						
							|  |  |  | 					 * we need to know this before alloc */ | 
					
						
							|  |  |  | 					/* calls bpy_bmelemseq_length() */ | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 					tot = Py_TYPE(value)->tp_as_sequence->sq_length(value); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, tot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					i = 0; | 
					
						
							|  |  |  | 					BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) { | 
					
						
							|  |  |  | 						slot->data.buf[i] = ele; | 
					
						
							|  |  |  | 						i++; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/* keep this last */ | 
					
						
							|  |  |  | 				else if (PySequence_Check(value)) { | 
					
						
							|  |  |  | 					BMElem **elem_array = NULL; | 
					
						
							|  |  |  | 					Py_ssize_t elem_array_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX, | 
					
						
							|  |  |  | 					                                       &elem_array_len, (slot->slot_subtype.elem & BM_ALL_NOLOOP), | 
					
						
							| 
									
										
										
										
											2013-01-14 16:42:43 +00:00
										 |  |  | 					                                       true, true, slot_name); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					/* error is set above */ | 
					
						
							|  |  |  | 					if (elem_array == NULL) { | 
					
						
							|  |  |  | 						return -1; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, elem_array_len); | 
					
						
							|  |  |  | 					memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len); | 
					
						
							|  |  |  | 					PyMem_FREE(elem_array); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 					             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 					             "a bmesh sequence, list, (htype, flag) pair, not %.200s", | 
					
						
							|  |  |  | 					             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_MAPPING: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* first check types */ | 
					
						
							|  |  |  | 			if (slot->slot_subtype.map != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) { | 
					
						
							|  |  |  | 				if (!PyDict_Check(value)) { | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 					             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 					             "a dict, not %.200s", | 
					
						
							|  |  |  | 					             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				if (!PySet_Check(value)) { | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 					             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 					             "a set, not %.200s", | 
					
						
							|  |  |  | 					             opname, slot_name, Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			switch (slot->slot_subtype.map) { | 
					
						
							|  |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_ELEM: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (PyDict_Size(value) > 0) { | 
					
						
							|  |  |  | 						PyObject *arg_key, *arg_value; | 
					
						
							|  |  |  | 						Py_ssize_t arg_pos = 0; | 
					
						
							|  |  |  | 						while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid key in dict") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_value, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid value in dict") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							BMO_slot_map_elem_insert(bmop, slot, | 
					
						
							|  |  |  | 							                         ((BPy_BMElem *)arg_key)->ele, ((BPy_BMElem *)arg_value)->ele); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-28 00:47:33 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_FLT: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (PyDict_Size(value) > 0) { | 
					
						
							|  |  |  | 						PyObject *arg_key, *arg_value; | 
					
						
							|  |  |  | 						Py_ssize_t arg_pos = 0; | 
					
						
							|  |  |  | 						while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) { | 
					
						
							|  |  |  | 							float value_f; | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid key in dict") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							value_f = PyFloat_AsDouble(arg_value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (value_f == -1.0f && PyErr_Occurred()) { | 
					
						
							|  |  |  | 								PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 								             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 								             "a dict with float values, not %.200s", | 
					
						
							|  |  |  | 								             opname, slot_name, Py_TYPE(arg_value)->tp_name); | 
					
						
							|  |  |  | 								return -1; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							BMO_slot_map_float_insert(bmop, slot, | 
					
						
							|  |  |  | 							                          ((BPy_BMElem *)arg_key)->ele, value_f); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_INT: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (PyDict_Size(value) > 0) { | 
					
						
							|  |  |  | 						PyObject *arg_key, *arg_value; | 
					
						
							|  |  |  | 						Py_ssize_t arg_pos = 0; | 
					
						
							|  |  |  | 						while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) { | 
					
						
							|  |  |  | 							int value_i; | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid key in dict") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 							value_i = PyC_Long_AsI32(arg_value); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (value_i == -1 && PyErr_Occurred()) { | 
					
						
							|  |  |  | 								PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 								             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 								             "a dict with int values, not %.200s", | 
					
						
							|  |  |  | 								             opname, slot_name, Py_TYPE(arg_value)->tp_name); | 
					
						
							|  |  |  | 								return -1; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							BMO_slot_map_int_insert(bmop, slot, | 
					
						
							|  |  |  | 							                        ((BPy_BMElem *)arg_key)->ele, value_i); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_BOOL: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (PyDict_Size(value) > 0) { | 
					
						
							|  |  |  | 						PyObject *arg_key, *arg_value; | 
					
						
							|  |  |  | 						Py_ssize_t arg_pos = 0; | 
					
						
							|  |  |  | 						while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) { | 
					
						
							|  |  |  | 							int value_i; | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid key in dict") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | 							value_i = PyC_Long_AsI32(arg_value); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (value_i == -1 && PyErr_Occurred()) { | 
					
						
							|  |  |  | 								PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 								             "%.200s: keyword \"%.200s\" expected " | 
					
						
							|  |  |  | 								             "a dict with bool values, not %.200s", | 
					
						
							|  |  |  | 								             opname, slot_name, Py_TYPE(arg_value)->tp_name); | 
					
						
							|  |  |  | 								return -1; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							BMO_slot_map_bool_insert(bmop, slot, | 
					
						
							|  |  |  | 							                         ((BPy_BMElem *)arg_key)->ele, value_i != 0); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (PySet_Size(value) > 0) { | 
					
						
							|  |  |  | 						PyObject *arg_key; | 
					
						
							|  |  |  | 						Py_ssize_t arg_pos = 0; | 
					
						
							|  |  |  | 						Py_ssize_t arg_hash = 0; | 
					
						
							|  |  |  | 						while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 15:26:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP, | 
					
						
							|  |  |  | 							                                opname, slot_name, "invalid key in set") == -1) | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								return -1;  /* error is set in bpy_slot_from_py_elem_check() */ | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							BMO_slot_map_empty_insert(bmop, slot, | 
					
						
							|  |  |  | 							                         ((BPy_BMElem *)arg_key)->ele); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL: | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					/* can't convert from these */ | 
					
						
							|  |  |  | 					PyErr_Format(PyExc_NotImplementedError, | 
					
						
							| 
									
										
										
										
											2014-03-01 14:20:54 +11:00
										 |  |  | 					             "This arguments mapping subtype %d is not supported", slot->slot_subtype.map); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-10-01 22:36:09 +10:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			/* TODO --- many others */ | 
					
						
							|  |  |  | 			PyErr_Format(PyExc_NotImplementedError, | 
					
						
							|  |  |  | 			             "%.200s: keyword \"%.200s\" type %d not working yet!", | 
					
						
							|  |  |  | 			             opname, slot_name, slot->slot_type); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 	/* all is well */ | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-09-03 16:49:08 +02:00
										 |  |  |  * Use for getting return values from an operator that's already executed. | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \note Don't throw any exceptions and should always return a valid (PyObject *). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-01-09 03:30:15 +00:00
										 |  |  | static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyObject *item = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* keep switch in same order as above */ | 
					
						
							|  |  |  | 	switch (slot->slot_type) { | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_BOOL: | 
					
						
							|  |  |  | 			item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_INT: | 
					
						
							|  |  |  | 			item = PyLong_FromLong(BMO_SLOT_AS_INT(slot)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_FLT: | 
					
						
							|  |  |  | 			item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_MAT: | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 			item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, NULL); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_VEC: | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | 			item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, NULL); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_PTR: | 
					
						
							|  |  |  | 			BLI_assert(0);  /* currently we don't have any pointer return values in use */ | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 			item = Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_ELEMENT_BUF: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) { | 
					
						
							|  |  |  | 				BMHeader *ele = BMO_slot_buffer_get_single(slot); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 				item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				const int size = slot->len; | 
					
						
							|  |  |  | 				void **buffer = BMO_SLOT_AS_BUFFER(slot); | 
					
						
							|  |  |  | 				int j; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				item = PyList_New(size); | 
					
						
							|  |  |  | 				for (j = 0; j < size; j++) { | 
					
						
							|  |  |  | 					BMHeader *ele = buffer[j]; | 
					
						
							|  |  |  | 					PyList_SET_ITEM(item, j, BPy_BMElem_CreatePyObject(bm, ele)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		case BMO_OP_SLOT_MAPPING: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			GHash *slot_hash = BMO_SLOT_AS_GHASH(slot); | 
					
						
							|  |  |  | 			GHashIterator hash_iter; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			switch (slot->slot_subtype.map) { | 
					
						
							|  |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_ELEM: | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-02-15 23:36:11 +11:00
										 |  |  | 					item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (slot_hash) { | 
					
						
							|  |  |  | 						GHASH_ITER (hash_iter, slot_hash) { | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); | 
					
						
							|  |  |  | 							void     *ele_val = BLI_ghashIterator_getValue(&hash_iter); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							PyObject *py_key =  BPy_BMElem_CreatePyObject(bm, ele_key); | 
					
						
							|  |  |  | 							PyObject *py_val =  BPy_BMElem_CreatePyObject(bm, ele_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							PyDict_SetItem(item, py_key, py_val); | 
					
						
							|  |  |  | 							Py_DECREF(py_key); | 
					
						
							|  |  |  | 							Py_DECREF(py_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-28 00:47:33 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_FLT: | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-02-15 23:36:11 +11:00
										 |  |  | 					item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (slot_hash) { | 
					
						
							|  |  |  | 						GHASH_ITER (hash_iter, slot_hash) { | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); | 
					
						
							|  |  |  | 							void     *ele_val = BLI_ghashIterator_getValue(&hash_iter); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyObject *py_key =  BPy_BMElem_CreatePyObject(bm,  ele_key); | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							PyObject *py_val =  PyFloat_FromDouble(*(float *)&ele_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyDict_SetItem(item, py_key, py_val); | 
					
						
							|  |  |  | 							Py_DECREF(py_key); | 
					
						
							|  |  |  | 							Py_DECREF(py_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_INT: | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-02-15 23:36:11 +11:00
										 |  |  | 					item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (slot_hash) { | 
					
						
							|  |  |  | 						GHASH_ITER (hash_iter, slot_hash) { | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); | 
					
						
							|  |  |  | 							void     *ele_val = BLI_ghashIterator_getValue(&hash_iter); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyObject *py_key =  BPy_BMElem_CreatePyObject(bm,  ele_key); | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							PyObject *py_val =  PyLong_FromLong(*(int *)&ele_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyDict_SetItem(item, py_key, py_val); | 
					
						
							|  |  |  | 							Py_DECREF(py_key); | 
					
						
							|  |  |  | 							Py_DECREF(py_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_BOOL: | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-02-15 23:36:11 +11:00
										 |  |  | 					item = _PyDict_NewPresized(slot_hash ? BLI_ghash_len(slot_hash) : 0); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					if (slot_hash) { | 
					
						
							|  |  |  | 						GHASH_ITER (hash_iter, slot_hash) { | 
					
						
							| 
									
										
										
										
											2013-09-02 03:13:51 +00:00
										 |  |  | 							BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); | 
					
						
							|  |  |  | 							void     *ele_val = BLI_ghashIterator_getValue(&hash_iter); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyObject *py_key =  BPy_BMElem_CreatePyObject(bm,  ele_key); | 
					
						
							| 
									
										
										
										
											2014-01-03 21:35:29 +11:00
										 |  |  | 							PyObject *py_val =  PyBool_FromLong(*(bool *)&ele_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							PyDict_SetItem(item, py_key, py_val); | 
					
						
							|  |  |  | 							Py_DECREF(py_key); | 
					
						
							|  |  |  | 							Py_DECREF(py_val); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY: | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					item = PySet_New(NULL); | 
					
						
							|  |  |  | 					if (slot_hash) { | 
					
						
							|  |  |  | 						GHASH_ITER (hash_iter, slot_hash) { | 
					
						
							|  |  |  | 							BMHeader       *ele_key = BLI_ghashIterator_getKey(&hash_iter); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							PyObject *py_key =  BPy_BMElem_CreatePyObject(bm,  ele_key); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							PySet_Add(item, py_key); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 							Py_DECREF(py_key); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL: | 
					
						
							|  |  |  | 					/* can't convert from these */ | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 					item = Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	BLI_assert(item != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return item; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * This is the __call__ for bmesh.ops.xxx() | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *ret; | 
					
						
							|  |  |  | 	BPy_BMesh *py_bm; | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((PyTuple_GET_SIZE(args) == 1) && | 
					
						
							|  |  |  | 	    (py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) && | 
					
						
							| 
									
										
										
										
											2014-01-12 22:05:24 +11:00
										 |  |  | 	    (BPy_BMesh_Check(py_bm))) | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		BPY_BM_CHECK_OBJ(py_bm); | 
					
						
							|  |  |  | 		bm = py_bm->bm; | 
					
						
							| 
									
										
										
										
											2013-02-13 04:55:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-01 19:07:11 +10:00
										 |  |  | 		if (bm->use_toolflags == false) { | 
					
						
							|  |  |  | 			PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 			                "bmesh created with 'use_operators=False'"); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-13 04:55:05 +00:00
										 |  |  | 		/* could complain about entering with exceptions... */ | 
					
						
							|  |  |  | 		BMO_error_clear(bm); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2013-05-02 14:03:56 +00:00
										 |  |  | 		                "bmesh operators expect a single BMesh positional argument, all other args must be keywords"); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO - error check this!, though we do the error check on attribute access */ | 
					
						
							|  |  |  | 	/* TODO - make flags optional */ | 
					
						
							|  |  |  | 	BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (kw && PyDict_Size(kw) > 0) { | 
					
						
							|  |  |  | 		/* setup properties, see bpy_rna.c: pyrna_py_to_prop()
 | 
					
						
							|  |  |  | 		 * which shares this logic for parsing properties */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PyObject *key, *value; | 
					
						
							|  |  |  | 		Py_ssize_t pos = 0; | 
					
						
							|  |  |  | 		while (PyDict_Next(kw, &pos, &key, &value)) { | 
					
						
							|  |  |  | 			const char *slot_name = _PyUnicode_AsString(key); | 
					
						
							| 
									
										
										
										
											2012-11-28 15:07:57 +00:00
										 |  |  | 			BMOpSlot *slot; | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-28 15:07:57 +00:00
										 |  |  | 			if (!BMO_slot_exists(bmop.slots_in, slot_name)) { | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 				             "%.200s: keyword \"%.200s\" is invalid for this operator", | 
					
						
							|  |  |  | 				             self->opname, slot_name); | 
					
						
							| 
									
										
										
										
											2012-11-28 15:07:57 +00:00
										 |  |  | 				BMO_op_finish(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-15 10:48:48 +00:00
										 |  |  | 			slot = BMO_slot_get(bmop.slots_in, slot_name); | 
					
						
							| 
									
										
										
										
											2012-11-28 15:07:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			/* now assign the value */ | 
					
						
							|  |  |  | 			if (bpy_slot_from_py(bm, &bmop, slot, value, | 
					
						
							|  |  |  | 			                     self->opname, slot_name) == -1) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2012-11-28 15:07:57 +00:00
										 |  |  | 				BMO_op_finish(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* from here until the end of the function, no returns, just set 'ret' */ | 
					
						
							|  |  |  | 	if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) { | 
					
						
							|  |  |  | 		ret = NULL;  /* exception raised above */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (bmop.slots_out[0].slot_name == NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 		ret = Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* build return value */ | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 		ret = PyDict_New(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (i = 0; bmop.slots_out[i].slot_name; i++) { | 
					
						
							|  |  |  | 			// BMOpDefine *op_def = opdefines[bmop.type];
 | 
					
						
							|  |  |  | 			// BMOSlotType *slot_type = op_def->slot_types_out[i];
 | 
					
						
							|  |  |  | 			BMOpSlot *slot = &bmop.slots_out[i]; | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			PyObject *item; | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-27 14:25:38 +00:00
										 |  |  | 			/* this function doesn't throw exceptions */ | 
					
						
							|  |  |  | 			item = bpy_slot_to_py(bm, slot); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 			if (item == NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 				item = Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 1
 | 
					
						
							|  |  |  | 			/* temp code, strip off '.out' while we keep this convention */ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				char slot_name_strip[MAX_SLOTNAME]; | 
					
						
							| 
									
										
										
										
											2014-04-27 00:21:23 +10:00
										 |  |  | 				const char *ch = strchr(slot->slot_name, '.');  /* can't fail! */ | 
					
						
							| 
									
										
										
										
											2012-11-27 13:54:34 +00:00
										 |  |  | 				int tot = ch - slot->slot_name; | 
					
						
							|  |  |  | 				BLI_assert(ch != NULL); | 
					
						
							|  |  |  | 				memcpy(slot_name_strip, slot->slot_name, tot); | 
					
						
							|  |  |  | 				slot_name_strip[tot] = '\0'; | 
					
						
							|  |  |  | 				PyDict_SetItemString(ret, slot_name_strip, item); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 			PyDict_SetItemString(ret, slot->slot_name, item); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			Py_DECREF(item); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMO_op_finish(bm, &bmop); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } |