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只能删除一层,不能够递归删除。的更多相关文章

  1. JAVA删除某个文件夹(递归删除文件夹的所有文件)

    /** * 递归删除文件夹下所有内容 最后删除该文件夹 * @param filePath 要删除的文件夹路径 * @return */ public boolean deleteFiles(Stri ...

  2. Node.js之删除文件夹(含递归删除)

    应用场景:比如像Eclipse这样的IDE,右击项目,出现选项,点击选项中的删除,就可以删除这个项目及其下的子目录包含文件(使用electron开发的桌面端项目多少都会用到). 核心代码如下: /** ...

  3. Python dict operation introduce

    字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: d = ...

  4. Python dict字典方法完全攻略(全)

    我们知道,Python 字典的数据类型为 dict,我们可使用 dir(dict) 来查看该类型包含哪些方法,例如: >>> dir(dict)['clear', 'copy', ' ...

  5. python dict的函数

    1. dict.clear() 删除字典内所有元素 2. dict.copy() 返回一个字典的浅复制 3. dict.fromkeys(seq[, val]) 创建一个新字典,以序列 seq 中元素 ...

  6. Python 字典 clear()方法

    描述 Python 字典 clear() 方法用于删除字典内所有元素. 语法 clear() 方法语法: D.clear() 参数 无. 返回值 该方法没有任何返回值. 实例 以下实例展示了 clea ...

  7. python dict.get()和dict['key']的区别

    先看代码: In [1]: a = {'name': 'wang'} In [2]: a.get('age') In [3]: a['age'] --------------------------- ...

  8. 使用ownCloud搭建你的个人云服务(ubuntu 14.04 server)(ownCloud对文件不切片,Seafile对文件切片),owncloud没有存储的功能 只能同步 本地删除了服务器也会删除

    ownCloud是什么 ownCloud是一个自由且开源的个人云存储解决方案(类似百度网盘或者Dropbox),包括两个部分:服务器和客户端. ownCloud在客户端可通过网页界面,或者安装专用的客 ...

  9. Python dict(或对象)与json之间的互相转化

    Python dict(或对象)与json之间的互相转化 原文转载自 1.JSON:JavaScript 对象表示法,是轻量级的文本数据交换格式,独立于语言,平台 2.JSON 语法规则 数据在名称/ ...

随机推荐

  1. Word Search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  2. 解读ASP.NET 5 & MVC6系列(16):自定义View视图文件查找逻辑

    之前MVC5和之前的版本中,我们要想对View文件的路径进行控制的话,则必须要对IViewEngine接口的FindPartialView或FindView方法进行重写,所有的视图引擎都继承于该IVi ...

  3. [LeetCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  4. Java递归目录结构

    import java.io.File; public class FileTree { public static void main(String[] args) { printFileTree( ...

  5. 自建Ceph存储与 AWS、阿里云、腾讯云的成本对比

    本文单从存储成本角度对比了自建Ceph存储和业界公有云存储的硬件成本,不包括IDC带宽成本. 统计Ceph集群的用到的主要设备为: OSD.MON.RGW服务器 .TOR交换机. 机架. 下表解释: ...

  6. DrawerLayout 和 NavigationView 的使用

    参考: 1.NavigationView 的使用 2.NavigationView更改菜单icon和title颜色变化效果 3.Android 自己实现 NavigationView 转了第一篇   ...

  7. ABP文档 :Overall - Introduction

    介绍 我们基于不同的需求创建不同的应用,但却在一次又一次地实现相同或相似的结构.至少在某种程度上,授权.验证.异常处理.日志.本地化.数据库连接管理.配置管理.审计日志属于通用的结构. 另外我们总是在 ...

  8. jquery Combo Select 下拉框可选可输入插件

    Combo Select 是一款友好的 jQuery 下拉框插件,在 PC 浏览器上它能模拟一个简单漂亮的下拉框,在 iPad 等移动设备上又能回退到原生样式.Combo Select 能够对选项进行 ...

  9. Android基础总结(五)

    HttpClient 发送get请求 创建一个客户端对象 HttpClient client = new DefaultHttpClient(); 创建一个get请求对象 HttpGet hg = n ...

  10. 手机端html5触屏事件(touch事件)

    touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend:触摸结束的时候触发 而每个触摸事件都包括了三个触摸列表,每个列表里包含了对应的一系列触摸点( ...