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 语法规则 数据在名称/ ...
随机推荐
- [译]RxJS 5.X基础篇
欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...
- C++远征之封装篇(下)
对象数组 类 x1[]; 栈中实例化,不用delete. 类 *X=new X[];//在堆中实例化,结尾需要用delete删除 delete []X; //这是数组的删除形式 X=NULL;
- [转] JAVA读取excel数据(插入oracle数据库)
原文地址:http://blog.csdn.net/zczzsq/article/details/16803349 本实例做的是读取execl(只能读取.xls的execl,即只能读取03版的),如果 ...
- C++中new,delete和new[] ,delete[]的分析
转载在这里 http://www.cnblogs.com/hazir/p/new_and_delete.html
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- Python 【第八章】:JavaScript 、Dom、jQuery
JavaScript 放置位置 body内部最下面,这样可以避免javascript链接失效时,长时间加载不到页面html内容 变量: var a =123 局部变量 a = 123 全局变量 作用域 ...
- SQLAlchemy(一)
说明 SQLAlchemy只是一个翻译的过程,我们通过类来操作数据库,他会将我们的对应数据转换成SQL语句. 运用ORM创建表 #!/usr/bin/env python #! -*- coding: ...
- sass 安装、配置,css规则
http://blog.csdn.net/oyuemijindu/article/details/51036096 --sass 安装 一安装 1.ruby下载,可以到官网下载 ,注意如果是系统如果 ...
- iife js
摘自:http://dz.sdut.edu.cn/blog/subaochen/2016/02/%E8%AF%B4%E4%B8%80%E8%AF%B4js%E7%9A%84iife/ 1 定义 IIF ...
- Android Stdio 调试Smali
一 安装插件 1)Android stdio 安装插件 二 反编译smali 1)java -jar baksmali-2.1.2.jar app-debug.apk -o test/src2)and ...