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
80e7f27e
Commit
80e7f27e
authored
Aug 26, 2007
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use unicode and remove support for some uses of str8.
parent
da059e35
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
43 deletions
+20
-43
Objects/typeobject.c
Objects/typeobject.c
+10
-14
Python/import.c
Python/import.c
+10
-29
No files found.
Objects/typeobject.c
View file @
80e7f27e
...
...
@@ -44,6 +44,7 @@ static int
type_set_name
(
PyTypeObject
*
type
,
PyObject
*
value
,
void
*
context
)
{
PyHeapTypeObject
*
et
;
char
*
tp_name
;
if
(
!
(
type
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
))
{
PyErr_Format
(
PyExc_TypeError
,
...
...
@@ -61,11 +62,10 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
type
->
tp_name
,
Py_Type
(
value
)
->
tp_name
);
return
-
1
;
}
value
=
_PyUnicode_AsDefaultEncodedString
(
value
,
NULL
);
if
(
valu
e
==
NULL
)
tp_name
=
PyUnicode_AsString
(
value
);
if
(
tp_nam
e
==
NULL
)
return
-
1
;
if
(
strlen
(
PyString_AS_STRING
(
value
))
!=
(
size_t
)
PyString_GET_SIZE
(
value
))
{
if
(
strlen
(
tp_name
)
!=
(
size_t
)
PyUnicode_GET_SIZE
(
value
))
{
PyErr_Format
(
PyExc_ValueError
,
"__name__ must not contain null bytes"
);
return
-
1
;
...
...
@@ -78,7 +78,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
Py_DECREF
(
et
->
ht_name
);
et
->
ht_name
=
value
;
type
->
tp_name
=
PyString_AS_STRING
(
value
)
;
type
->
tp_name
=
tp_name
;
return
0
;
}
...
...
@@ -1736,7 +1736,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
/* Have slots */
/* Make it into a tuple */
if
(
Py
String_Check
(
slots
)
||
Py
Unicode_Check
(
slots
))
if
(
PyUnicode_Check
(
slots
))
slots
=
PyTuple_Pack
(
1
,
slots
);
else
slots
=
PySequence_Tuple
(
slots
);
...
...
@@ -1875,14 +1875,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type
->
tp_as_sequence
=
&
et
->
as_sequence
;
type
->
tp_as_mapping
=
&
et
->
as_mapping
;
type
->
tp_as_buffer
=
&
et
->
as_buffer
;
if
(
PyString_Check
(
name
))
type
->
tp_name
=
PyString_AsString
(
name
);
else
{
type
->
tp_name
=
PyUnicode_AsString
(
name
);
if
(
!
type
->
tp_name
)
{
Py_DECREF
(
type
);
return
NULL
;
}
type
->
tp_name
=
PyUnicode_AsString
(
name
);
if
(
!
type
->
tp_name
)
{
Py_DECREF
(
type
);
return
NULL
;
}
/* Set tp_base and tp_bases */
...
...
Python/import.c
View file @
80e7f27e
...
...
@@ -453,8 +453,8 @@ PyImport_Cleanup(void)
while
(
PyDict_Next
(
modules
,
&
pos
,
&
key
,
&
value
))
{
if
(
value
->
ob_refcnt
!=
1
)
continue
;
if
(
Py
String
_Check
(
key
)
&&
PyModule_Check
(
value
))
{
name
=
Py
String_AS_STRING
(
key
);
if
(
Py
Unicode
_Check
(
key
)
&&
PyModule_Check
(
value
))
{
name
=
Py
Unicode_AsString
(
key
);
if
(
strcmp
(
name
,
"__builtin__"
)
==
0
)
continue
;
if
(
strcmp
(
name
,
"sys"
)
==
0
)
...
...
@@ -472,8 +472,8 @@ PyImport_Cleanup(void)
/* Next, delete all modules (still skipping __builtin__ and sys) */
pos
=
0
;
while
(
PyDict_Next
(
modules
,
&
pos
,
&
key
,
&
value
))
{
if
(
Py
String
_Check
(
key
)
&&
PyModule_Check
(
value
))
{
name
=
Py
String_AS_STRING
(
key
);
if
(
Py
Unicode
_Check
(
key
)
&&
PyModule_Check
(
value
))
{
name
=
Py
Unicode_AsString
(
key
);
if
(
strcmp
(
name
,
"__builtin__"
)
==
0
)
continue
;
if
(
strcmp
(
name
,
"sys"
)
==
0
)
...
...
@@ -2008,30 +2008,21 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
*
buf
=
'\0'
;
*
p_buflen
=
0
;
modname
=
PyDict_GetItem
(
globals
,
namestr
);
if
(
modname
==
NULL
||
(
!
PyString_Check
(
modname
)
&&
!
PyUnicode_Check
(
modname
)
))
if
(
modname
==
NULL
||
!
PyUnicode_Check
(
modname
))
return
Py_None
;
if
(
PyUnicode_Check
(
modname
))
{
/* XXX need to support Unicode better */
modname
=
_PyUnicode_AsDefaultEncodedString
(
modname
,
NULL
);
if
(
!
modname
)
{
PyErr_Clear
();
return
NULL
;
}
}
modpath
=
PyDict_GetItem
(
globals
,
pathstr
);
if
(
modpath
!=
NULL
)
{
Py_ssize_t
len
=
Py
String
_GET_SIZE
(
modname
);
Py_ssize_t
len
=
Py
Unicode
_GET_SIZE
(
modname
);
if
(
len
>
MAXPATHLEN
)
{
PyErr_SetString
(
PyExc_ValueError
,
"Module name too long"
);
return
NULL
;
}
strcpy
(
buf
,
Py
String_AS_STRING
(
modname
));
strcpy
(
buf
,
Py
Unicode_AsString
(
modname
));
}
else
{
char
*
start
=
Py
String_AS_STRING
(
modname
);
char
*
start
=
Py
Unicode_AsString
(
modname
);
char
*
lastdot
=
strrchr
(
start
,
'.'
);
size_t
len
;
if
(
lastdot
==
NULL
&&
level
>
0
)
{
...
...
@@ -2174,19 +2165,9 @@ ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
}
return
0
;
}
if
(
PyString_Check
(
item
))
{
/* XXX there shouldn't be any str8 objects here */
PyObject
*
uni
=
PyUnicode_DecodeASCII
(
PyString_AsString
(
item
),
PyString_Size
(
item
),
"strict"
);
Py_DECREF
(
item
);
if
(
!
uni
)
return
0
;
item
=
uni
;
}
if
(
!
PyUnicode_Check
(
item
))
{
PyErr_SetString
(
PyExc_TypeError
,
"Item in ``from list'' not a
unicode
string"
);
"Item in ``from list'' not a string"
);
Py_DECREF
(
item
);
return
0
;
}
...
...
@@ -2444,7 +2425,7 @@ PyImport_ReloadModule(PyObject *m)
done using whatever import hooks are installed in the current
environment, e.g. by "rexec".
A dummy list ["__doc__"] is passed as the 4th argument so that
e.g. PyImport_Import(Py
String
_FromString("win32com.client.gencache"))
e.g. PyImport_Import(Py
Unicode
_FromString("win32com.client.gencache"))
will return <module "gencache"> instead of <module "win32com">. */
PyObject
*
...
...
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