python dict clear只能删除一层,不能够递归删除。
void
PyDict_Clear(PyObject *op)
{
dictobject *mp;
dictentry *ep, *table;
int table_is_malloced;
Py_ssize_t fill;
dictentry small_copy[PyDict_MINSIZE];
#ifdef Py_DEBUG
Py_ssize_t i, n;
#endif if (!PyDict_Check(op))
return;
mp = (dictobject *)op;
#ifdef Py_DEBUG
n = mp->ma_mask + ;
i = ;
#endif table = mp->ma_table;
assert(table != NULL);
table_is_malloced = table != mp->ma_smalltable; /* This is delicate. During the process of clearing the dict,
* decrefs can cause the dict to mutate. To avoid fatal confusion
* (voice of experience), we have to make the dict empty before
* clearing the slots, and never refer to anything via mp->xxx while
* clearing.
*/
fill = mp->ma_fill;
if (table_is_malloced)
EMPTY_TO_MINSIZE(mp); else if (fill > ) {
/* It's a small table with something that needs to be cleared.
* Afraid the only safe way is to copy the dict entries into
* another small table first.
*/
memcpy(small_copy, table, sizeof(small_copy));
table = small_copy;
EMPTY_TO_MINSIZE(mp);
}
/* else it's a small table that's already empty */ /* Now we can finally clear things. If C had refcounts, we could
* assert that the refcount on table is 1 now, i.e. that this function
* has unique access to it, so decref side-effects can't alter it.
*/
for (ep = table; fill > ; ++ep) {
#ifdef Py_DEBUG
assert(i < n);
++i;
#endif
if (ep->me_key) {
--fill;
Py_DECREF(ep->me_key);
Py_XDECREF(ep->me_value);//只有这里处理了,但是如果value是一个字典,并且有其他地方引用了,那么就不能删掉了,我觉得应该递归删除
/*i
f(PyDict_Check(op->me_value))
{
PyDict_Clear(op->me_value);
}
else{ Py_XDECREF(ep->me_value);
}
*/
}
#ifdef Py_DEBUG
else
assert(ep->me_value == NULL);
#endif
} if (table_is_malloced)
PyMem_DEL(table);
}
python dict clear只能删除一层,不能够递归删除。的更多相关文章
- JAVA删除某个文件夹(递归删除文件夹的所有文件)
/** * 递归删除文件夹下所有内容 最后删除该文件夹 * @param filePath 要删除的文件夹路径 * @return */ public boolean deleteFiles(Stri ...
- Node.js之删除文件夹(含递归删除)
应用场景:比如像Eclipse这样的IDE,右击项目,出现选项,点击选项中的删除,就可以删除这个项目及其下的子目录包含文件(使用electron开发的桌面端项目多少都会用到). 核心代码如下: /** ...
- Python dict operation introduce
字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: d = ...
- Python dict字典方法完全攻略(全)
我们知道,Python 字典的数据类型为 dict,我们可使用 dir(dict) 来查看该类型包含哪些方法,例如: >>> dir(dict)['clear', 'copy', ' ...
- python dict的函数
1. dict.clear() 删除字典内所有元素 2. dict.copy() 返回一个字典的浅复制 3. dict.fromkeys(seq[, val]) 创建一个新字典,以序列 seq 中元素 ...
- Python 字典 clear()方法
描述 Python 字典 clear() 方法用于删除字典内所有元素. 语法 clear() 方法语法: D.clear() 参数 无. 返回值 该方法没有任何返回值. 实例 以下实例展示了 clea ...
- python dict.get()和dict['key']的区别
先看代码: In [1]: a = {'name': 'wang'} In [2]: a.get('age') In [3]: a['age'] --------------------------- ...
- 使用ownCloud搭建你的个人云服务(ubuntu 14.04 server)(ownCloud对文件不切片,Seafile对文件切片),owncloud没有存储的功能 只能同步 本地删除了服务器也会删除
ownCloud是什么 ownCloud是一个自由且开源的个人云存储解决方案(类似百度网盘或者Dropbox),包括两个部分:服务器和客户端. ownCloud在客户端可通过网页界面,或者安装专用的客 ...
- Python dict(或对象)与json之间的互相转化
Python dict(或对象)与json之间的互相转化 原文转载自 1.JSON:JavaScript 对象表示法,是轻量级的文本数据交换格式,独立于语言,平台 2.JSON 语法规则 数据在名称/ ...
随机推荐
- play with usb
1) struct usbdevfs_bulktransfer { unsigned int ep; unsigned int len; unsigned i ...
- [LeetCode] Reorder List 链表重排序
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do th ...
- HTTP相关函数
1.headers_list() //返回头部信息 2.header("Content-type: text/html; charset=utf-8") //修改编码 3.head ...
- charing animation
FHD : full high definition,1920 x 1080,全高清 vendor/mediatek/proprietary/bootable/bootloader/lk/dev/lo ...
- springboot @ConfigurationProperties
Spring Boot 提供了一种方式 --类型安全的bean,能够根据类型校验和管理application中的bean.继续使用author做例子.配置放在author.properties文件中. ...
- MySQL练习题参考答案
MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...
- C#-WebForm-★★★ 分页展示 ★★★
什么是"分页展示"? 分页展示就是将庞大的数据分成若干页,每页展示若干条数据,向用户展示数据 流程:客户端浏览器向服务器发送查询请求 → 服务器从数据库查询数据 → 服务器转换成代 ...
- Android基础总结(十一)
Fragment(重要) 用途:在一个Activity里切换界面,切换界面时只切换Fragment里面的内容 生命周期方法跟Activity一致,可以理解把其为就是一个Activity fragmen ...
- JDBC判断数据库是否插入成功
package com.xujianyou; import java.sql.*; public class TestConnect { public static void main(String ...
- my computer
把08年买的电脑换了,自己买的配件装的,狂拽酷炫叼炸天. 配置清单: CPU :英特尔至强E3-1230 V2 主板 :华硕P8Z77-V LX LX2 机箱 :撒哈拉海盗贼王Z6游戏机箱(白色限量版 ...