Skip to content

Commit 26ce615

Browse files
committed
Fix to string utils.
1 parent bb8bd26 commit 26ce615

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

cefpython/cef1/windows/binaries/cefadvanced.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ <h3>Javascript bindings</h3>
181181
<h4>Passing arguments</h4>
182182

183183
<a href="javascript:alert('Return value from python.Test1: '+python.Test1(100))">python.Test1(100)</a><br>
184-
<a href="javascript:alert('Return value from python.Test2: '+JSON.stringify(python.Test2(100, 'This string was passed from javascript')))">python.Test2(100, 'This string was passed from javascript')</a> - python.Test2() should return: [1,2, [2.1, {'3': 3, '4': [5,6]}]]
184+
<a href="javascript:alert('Return value from python.Test2: '+JSON.stringify(python.Test2(100, 'This string was passed from javascript', '')))">python.Test2(100, 'This string was passed from javascript', '')</a> - python.Test2() should return: [1,2, [2.1, {'3': 3, '4': [5,6]}]]
185185
<br><br>
186186

187187
<script>var array = [1]; array[100] = 100.01;</script>

cefpython/cef1/windows/binaries/cefadvanced.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ def Test1(self, arg1):
363363
print("python.Test1(%s) called" % arg1)
364364
return "This string was returned from python function python.Test1()"
365365

366-
def Test2(self, arg1, arg2):
367-
print("python.Test2(%s, %s) called" % (arg1, arg2))
366+
def Test2(self, arg1, arg2, arg3):
367+
print("python.Test2(%s, '%s', '%s') called" % (arg1, arg2, arg3))
368368
# Testing nested return values.
369-
return [1,2, [2.1, {'3': 3, '4': [5,6]}]]
369+
return [1,2, [2.1, {'3': 3, '4': [5,6]}], '']
370370

371371
def PrintPyConfig(self):
372372
print("python.PrintPyConfig(): %s" % (

cefpython/paint_buffer.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ cdef class PaintBuffer:
2424
cdef py_bool dest_alloced = False
2525
cdef object ret
2626

27+
origin = origin.lower()
28+
mode = mode.lower()
2729
assert origin in ("top-left", "bottom-left"), "Invalid origin"
2830
assert mode in ("bgra", "rgba"), "Invalid mode"
2931

cefpython/string_utils.pyx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ ELSE:
88
cdef int wchar_t_size = 4
99

1010
cdef void CharToWidechar(char* charString, wchar_t* wideString, int wideSize):
11-
cdef int copiedChars = MultiByteToWideChar(
11+
cdef int copiedCharacters = MultiByteToWideChar(
1212
CP_UTF8, 0, charString, -1, wideString, wideSize)
13+
# MultiByteToWideChar does not include the NULL character
14+
# when 0 bytes are written.
15+
if wideSize > 0 and copiedCharacters == 0:
16+
wideString[0] = <wchar_t>0;
1317

1418
cdef str CharToPyString(
1519
char* charString):
@@ -27,15 +31,17 @@ cdef str WidecharToPyString(
2731
wchar_t* wcharString):
2832
cdef int charBytes = WideCharToMultiByte(
2933
CP_UTF8, 0, wcharString, -1, NULL, 0, NULL, NULL)
34+
assert charBytes > 0, "WideCharToMultiByte() returned 0"
3035

31-
# When CefString is an empty string, WideCharToMultiByte
32-
# returns 0 bytes, it does not include the NUL character,
33-
# so we need to use calloc instead of malloc.
34-
35-
cdef char* charString = <char*>calloc(charBytes, sizeof(char))
36+
cdef char* charString = <char*>malloc(charBytes * sizeof(char))
3637
cdef int copiedBytes = WideCharToMultiByte(
3738
CP_UTF8, 0, wcharString, -1, charString, charBytes, NULL, NULL)
3839

40+
# WideCharToMultiByte does not include the NULL character
41+
# when 0 bytes are written.
42+
if copiedBytes == 0:
43+
charString[0] = <char>0;
44+
3945
cdef str pyString = CharToPyString(charString)
4046
free(charString)
4147
return pyString

0 commit comments

Comments
 (0)