Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Delta Between Two Patch Sets: Modules/threadmodule.c

Issue 3641: thread._local, threading.local Python issue 1868 & 3710 SVN Base: http://svn.python.org/view/*checkout*/python/trunk/
Left Patch Set: christian heimes updated version Created 1 year, 3 months ago , Downloaded from: http://bugs.python.org/file11297/threading_local2.patch
Right Patch Set: threading_local4 - includes the unit test, fixes the missing error path decref Created 1 year, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 1
2 /* Thread module */ 2 /* Thread module */
3 /* Interface to Sjoerd's portable C thread library */ 3 /* Interface to Sjoerd's portable C thread library */
4 4
5 #include "Python.h" 5 #include "Python.h"
6 6
7 #ifndef WITH_THREAD 7 #ifndef WITH_THREAD
8 #error "Error! The rest of Python is not compiled with thread support." 8 #error "Error! The rest of Python is not compiled with thread support."
9 #error "Rerun configure, adding a --with-threads option." 9 #error "Rerun configure, adding a --with-threads option."
10 #error "Then run `make clean' followed by `make'." 10 #error "Then run `make clean' followed by `make'."
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (localdict == NULL) 197 if (localdict == NULL)
198 goto err; 198 goto err;
199 199
200 tdict = PyThreadState_GetDict(); 200 tdict = PyThreadState_GetDict();
201 if (tdict == NULL) { 201 if (tdict == NULL) {
202 PyErr_SetString(PyExc_SystemError, 202 PyErr_SetString(PyExc_SystemError,
203 "Couldn't get thread-state dictionary"); 203 "Couldn't get thread-state dictionary");
204 goto err; 204 goto err;
205 } 205 }
206 206
207 » if (PyDict_SetItem(tdict, self->key, localdict) < 0) 207 » if (PyDict_SetItem(tdict, self->key, localdict) < 0) {
208 » » Py_DECREF(localdict);
208 goto err; 209 goto err;
210 }
209 Py_DECREF(localdict); 211 Py_DECREF(localdict);
210 212
211 return (PyObject *)self; 213 return (PyObject *)self;
212 214
213 err: 215 err:
214 Py_DECREF(self); 216 Py_DECREF(self);
215 return NULL; 217 return NULL;
216 } 218 }
217 219
218 static int 220 static int
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return ldict; 294 return ldict;
293 } 295 }
294 296
295 static int 297 static int
296 local_setattro(localobject *self, PyObject *name, PyObject *v) 298 local_setattro(localobject *self, PyObject *name, PyObject *v)
297 { 299 {
298 PyObject *ldict = _ldict(self); 300 PyObject *ldict = _ldict(self);
299 if (ldict == NULL) 301 if (ldict == NULL)
300 return -1; 302 return -1;
301 303
302 » return PyDict_SetItem(ldict, name, v); 304 » if (v != NULL) {
305 » » return PyDict_SetItem(ldict, name, v);
306 » } else {
307 » » int res;
308 » » res = PyDict_DelItem(ldict, name);
309 » » if ((res < 0) && PyErr_ExceptionMatches(PyExc_KeyError)) {
310 » » » PyErr_SetObject(PyExc_AttributeError, name);
311 » » }
312 » » return res;
313 » }
303 } 314 }
304 315
305 static PyObject * 316 static PyObject *
306 local_getdict(localobject *self, void *closure) 317 local_getdict(localobject *self, void *closure)
307 { 318 {
308 PyObject *ldict = _ldict(self); 319 PyObject *ldict = _ldict(self);
309 if (ldict == NULL) { 320 if (ldict == NULL) {
310 PyErr_SetString(PyExc_AttributeError, "__dict__"); 321 PyErr_SetString(PyExc_AttributeError, "__dict__");
311 return NULL; 322 return NULL;
312 } 323 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 Py_INCREF(&Locktype); 705 Py_INCREF(&Locktype);
695 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); 706 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype);
696 707
697 Py_INCREF(&localtype); 708 Py_INCREF(&localtype);
698 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) 709 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
699 return; 710 return;
700 711
701 /* Initialize the C thread library */ 712 /* Initialize the C thread library */
702 PyThread_init_thread(); 713 PyThread_init_thread();
703 } 714 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497