[pypy-svn] r52190 - pypy/extradoc/talk/sfi2008/demo

fijal at codespeak.net fijal at codespeak.net
Wed Mar 5 13:00:27 CET 2008


Author: fijal
Date: Wed Mar  5 13:00:26 2008
New Revision: 52190

Added:
   pypy/extradoc/talk/sfi2008/demo/ctypes.c
Log:
Part of ctypes module to showcase refcounting happening


Added: pypy/extradoc/talk/sfi2008/demo/ctypes.c
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/sfi2008/demo/ctypes.c	Wed Mar  5 13:00:26 2008
@@ -0,0 +1,28 @@
+static int
+KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
+{
+	int result;
+	CDataObject *ob;
+	PyObject *key;
+
+/* Optimization: no need to store None */
+	if (keep == Py_None) {
+		Py_DECREF(Py_None);
+		return 0;
+	}
+	ob = CData_GetContainer(target);
+	if (ob->b_objects == NULL || !PyDict_Check(ob->b_objects)) {
+		Py_XDECREF(ob->b_objects);
+		ob->b_objects = keep; /* refcount consumed */
+		return 0;
+	}
+	key = unique_key(target, index);
+	if (key == NULL) {
+		Py_DECREF(keep);
+		return -1;
+	}
+	result = PyDict_SetItem(ob->b_objects, key, keep);
+	Py_DECREF(key);
+	Py_DECREF(keep);
+	return result;
+}



More information about the Pypy-commit mailing list