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

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: Created 1 year, 2 months ago , Downloaded from: http://bugs.python.org/file9225/threading_local.patch
Right Patch Set: threading_local4 - includes the unit test, fixes the missing error path decref Created 1 year, 2 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) {
Antoine Pitrou 2008/08/28 09:29:49 A Py_DECREF(localdict) is needed just before baili
gregory.p.smith 2008/09/02 06:43:30 On 2008/08/28 09:29:49, Antoine Pitrou wrote: > A
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 290 }
289 291
290 } 292 }
291 293
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 » int res = PyObject_GenericSetAttr((PyObject *)self, name, v); 300 » PyObject *ldict = _ldict(self);
299 301 » if (ldict == NULL)
300 » if (res < 0 && PyErr_ExceptionMatches(PyExc_AttributeError)) { 302 » » return -1;
Antoine Pitrou 2008/08/28 09:29:49 Why did you add this fallback? Is it really necess
gregory.p.smith 2008/09/02 06:43:30 On 2008/08/28 09:29:49, Antoine Pitrou wrote: > Wh
301 » » PyObject *ldict = _ldict(self); 303
302 » » if (ldict == NULL) 304 » if (v != NULL) {
303 » » » return -1; 305 » » return PyDict_SetItem(ldict, name, v);
304 306 » } else {
305 » » PyErr_Clear(); 307 » » int res;
306 308 » » res = PyDict_DelItem(ldict, name);
307 » » res = PyDict_SetItem(ldict, name, v); 309 » » if ((res < 0) && PyErr_ExceptionMatches(PyExc_KeyError)) {
308 » } 310 » » » PyErr_SetObject(PyExc_AttributeError, name);
309 311 » » }
310 » return res; 312 » » return res;
313 » }
311 } 314 }
312 315
313 static PyObject * 316 static PyObject *
314 local_getdict(localobject *self, void *closure) 317 local_getdict(localobject *self, void *closure)
315 { 318 {
316 PyObject *ldict = _ldict(self); 319 PyObject *ldict = _ldict(self);
317 if (ldict == NULL) { 320 if (ldict == NULL) {
318 PyErr_SetString(PyExc_AttributeError, "__dict__"); 321 PyErr_SetString(PyExc_AttributeError, "__dict__");
319 return NULL; 322 return NULL;
320 } 323 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 379
377 static PyObject * 380 static PyObject *
378 local_getattro(localobject *self, PyObject *name) 381 local_getattro(localobject *self, PyObject *name)
379 { 382 {
380 PyObject *ldict, *value; 383 PyObject *ldict, *value;
381 384
382 ldict = _ldict(self); 385 ldict = _ldict(self);
383 if (ldict == NULL) 386 if (ldict == NULL)
384 return NULL; 387 return NULL;
385 388
386 if (Py_TYPE(self) != &localtype)
387 /* use generic lookup for subtypes */
388 return PyObject_GenericGetAttr((PyObject *)self, name);
389
390 /* Optimization: just look in dict ourselves */ 389 /* Optimization: just look in dict ourselves */
391 value = PyDict_GetItem(ldict, name); 390 value = PyDict_GetItem(ldict, name);
392 if (value == NULL) 391 if (value == NULL)
393 /* Fall back on generic to get __class__ and __dict__ */ 392 /* Fall back on generic to get __class__ and __dict__ */
394 return PyObject_GenericGetAttr((PyObject *)self, name); 393 return PyObject_GenericGetAttr((PyObject *)self, name);
395 394
396 Py_INCREF(value); 395 Py_INCREF(value);
397 return value; 396 return value;
398 } 397 }
399 398
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 Py_INCREF(&Locktype); 705 Py_INCREF(&Locktype);
707 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); 706 PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype);
708 707
709 Py_INCREF(&localtype); 708 Py_INCREF(&localtype);
710 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) 709 if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
711 return; 710 return;
712 711
713 /* Initialize the C thread library */ 712 /* Initialize the C thread library */
714 PyThread_init_thread(); 713 PyThread_init_thread();
715 } 714 }
LEFTRIGHT

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