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
21a663ea
Commit
21a663ea
authored
Apr 13, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26057: Got rid of nonneeded use of PyUnicode_FromObject().
parent
131b8f8e
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
240 additions
and
641 deletions
+240
-641
Modules/_codecsmodule.c
Modules/_codecsmodule.c
+45
-186
Modules/socketmodule.c
Modules/socketmodule.c
+20
-24
Objects/stringlib/find.h
Objects/stringlib/find.h
+2
-11
Objects/unicodeobject.c
Objects/unicodeobject.c
+163
-399
Python/bltinmodule.c
Python/bltinmodule.c
+2
-3
Python/getargs.c
Python/getargs.c
+8
-18
No files found.
Modules/_codecsmodule.c
View file @
21a663ea
This diff is collapsed.
Click to expand it.
Modules/socketmodule.c
View file @
21a663ea
...
...
@@ -1401,7 +1401,7 @@ static int
idna_converter
(
PyObject
*
obj
,
struct
maybe_idna
*
data
)
{
size_t
len
;
PyObject
*
obj2
,
*
obj3
;
PyObject
*
obj2
;
if
(
obj
==
NULL
)
{
idna_cleanup
(
data
);
return
1
;
...
...
@@ -1416,31 +1416,27 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
data
->
buf
=
PyByteArray_AsString
(
obj
);
len
=
PyByteArray_Size
(
obj
);
}
else
if
(
PyUnicode_Check
(
obj
)
&&
PyUnicode_READY
(
obj
)
==
0
&&
PyUnicode_IS_COMPACT_ASCII
(
obj
))
{
else
if
(
PyUnicode_Check
(
obj
))
{
if
(
PyUnicode_READY
(
obj
)
==
0
&&
PyUnicode_IS_COMPACT_ASCII
(
obj
))
{
data
->
buf
=
PyUnicode_DATA
(
obj
);
len
=
PyUnicode_GET_LENGTH
(
obj
);
}
else
{
obj2
=
PyUnicode_FromObject
(
obj
);
obj2
=
PyUnicode_AsEncodedString
(
obj
,
"idna"
,
NULL
);
if
(
!
obj2
)
{
PyErr_Format
(
PyExc_TypeError
,
"string or unicode text buffer expected, not %s"
,
obj
->
ob_type
->
tp_name
);
return
0
;
}
obj3
=
PyUnicode_AsEncodedString
(
obj2
,
"idna"
,
NULL
);
Py_DECREF
(
obj2
);
if
(
!
obj3
)
{
PyErr_SetString
(
PyExc_TypeError
,
"encoding of hostname failed"
);
return
0
;
}
if
(
!
PyBytes_Check
(
obj3
))
{
Py_DECREF
(
obj3
)
;
PyErr_SetString
(
PyExc_TypeError
,
"encoding of hostname failed to return bytes"
);
return
0
;
assert
(
PyBytes_Check
(
obj2
));
data
->
obj
=
obj2
;
data
->
buf
=
PyBytes_AS_STRING
(
obj2
);
len
=
PyBytes_GET_SIZE
(
obj2
)
;
}
data
->
obj
=
obj3
;
data
->
buf
=
PyBytes_AS_STRING
(
obj3
);
len
=
PyBytes_GET_SIZE
(
obj3
);
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"str, bytes or bytearray expected, not %s"
,
obj
->
ob_type
->
tp_name
);
return
0
;
}
if
(
strlen
(
data
->
buf
)
!=
len
)
{
Py_CLEAR
(
data
->
obj
);
...
...
Objects/stringlib/find.h
View file @
21a663ea
...
...
@@ -123,11 +123,6 @@ STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args,
/*
Wraps stringlib_parse_args_finds() and additionally ensures that the
first argument is a unicode object.
Note that we receive a pointer to the pointer of the substring object,
so when we create that object in this function we don't DECREF it,
because it continues living in the caller functions (those functions,
after finishing using the substring, must DECREF it).
*/
Py_LOCAL_INLINE
(
int
)
...
...
@@ -135,14 +130,10 @@ STRINGLIB(parse_args_finds_unicode)(const char * function_name, PyObject *args,
PyObject
**
substring
,
Py_ssize_t
*
start
,
Py_ssize_t
*
end
)
{
PyObject
*
tmp_substring
;
if
(
STRINGLIB
(
parse_args_finds
)(
function_name
,
args
,
&
tmp_substring
,
if
(
STRINGLIB
(
parse_args_finds
)(
function_name
,
args
,
substring
,
start
,
end
))
{
tmp_substring
=
PyUnicode_FromObject
(
tmp_substring
);
if
(
!
tmp_substring
)
if
(
ensure_unicode
(
*
substring
)
<
0
)
return
0
;
*
substring
=
tmp_substring
;
return
1
;
}
return
0
;
...
...
Objects/unicodeobject.c
View file @
21a663ea
This diff is collapsed.
Click to expand it.
Python/bltinmodule.c
View file @
21a663ea
...
...
@@ -1931,9 +1931,8 @@ builtin_input_impl(PyModuleDef *module, PyObject *prompt)
Py_CLEAR
(
stringpo
);
if
(
po
==
NULL
)
goto
_readline_errors
;
promptstr
=
PyBytes_AsString
(
po
);
if
(
promptstr
==
NULL
)
goto
_readline_errors
;
assert
(
PyBytes_Check
(
po
));
promptstr
=
PyBytes_AS_STRING
(
po
);
}
else
{
po
=
NULL
;
...
...
Python/getargs.c
View file @
21a663ea
...
...
@@ -1056,35 +1056,25 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
return
converterr
(
"(AsCharBuffer failed)"
,
arg
,
msgbuf
,
bufsize
);
}
else
{
PyObject
*
u
;
/* Convert object to Unicode */
u
=
PyUnicode_FromObject
(
arg
);
if
(
u
==
NULL
)
return
converterr
(
"string or unicode or text buffer"
,
arg
,
msgbuf
,
bufsize
);
else
if
(
PyUnicode_Check
(
arg
))
{
/* Encode object; use default error handling */
s
=
PyUnicode_AsEncodedString
(
u
,
s
=
PyUnicode_AsEncodedString
(
arg
,
encoding
,
NULL
);
Py_DECREF
(
u
);
if
(
s
==
NULL
)
return
converterr
(
"(encoding failed)"
,
arg
,
msgbuf
,
bufsize
);
if
(
!
PyBytes_Check
(
s
))
{
Py_DECREF
(
s
);
return
converterr
(
"(encoder failed to return bytes)"
,
arg
,
msgbuf
,
bufsize
);
}
assert
(
PyBytes_Check
(
s
));
size
=
PyBytes_GET_SIZE
(
s
);
ptr
=
PyBytes_AS_STRING
(
s
);
if
(
ptr
==
NULL
)
ptr
=
""
;
}
else
{
return
converterr
(
recode_strings
?
"str"
:
"str, bytes or bytearray"
,
arg
,
msgbuf
,
bufsize
);
}
/* Write output; output is guaranteed to be 0-terminated */
if
(
*
format
==
'#'
)
{
...
...
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