gdb: change thread_info::name to unique_xmalloc_ptr, add helper function
This started out as changing thread_info::name to a unique_xmalloc_ptr. That showed that almost all users of that field had the same logic to get a thread's name: use thread_info::name if non-nullptr, else ask the target. Factor out this logic in a new thread_name free function. Make the field private (rename to m_name) and add some accessors. Change-Id: Iebdd95f4cd21fbefc505249bd1d05befc466a2fc
This commit is contained in:
parent
7ebaa5f782
commit
25558938d0
6 changed files with 57 additions and 30 deletions
|
@ -66,14 +66,10 @@ static PyObject *
|
|||
thpy_get_name (PyObject *self, void *ignore)
|
||||
{
|
||||
thread_object *thread_obj = (thread_object *) self;
|
||||
const char *name;
|
||||
|
||||
THPY_REQUIRE_VALID (thread_obj);
|
||||
|
||||
name = thread_obj->thread->name;
|
||||
if (name == NULL)
|
||||
name = target_thread_name (thread_obj->thread);
|
||||
|
||||
const char *name = thread_name (thread_obj->thread);
|
||||
if (name == NULL)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
|
@ -115,8 +111,7 @@ thpy_set_name (PyObject *self, PyObject *newvalue, void *ignore)
|
|||
return -1;
|
||||
}
|
||||
|
||||
xfree (thread_obj->thread->name);
|
||||
thread_obj->thread->name = name.release ();
|
||||
thread_obj->thread->set_name (std::move (name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue