static int foreach_libblock_id_user_map_callback( void *user_data, ID *self_id, ID **id_p, int UNUSED(cb_flag)) { IDUserMapData *data = user_data; if (*id_p) { if (data->types_bitmap) { if (!id_check_type(*id_p, data->types_bitmap)) { return IDWALK_RET_NOP; } } if ((GS(self_id->name) == ID_OB) && (id_p == (ID **)&((Object *)self_id)->proxy_from)) { /* We skip proxy_from here, since it some internal pointer which is not irrelevant info for py/API level. */ return IDWALK_RET_NOP; } else if ((GS(self_id->name) == ID_KE) && (id_p == (ID **)&((Key *)self_id)->from)) { /* We skip from here, since it some internal pointer which is not irrelevant info for py/API level. */ return IDWALK_RET_NOP; } /* pyrna_struct_hash() uses ptr.data only, * but pyrna_struct_richcmp() uses also ptr.type, * so we need to create a valid PointerRNA here... */ PyObject *key = data->py_id_key_lookup_only; RNA_id_pointer_create(*id_p, &((BPy_StructRNA *)key)->ptr); PyObject *set; if ((set = PyDict_GetItem(data->user_map, key)) == NULL) { /* limit to key's added already */ if (data->is_subset) { return IDWALK_RET_NOP; } /* Cannot use our placeholder key here! */ key = pyrna_id_CreatePyObject(*id_p); set = PySet_New(NULL); PyDict_SetItem(data->user_map, key, set); Py_DECREF(set); Py_DECREF(key); } if (data->py_id_curr == NULL) { data->py_id_curr = pyrna_id_CreatePyObject(data->id_curr); } PySet_Add(set, data->py_id_curr); } return IDWALK_RET_NOP; }
static PyObject *bpy_bmtexpoly_image_get(BPy_BMTexPoly *self, void *UNUSED(closure)) { return pyrna_id_CreatePyObject((ID *)self->data->tpage); }
static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) { #if 0 /* If someone knows how to get a proper 'self' in that case... */ BPy_StructRNA *pyrna = (BPy_StructRNA *)self; Main *bmain = pyrna->ptr.data; #else Main *bmain = G.main; /* XXX Ugly, but should work! */ #endif static const char *kwlist[] = {"subset", "key_types", "value_types", NULL}; PyObject *subset = NULL; PyObject *key_types = NULL; PyObject *val_types = NULL; BLI_bitmap *key_types_bitmap = NULL; BLI_bitmap *val_types_bitmap = NULL; PyObject *ret = NULL; if (!PyArg_ParseTupleAndKeywords( args, kwds, "|O$O!O!:user_map", (char **)kwlist, &subset, &PySet_Type, &key_types, &PySet_Type, &val_types)) { return NULL; } if (key_types) { key_types_bitmap = pyrna_set_to_enum_bitmap( rna_enum_id_type_items, key_types, sizeof(short), true, USHRT_MAX, "key types"); if (key_types_bitmap == NULL) { goto error; } } if (val_types) { val_types_bitmap = pyrna_set_to_enum_bitmap( rna_enum_id_type_items, val_types, sizeof(short), true, USHRT_MAX, "value types"); if (val_types_bitmap == NULL) { goto error; } } IDUserMapData data_cb = {NULL}; if (subset) { PyObject *subset_fast = PySequence_Fast(subset, "user_map"); if (subset_fast == NULL) { goto error; } PyObject **subset_array = PySequence_Fast_ITEMS(subset_fast); Py_ssize_t subset_len = PySequence_Fast_GET_SIZE(subset_fast); data_cb.user_map = _PyDict_NewPresized(subset_len); data_cb.is_subset = true; for (; subset_len; subset_array++, subset_len--) { PyObject *set = PySet_New(NULL); PyDict_SetItem(data_cb.user_map, *subset_array, set); Py_DECREF(set); } Py_DECREF(subset_fast); } else { data_cb.user_map = PyDict_New(); } data_cb.types_bitmap = key_types_bitmap; ListBase *lb_array[MAX_LIBARRAY]; int lb_index; lb_index = set_listbasepointers(bmain, lb_array); while (lb_index--) { if (val_types_bitmap && lb_array[lb_index]->first) { if (!id_check_type(lb_array[lb_index]->first, val_types_bitmap)) { continue; } } for (ID *id = lb_array[lb_index]->first; id; id = id->next) { /* One-time init, ID is just used as placeholder here, we abuse this in iterator callback * to avoid having to rebuild a complete bpyrna object each time for the key searching * (where only ID pointer value is used). */ if (data_cb.py_id_key_lookup_only == NULL) { data_cb.py_id_key_lookup_only = pyrna_id_CreatePyObject(id); } if (!data_cb.is_subset) { PyObject *key = data_cb.py_id_key_lookup_only; PyObject *set; RNA_id_pointer_create(id, &((BPy_StructRNA *)key)->ptr); /* We have to insert the key now, otherwise ID unused would be missing from final dict... */ if ((set = PyDict_GetItem(data_cb.user_map, key)) == NULL) { /* Cannot use our placeholder key here! */ key = pyrna_id_CreatePyObject(id); set = PySet_New(NULL); PyDict_SetItem(data_cb.user_map, key, set); Py_DECREF(set); Py_DECREF(key); } } data_cb.id_curr = id; BKE_library_foreach_ID_link(id, foreach_libblock_id_user_map_callback, &data_cb, IDWALK_NOP); if (data_cb.py_id_curr) { Py_DECREF(data_cb.py_id_curr); data_cb.py_id_curr = NULL; } } } ret = data_cb.user_map; error: Py_XDECREF(data_cb.py_id_key_lookup_only); if (key_types_bitmap) { MEM_freeN(key_types_bitmap); } if (val_types_bitmap) { MEM_freeN(val_types_bitmap); } return ret; }
static PyObject *idprop_py_from_idp_id(IDProperty *prop) { return pyrna_id_CreatePyObject(prop->data.pointer); }