| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pygen | 
					
						
							|  |  |  |  * \brief header-only utilities | 
					
						
							|  |  |  |  * \note light addition to Python.h, use py_capi_utils.h for larger features. | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef __PYTHON_UTILDEFINES_H__
 | 
					
						
							|  |  |  | #define __PYTHON_UTILDEFINES_H__
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define PyTuple_SET_ITEMS(op_arg, ...) \
 | 
					
						
							|  |  |  | { \ | 
					
						
							|  |  |  | 	PyTupleObject *op = (PyTupleObject *)op_arg; \ | 
					
						
							|  |  |  | 	PyObject **ob_items = op->ob_item; \ | 
					
						
							|  |  |  | 	CHECK_TYPE_ANY(op_arg, PyObject *, PyTupleObject *); \ | 
					
						
							| 
									
										
										
										
											2017-08-23 20:04:26 +10:00
										 |  |  | 	BLI_assert(VA_NARGS_COUNT(__VA_ARGS__) == PyTuple_GET_SIZE(op)); \ | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 	ARRAY_SET_ITEMS(ob_items, __VA_ARGS__); \ | 
					
						
							|  |  |  | } (void)0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* wrap Py_INCREF & return the result,
 | 
					
						
							|  |  |  |  * use sparingly to avoid comma operator or temp var assignment */ | 
					
						
							| 
									
										
										
										
											2017-08-20 21:14:33 +10:00
										 |  |  | Py_LOCAL_INLINE(PyObject *)Py_INCREF_RET(PyObject *op) { Py_INCREF(op); return op; } | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 17:39:47 +11:00
										 |  |  | /* append & transfer ownership to the list, avoids inline Py_DECREF all over (which is quite a large macro) */ | 
					
						
							| 
									
										
										
										
											2017-08-20 21:14:33 +10:00
										 |  |  | Py_LOCAL_INLINE(int) PyList_APPEND(PyObject *op, PyObject *v) | 
					
						
							| 
									
										
										
										
											2015-01-06 17:39:47 +11:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret = PyList_Append(op, v); | 
					
						
							|  |  |  | 	Py_DecRef(v); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  /* __PYTHON_UTILDEFINES_H__ */
 |