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
60fbac95
Commit
60fbac95
authored
Sep 01, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create PyUnicode_strdup() function
parent
74676426
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
Include/unicodeobject.h
Include/unicodeobject.h
+10
-1
Objects/unicodeobject.c
Objects/unicodeobject.c
+22
-0
No files found.
Include/unicodeobject.h
View file @
60fbac95
...
@@ -220,6 +220,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
...
@@ -220,6 +220,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS2_Fini
# define _PyUnicode_Fini _PyUnicodeUCS2_Fini
# define _PyUnicode_Init _PyUnicodeUCS2_Init
# define _PyUnicode_Init _PyUnicodeUCS2_Init
# define PyUnicode_strdup PyUnicodeUCS2_strdup
#else
#else
...
@@ -302,7 +303,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
...
@@ -302,7 +303,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS4_Fini
# define _PyUnicode_Fini _PyUnicodeUCS4_Fini
# define _PyUnicode_Init _PyUnicodeUCS4_Init
# define _PyUnicode_Init _PyUnicodeUCS4_Init
# define PyUnicode_strdup PyUnicodeUCS4_strdup
#endif
#endif
...
@@ -1602,6 +1603,14 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
...
@@ -1602,6 +1603,14 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
Py_UNICODE
c
Py_UNICODE
c
);
);
/* Create a copy of a unicode string ending with a nul character. Return NULL
and raise a MemoryError exception on memory allocation failure, otherwise
return a new allocated buffer (use PyMem_Free() to free the buffer). */
PyAPI_FUNC
(
Py_UNICODE
*
)
PyUnicode_strdup
(
PyObject
*
unicode
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
Objects/unicodeobject.c
View file @
60fbac95
...
@@ -10014,6 +10014,28 @@ Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c)
...
@@ -10014,6 +10014,28 @@ Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c)
return
NULL
;
return
NULL
;
}
}
Py_UNICODE
*
PyUnicode_strdup
(
PyObject
*
object
)
{
PyUnicodeObject
*
unicode
=
(
PyUnicodeObject
*
)
object
;
Py_UNICODE
*
copy
;
Py_ssize_t
size
;
/* Ensure we won't overflow the size. */
if
(
PyUnicode_GET_SIZE
(
unicode
)
>
((
PY_SSIZE_T_MAX
/
sizeof
(
Py_UNICODE
))
-
1
))
{
PyErr_NoMemory
();
return
NULL
;
}
size
=
PyUnicode_GET_SIZE
(
unicode
)
+
1
;
/* copy the nul character */
size
*=
sizeof
(
Py_UNICODE
);
copy
=
PyMem_Malloc
(
size
);
if
(
copy
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
}
memcpy
(
copy
,
PyUnicode_AS_UNICODE
(
unicode
),
size
);
return
copy
;
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
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