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
43ab100c
Commit
43ab100c
authored
May 28, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix refleaks in UnicodeError get and set methods.
parent
2b330376
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
45 deletions
+56
-45
Objects/exceptions.c
Objects/exceptions.c
+56
-45
No files found.
Objects/exceptions.c
View file @
43ab100c
/*
* New exceptions.c written in Iceland by Richard Jones and Georg Brandl.
*
* Thanks go to Tim Peters and Michael Hudson for debugging.
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"
...
...
@@ -1037,56 +1043,57 @@ SyntaxError_str(PySyntaxErrorObject *self)
{
PyObject
*
str
;
PyObject
*
result
;
int
have_filename
=
0
;
int
have_lineno
=
0
;
char
*
buffer
=
NULL
;
if
(
self
->
msg
)
str
=
PyObject_Str
(
self
->
msg
);
else
str
=
PyObject_Str
(
Py_None
);
result
=
str
;
if
(
!
str
)
return
NULL
;
/* Don't fiddle with non-string return (shouldn't happen anyway) */
if
(
!
PyString_Check
(
str
))
return
str
;
/* XXX -- do all the additional formatting with filename and
lineno here */
if
(
str
!=
NULL
&&
PyString_Check
(
str
))
{
int
have_filename
=
0
;
int
have_lineno
=
0
;
char
*
buffer
=
NULL
;
have_filename
=
(
self
->
filename
!=
NULL
)
&&
PyString_Check
(
self
->
filename
);
have_lineno
=
(
self
->
lineno
!=
NULL
)
&&
PyInt_Check
(
self
->
lineno
);
if
(
have_filename
||
have_lineno
)
{
Py_ssize_t
bufsize
=
PyString_GET_SIZE
(
str
)
+
64
;
if
(
have_filename
)
bufsize
+=
PyString_GET_SIZE
(
self
->
filename
);
buffer
=
(
char
*
)
PyMem_MALLOC
(
bufsize
);
if
(
buffer
!=
NULL
)
{
if
(
have_filename
&&
have_lineno
)
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (%s, line %ld)"
,
PyString_AS_STRING
(
str
),
my_basename
(
PyString_AS_STRING
(
self
->
filename
)),
PyInt_AsLong
(
self
->
lineno
));
else
if
(
have_filename
)
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (%s)"
,
PyString_AS_STRING
(
str
),
my_basename
(
PyString_AS_STRING
(
self
->
filename
)));
else
if
(
have_lineno
)
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (line %ld)"
,
PyString_AS_STRING
(
str
),
PyInt_AsLong
(
self
->
lineno
));
result
=
PyString_FromString
(
buffer
);
PyMem_FREE
(
buffer
);
if
(
result
==
NULL
)
result
=
str
;
else
Py_DECREF
(
str
);
}
}
}
have_filename
=
(
self
->
filename
!=
NULL
)
&&
PyString_Check
(
self
->
filename
);
have_lineno
=
(
self
->
lineno
!=
NULL
)
&&
PyInt_Check
(
self
->
lineno
);
if
(
!
have_filename
&&
!
have_lineno
)
return
str
;
Py_ssize_t
bufsize
=
PyString_GET_SIZE
(
str
)
+
64
;
if
(
have_filename
)
bufsize
+=
PyString_GET_SIZE
(
self
->
filename
);
buffer
=
PyMem_MALLOC
(
bufsize
);
if
(
buffer
==
NULL
)
return
str
;
if
(
have_filename
&&
have_lineno
)
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (%s, line %ld)"
,
PyString_AS_STRING
(
str
),
my_basename
(
PyString_AS_STRING
(
self
->
filename
)),
PyInt_AsLong
(
self
->
lineno
));
else
if
(
have_filename
)
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (%s)"
,
PyString_AS_STRING
(
str
),
my_basename
(
PyString_AS_STRING
(
self
->
filename
)));
else
/* only have_lineno */
PyOS_snprintf
(
buffer
,
bufsize
,
"%s (line %ld)"
,
PyString_AS_STRING
(
str
),
PyInt_AsLong
(
self
->
lineno
));
result
=
PyString_FromString
(
buffer
);
PyMem_FREE
(
buffer
);
if
(
result
==
NULL
)
result
=
str
;
else
Py_DECREF
(
str
);
return
result
;
}
...
...
@@ -1208,7 +1215,7 @@ set_ssize_t(PyObject **attr, Py_ssize_t value)
PyObject
*
obj
=
PyInt_FromSsize_t
(
value
);
if
(
!
obj
)
return
-
1
;
Py_
XDECREF
(
*
attr
);
Py_
CLEAR
(
*
attr
);
*
attr
=
obj
;
return
0
;
}
...
...
@@ -1236,7 +1243,7 @@ set_string(PyObject **attr, const char *value)
PyObject
*
obj
=
PyString_FromString
(
value
);
if
(
!
obj
)
return
-
1
;
Py_
XDECREF
(
*
attr
);
Py_
CLEAR
(
*
attr
);
*
attr
=
obj
;
return
0
;
}
...
...
@@ -1302,6 +1309,7 @@ PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
*
start
=
0
;
/*XXX check for values <0*/
if
(
*
start
>=
size
)
*
start
=
size
-
1
;
Py_DECREF
(
obj
);
return
0
;
}
return
-
1
;
...
...
@@ -1321,6 +1329,7 @@ PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
*
start
=
0
;
if
(
*
start
>=
size
)
*
start
=
size
-
1
;
Py_DECREF
(
obj
);
return
0
;
}
return
-
1
;
...
...
@@ -1368,6 +1377,7 @@ PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
*
end
=
1
;
if
(
*
end
>
size
)
*
end
=
size
;
Py_DECREF
(
obj
);
return
0
;
}
return
-
1
;
...
...
@@ -1387,6 +1397,7 @@ PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
*
end
=
1
;
if
(
*
end
>
size
)
*
end
=
size
;
Py_DECREF
(
obj
);
return
0
;
}
return
-
1
;
...
...
@@ -1630,8 +1641,8 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
static
PyObject
*
UnicodeDecodeError_str
(
PyObject
*
self
)
{
Py_ssize_t
start
;
Py_ssize_t
end
;
Py_ssize_t
start
=
0
;
Py_ssize_t
end
=
0
;
if
(
PyUnicodeDecodeError_GetStart
(
self
,
&
start
))
return
NULL
;
...
...
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