| 
									
										
										
										
											2011-06-18 08:45:45 +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 ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file blender/python/intern/bpy_intern_string.c
 | 
					
						
							|  |  |  |  *  \ingroup pythonintern | 
					
						
							| 
									
										
										
										
											2011-11-05 08:21:12 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Store python versions of strings frequently used for python lookups | 
					
						
							|  |  |  |  * to avoid converting, creating the hash and freeing every time as | 
					
						
							|  |  |  |  * PyDict_GetItemString and PyObject_GetAttrString do. | 
					
						
							| 
									
										
										
										
											2011-06-18 08:45:45 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-28 05:06:30 +00:00
										 |  |  | #include "bpy_intern_string.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 15:57:14 +10:00
										 |  |  | static PyObject *bpy_intern_str_arr[16]; | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | PyObject *bpy_intern_str___doc__; | 
					
						
							|  |  |  | PyObject *bpy_intern_str___main__; | 
					
						
							|  |  |  | PyObject *bpy_intern_str___module__; | 
					
						
							|  |  |  | PyObject *bpy_intern_str___name__; | 
					
						
							|  |  |  | PyObject *bpy_intern_str___slots__; | 
					
						
							|  |  |  | PyObject *bpy_intern_str_attr; | 
					
						
							| 
									
										
										
										
											2013-02-05 04:41:11 +00:00
										 |  |  | PyObject *bpy_intern_str_bl_property; | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | PyObject *bpy_intern_str_bl_rna; | 
					
						
							| 
									
										
										
										
											2017-06-26 15:57:14 +10:00
										 |  |  | PyObject *bpy_intern_str_bl_target_properties; | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | PyObject *bpy_intern_str_bpy_types; | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | PyObject *bpy_intern_str_frame; | 
					
						
							| 
									
										
										
										
											2011-06-18 08:45:45 +00:00
										 |  |  | PyObject *bpy_intern_str_order; | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | PyObject *bpy_intern_str_properties; | 
					
						
							|  |  |  | PyObject *bpy_intern_str_register; | 
					
						
							| 
									
										
										
										
											2016-07-31 11:22:02 +10:00
										 |  |  | PyObject *bpy_intern_str_self; | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | PyObject *bpy_intern_str_unregister; | 
					
						
							| 
									
										
										
										
											2011-06-18 08:45:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void bpy_intern_string_init(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 	unsigned int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BPY_INTERN_STR(var, str) \
 | 
					
						
							|  |  |  | 	{ var = bpy_intern_str_arr[i++] = PyUnicode_FromString(str); } (void)0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str___main__, "__main__"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str___module__, "__module__"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str___name__, "__name__"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str_attr, "attr"); | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_bl_property, "bl_property"); | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna"); | 
					
						
							| 
									
										
										
										
											2017-06-26 15:57:14 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_bl_target_properties, "bl_target_properties"); | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types"); | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_frame, "frame"); | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_order, "order"); | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_properties, "properties"); | 
					
						
							|  |  |  | 	BPY_INTERN_STR(bpy_intern_str_register, "register"); | 
					
						
							| 
									
										
										
										
											2016-07-31 11:22:02 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_self, "self"); | 
					
						
							| 
									
										
										
										
											2017-06-21 12:43:19 +10:00
										 |  |  | 	BPY_INTERN_STR(bpy_intern_str_unregister, "unregister"); | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | #undef BPY_INTERN_STR
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-17 02:47:57 +10:00
										 |  |  | 	BLI_assert(i == ARRAY_SIZE(bpy_intern_str_arr)); | 
					
						
							| 
									
										
										
										
											2011-06-18 08:45:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void bpy_intern_string_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-17 02:47:57 +10:00
										 |  |  | 	unsigned int i = ARRAY_SIZE(bpy_intern_str_arr); | 
					
						
							| 
									
										
										
										
											2014-01-20 18:03:23 +11:00
										 |  |  | 	while (i--) { | 
					
						
							|  |  |  | 		Py_DECREF(bpy_intern_str_arr[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-18 08:45:45 +00:00
										 |  |  | } |