ccbuluo / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

empty string assignment produces garbage #260

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. a = ''   # empty string
2. len( a)  # or simply print a

What is the expected output? What do you see instead?
CPython will return 0 (len) or print an empty string
Pymite returns a random length string (based on current RAM buffer contents, 
likely parts of marshalled cob)

What version of the product are you using? On what operating system?
Darwin and PIC32 platforms

Please provide any additional information below.
The string_new macro calls string_create() in strobe.c  passing len = 0.
Unfortunately string_create interprets a len parameter ==0 as a flag to invoke 
the sli_strlen() function to detect a C string length

Proposed solution: pass a separate flag to string_create to indicate a C string 
is given and/or separate completely the string_create cases (with len vs. w/o 
length

Original issue reported on code.google.com by lucio.di...@googlemail.com on 22 Jun 2014 at 7:58

GoogleCodeExporter commented 9 years ago
The attached patch solves the problem by splitting the CreateNewString in two 
cases removing the ambiguity on the len=0 parameter case
Tested on Darwin 

Original comment by lucio.di...@googlemail.com on 11 Oct 2014 at 3:22

Attachments: