]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
examples:winexe: more efficient C array generation, no py2
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 27 May 2024 23:16:23 +0000 (11:16 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 31 May 2024 00:25:33 +0000 (00:25 +0000)
We don't need to recreate the src array every time, and we don't need
to worry about Python 2 strings.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
examples/winexe/wscript_build

index 364683405c251c6b4c2c5d7c73c6dcd4bbefbb24..a9de34739488a990e939033c60126fc733fe948c 100644 (file)
@@ -17,23 +17,12 @@ def generate_winexesvc_c_from_exe(t):
         return -1
 
     def c_array(src):
-        N = 0
-        result = ''
-        while src:
-            l = src[:8]
-            src = src[8:]
-            # Even files opened in binary mode are read as type "str" in
-            # Python 2, so we need to get the integer ordinal of each
-            # character in the string before we try to convert it to hex.
-            if isinstance(l, str):
-                h = ' '.join(["0x%02X," % ord(x) for x in l])
-            # Files opened in binary mode are read as type "bytes" in
-            # Python 3, so we can convert each individual integer in the
-            # array of bytes to hex directly.
-            else:
-                h = ' '.join(["0x%02X," % x for x in l])
-            result += "\t\t%s\n" % (h)
-        return result
+        result = []
+        for i in range(0, len(src), 8):
+            l = src[i:i+8]
+            h = ' '.join(["0x%02X," % x for x in l])
+            result.append(h)
+        return "\n\t\t".join(result)
 
     src_array = c_array(src_blob)
     if len(src_array) <= 0:
@@ -48,7 +37,7 @@ const DATA_BLOB *%s(void);
 const DATA_BLOB *%s(void)
 {
 \tstatic const uint8_t array[] = {
-%s
+\t\t%s
 \t};
 \tstatic const DATA_BLOB blob = {
 \t\t.data = discard_const_p(uint8_t, array),