mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
remove forward declarations, move constructor functions. makes code C++ safe.
This commit is contained in:
parent
019aec618a
commit
5576b54bec
1 changed files with 42 additions and 43 deletions
|
@ -22,24 +22,6 @@ typedef struct {
|
||||||
PyThread_type_lock lock_lock;
|
PyThread_type_lock lock_lock;
|
||||||
} lockobject;
|
} lockobject;
|
||||||
|
|
||||||
static PyTypeObject Locktype;
|
|
||||||
|
|
||||||
static lockobject *
|
|
||||||
newlockobject(void)
|
|
||||||
{
|
|
||||||
lockobject *self;
|
|
||||||
self = PyObject_New(lockobject, &Locktype);
|
|
||||||
if (self == NULL)
|
|
||||||
return NULL;
|
|
||||||
self->lock_lock = PyThread_allocate_lock();
|
|
||||||
if (self->lock_lock == NULL) {
|
|
||||||
PyObject_Del(self);
|
|
||||||
self = NULL;
|
|
||||||
PyErr_SetString(ThreadError, "can't allocate lock");
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lock_dealloc(lockobject *self)
|
lock_dealloc(lockobject *self)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +148,22 @@ static PyTypeObject Locktype = {
|
||||||
0, /*tp_repr*/
|
0, /*tp_repr*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static lockobject *
|
||||||
|
newlockobject(void)
|
||||||
|
{
|
||||||
|
lockobject *self;
|
||||||
|
self = PyObject_New(lockobject, &Locktype);
|
||||||
|
if (self == NULL)
|
||||||
|
return NULL;
|
||||||
|
self->lock_lock = PyThread_allocate_lock();
|
||||||
|
if (self->lock_lock == NULL) {
|
||||||
|
PyObject_Del(self);
|
||||||
|
self = NULL;
|
||||||
|
PyErr_SetString(ThreadError, "can't allocate lock");
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
/* Thread-local objects */
|
/* Thread-local objects */
|
||||||
|
|
||||||
#include "structmember.h"
|
#include "structmember.h"
|
||||||
|
@ -178,8 +176,6 @@ typedef struct {
|
||||||
PyObject *dict;
|
PyObject *dict;
|
||||||
} localobject;
|
} localobject;
|
||||||
|
|
||||||
static PyTypeObject localtype;
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||||
{
|
{
|
||||||
|
@ -315,29 +311,6 @@ _ldict(localobject *self)
|
||||||
return ldict;
|
return ldict;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
local_getattro(localobject *self, PyObject *name)
|
|
||||||
{
|
|
||||||
PyObject *ldict, *value;
|
|
||||||
|
|
||||||
ldict = _ldict(self);
|
|
||||||
if (ldict == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (self->ob_type != &localtype)
|
|
||||||
/* use generic lookup for subtypes */
|
|
||||||
return PyObject_GenericGetAttr((PyObject *)self, name);
|
|
||||||
|
|
||||||
/* Optimization: just look in dict ourselves */
|
|
||||||
value = PyDict_GetItem(ldict, name);
|
|
||||||
if (value == NULL)
|
|
||||||
/* Fall back on generic to get __class__ and __dict__ */
|
|
||||||
return PyObject_GenericGetAttr((PyObject *)self, name);
|
|
||||||
|
|
||||||
Py_INCREF(value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_setattro(localobject *self, PyObject *name, PyObject *v)
|
local_setattro(localobject *self, PyObject *name, PyObject *v)
|
||||||
{
|
{
|
||||||
|
@ -368,6 +341,8 @@ static PyGetSetDef local_getset[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PyObject *local_getattro(localobject *, PyObject *);
|
||||||
|
|
||||||
static PyTypeObject localtype = {
|
static PyTypeObject localtype = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
/* ob_size */ 0,
|
/* ob_size */ 0,
|
||||||
|
@ -412,6 +387,28 @@ static PyTypeObject localtype = {
|
||||||
/* tp_is_gc */ 0, /* For PyObject_IS_GC */
|
/* tp_is_gc */ 0, /* For PyObject_IS_GC */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
local_getattro(localobject *self, PyObject *name)
|
||||||
|
{
|
||||||
|
PyObject *ldict, *value;
|
||||||
|
|
||||||
|
ldict = _ldict(self);
|
||||||
|
if (ldict == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (self->ob_type != &localtype)
|
||||||
|
/* use generic lookup for subtypes */
|
||||||
|
return PyObject_GenericGetAttr((PyObject *)self, name);
|
||||||
|
|
||||||
|
/* Optimization: just look in dict ourselves */
|
||||||
|
value = PyDict_GetItem(ldict, name);
|
||||||
|
if (value == NULL)
|
||||||
|
/* Fall back on generic to get __class__ and __dict__ */
|
||||||
|
return PyObject_GenericGetAttr((PyObject *)self, name);
|
||||||
|
|
||||||
|
Py_INCREF(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/* Module functions */
|
/* Module functions */
|
||||||
|
|
||||||
|
@ -560,6 +557,8 @@ thread_PyThread_exit_prog(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static lockobject *newlockobject(void);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
thread_PyThread_allocate_lock(PyObject *self)
|
thread_PyThread_allocate_lock(PyObject *self)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue