Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bf55bcdd
Commit
bf55bcdd
authored
Jan 13, 2000
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List objects obtained through as_List(resource) are not auto-disposed upon
Python object freeing.
parent
7684ecdc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
11 deletions
+34
-11
Mac/Modules/list/Listmodule.c
Mac/Modules/list/Listmodule.c
+11
-9
Mac/Modules/list/listsupport.py
Mac/Modules/list/listsupport.py
+23
-2
No files found.
Mac/Modules/list/Listmodule.c
View file @
bf55bcdd
...
@@ -58,6 +58,7 @@ PyTypeObject List_Type;
...
@@ -58,6 +58,7 @@ PyTypeObject List_Type;
typedef
struct
ListObject
{
typedef
struct
ListObject
{
PyObject_HEAD
PyObject_HEAD
ListHandle
ob_itself
;
ListHandle
ob_itself
;
int
ob_must_be_disposed
;
}
ListObject
;
}
ListObject
;
PyObject
*
ListObj_New
(
itself
)
PyObject
*
ListObj_New
(
itself
)
...
@@ -71,6 +72,7 @@ PyObject *ListObj_New(itself)
...
@@ -71,6 +72,7 @@ PyObject *ListObj_New(itself)
it
=
PyObject_NEW
(
ListObject
,
&
List_Type
);
it
=
PyObject_NEW
(
ListObject
,
&
List_Type
);
if
(
it
==
NULL
)
return
NULL
;
if
(
it
==
NULL
)
return
NULL
;
it
->
ob_itself
=
itself
;
it
->
ob_itself
=
itself
;
it
->
ob_must_be_disposed
=
1
;
return
(
PyObject
*
)
it
;
return
(
PyObject
*
)
it
;
}
}
ListObj_Convert
(
v
,
p_itself
)
ListObj_Convert
(
v
,
p_itself
)
...
@@ -89,7 +91,7 @@ ListObj_Convert(v, p_itself)
...
@@ -89,7 +91,7 @@ ListObj_Convert(v, p_itself)
static
void
ListObj_dealloc
(
self
)
static
void
ListObj_dealloc
(
self
)
ListObject
*
self
;
ListObject
*
self
;
{
{
LDispose
(
self
->
ob_itself
);
if
(
self
->
ob_must_be_disposed
&&
self
->
ob_itself
)
LDispose
(
self
->
ob_itself
);
PyMem_DEL
(
self
);
PyMem_DEL
(
self
);
}
}
...
@@ -686,22 +688,22 @@ static PyObject *List_as_List(_self, _args)
...
@@ -686,22 +688,22 @@ static PyObject *List_as_List(_self, _args)
PyObject
*
_args
;
PyObject
*
_args
;
{
{
PyObject
*
_res
=
NULL
;
PyObject
*
_res
=
NULL
;
ListHandle
_rv
;
Handle
h
;
Handle
h
;
if
(
!
PyArg_ParseTuple
(
_args
,
"O&"
,
ListObject
*
l
;
ResObj_Convert
,
&
h
))
if
(
!
PyArg_ParseTuple
(
_args
,
"O&"
,
ResObj_Convert
,
&
h
))
return
NULL
;
return
NULL
;
_rv
=
as_List
(
h
);
l
=
(
ListObject
*
)
ListObj_New
(
as_List
(
h
)
);
_res
=
Py_BuildValue
(
"O&"
,
l
->
ob_must_be_disposed
=
0
;
ListObj_New
,
_rv
);
return
Py_BuildValue
(
"O"
,
l
);
return
_res
;
}
}
static
PyMethodDef
List_methods
[]
=
{
static
PyMethodDef
List_methods
[]
=
{
{
"LNew"
,
(
PyCFunction
)
List_LNew
,
1
,
{
"LNew"
,
(
PyCFunction
)
List_LNew
,
1
,
"(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"
},
"(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)"
},
{
"as_List"
,
(
PyCFunction
)
List_as_List
,
1
,
{
"as_List"
,
(
PyCFunction
)
List_as_List
,
1
,
"(
Handle h) -> (ListHandle _rv
)"
},
"(
Resource)->List.
\n
Returns List object (which is not auto-freed!
)"
},
{
NULL
,
NULL
,
0
}
{
NULL
,
NULL
,
0
}
};
};
...
...
Mac/Modules/list/listsupport.py
View file @
bf55bcdd
...
@@ -83,13 +83,23 @@ ListObj_setattr(self, name, value)
...
@@ -83,13 +83,23 @@ ListObj_setattr(self, name, value)
class
MyObjectDefinition
(
GlobalObjectDefinition
):
class
MyObjectDefinition
(
GlobalObjectDefinition
):
def
outputStructMembers
(
self
):
ObjectDefinition
.
outputStructMembers
(
self
)
Output
(
"int ob_must_be_disposed;"
)
def
outputCheckNewArg
(
self
):
def
outputCheckNewArg
(
self
):
Output
(
"""if (itself == NULL) {
Output
(
"""if (itself == NULL) {
PyErr_SetString(List_Error,"Cannot create null List");
PyErr_SetString(List_Error,"Cannot create null List");
return NULL;
return NULL;
}"""
)
}"""
)
def
outputInitStructMembers
(
self
):
ObjectDefinition
.
outputInitStructMembers
(
self
)
Output
(
"it->ob_must_be_disposed = 1;"
)
def
outputFreeIt
(
self
,
itselfname
):
def
outputFreeIt
(
self
,
itselfname
):
Output
(
"
LDispose(%s);"
,
itselfname
)
Output
(
"
if (self->ob_must_be_disposed && %s) LDispose(%s);"
,
itselfname
,
itselfname
)
def
outputGetattrHook
(
self
):
def
outputGetattrHook
(
self
):
Output
(
getattrHookCode
)
Output
(
getattrHookCode
)
...
@@ -114,7 +124,18 @@ methods = []
...
@@ -114,7 +124,18 @@ methods = []
execfile
(
INPUTFILE
)
execfile
(
INPUTFILE
)
# Function to convert any handle to a list and vv.
# Function to convert any handle to a list and vv.
f
=
Function
(
ListHandle
,
'as_List'
,
(
Handle
,
'h'
,
InMode
))
##f = Function(ListHandle, 'as_List', (Handle, 'h', InMode))
as_List_body
=
"""
Handle h;
ListObject *l;
if (!PyArg_ParseTuple(_args, "O&", ResObj_Convert, &h))
return NULL;
l = (ListObject *)ListObj_New(as_List(h));
l->ob_must_be_disposed = 0;
return Py_BuildValue("O", l);
"""
f
=
ManualGenerator
(
"as_List"
,
as_List_body
)
f
.
docstring
=
lambda
:
"(Resource)->List.
\
n
Returns List object (which is not auto-freed!)"
functions
.
append
(
f
)
functions
.
append
(
f
)
f
=
Method
(
Handle
,
'as_Resource'
,
(
ListHandle
,
'lh'
,
InMode
))
f
=
Method
(
Handle
,
'as_Resource'
,
(
ListHandle
,
'lh'
,
InMode
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment