Skip to content

Commit 3a900f9

Browse files
authored
Add a primitive to use PyUnicode_Append (mypyc/mypyc#686)
PyUnicode_Append tries to reuse the string instead of creating a new one (using refcount abuse). I did a manual test that it works but it isn't anything I'd want to add to the test suite.
1 parent 82ce38f commit 3a900f9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mypyc/ops_str.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
error_kind=ERR_MAGIC,
2525
emit=simple_emit('{dest} = PyUnicode_Concat({args[0]}, {args[1]});'))
2626

27+
# PyUnicodeAppend makes an effort to reuse the LHS when the refcount
28+
# is 1. This is super dodgy but oh well, the interpreter does it.
29+
binary_op(op='+=',
30+
arg_types=[str_rprimitive, str_rprimitive],
31+
steals=[True, False],
32+
result_type=str_rprimitive,
33+
error_kind=ERR_MAGIC,
34+
emit=simple_emit('{dest} = {args[0]}; PyUnicode_Append(&{dest}, {args[1]});'))
35+
2736

2837
def emit_str_compare(comparison: str) -> Callable[[EmitterInterface, List[str], str], None]:
2938
def emit(emitter: EmitterInterface, args: List[str], dest: str) -> None:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy