Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions layer1/PConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ int PConvPyListToStrVLAList(PyObject * obj, char **vla, int *n_str)
for(i = 0; i < n_st; i++) {
t = PyList_GetItem(obj, i);
if(PyString_Check(t)) {
l = PyString_Size(t);
auto strval = PyString_AsSomeString(t);
l = strval.length();
nn_ch = n_ch + l + 1;
VLACheck(*vla, char, nn_ch);
auto strval = PyString_AsSomeString(t);
UtilNCopy((*vla) + n_ch, strval.c_str(), l + 1);
n_ch = nn_ch;
} else {
Expand Down Expand Up @@ -1159,7 +1159,8 @@ int PConvPyListToStringVLA(PyObject * obj, char **vla_ptr)
for(a = 0; a < l; a++) {
i = PyList_GetItem(obj, a);
if(PyString_Check(i)) {
ll += PyString_Size(i) + 1;
// UTF-8 byte length (PyString_Size counts code points)
ll += PyString_AsSomeString(i).length() + 1;
}
}
vla = VLAlloc(char, ll);
Expand Down
6 changes: 3 additions & 3 deletions layer4/PopUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ Block *PopUpNew(PyMOLGlobals * G, int x, int y, int last_x, int last_y,
continue;
}
elem = PyList_GetItem(item, 1);
l = PyString_Size(elem);
str = PyString_AsString(elem);
cl = l;
l = strlen(str); /* buffer size in UTF-8 bytes */
cl = PyString_Size(elem); /* display width in characters */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to remove the legacy macros and to use PyUnicode_GetLength directly?

# define PyString_Size PyUnicode_GetLength
# define PyString_GET_SIZE PyUnicode_GetLength

c = str;
while(*c) {
if(TextStartsWithColorCode(c)) { /* discount the markup */
Expand All @@ -214,7 +214,7 @@ Block *PopUpNew(PyMOLGlobals * G, int x, int y, int last_x, int last_y,
if (PyList_Size(item) > 2) {
PyObject* command = PyList_GetItem(item, 2);
if(PyString_Check(command)) {
l = PyString_Size(command);
l = strlen(PyString_AsString(command));
if(l > mx)
mx = l;
}
Expand Down
21 changes: 21 additions & 0 deletions testing/tests/wizard/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
unit tests for wizard prompts
'''

from pymol import cmd, testing
from pymol.wizard import Wizard

class TestPrompt(testing.PyMOLTestCase):

def test_NonAsciiPrompt(self):
# github #517: prompt buffer was sized by code points instead of
# UTF-8 bytes, overflowing the heap for multi-byte characters.
# Plain Wizard instead of the message wizard, which prints the
# text and fails on non-UTF-8 consoles (e.g. cp1252 on Windows).
wiz = Wizard()
wiz.prompt = ["Unicode test: " + "测试消息" * 2000]
cmd.set_wizard(wiz)
for _ in range(10):
cmd.refresh_wizard()
self.assertIs(cmd.get_wizard(), wiz)
cmd.set_wizard()
Loading