diff --git a/KPHP/compiler/bicycle.cpp b/KPHP/compiler/bicycle.cpp
index 7cf972a..d43395e 100644
--- a/KPHP/compiler/bicycle.cpp
+++ b/KPHP/compiler/bicycle.cpp
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with VK/KittenPHP-DB-Engine. If not, see .
- This program is released under the GPL with the additional exemption
+ This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.
@@ -32,7 +32,6 @@ __thread int bicycle_thread_id;
/*** Malloc hooks ***/
#define BICYCLE_MALLOC
-#ifdef BICYCLE_MALLOC
extern "C" {
extern __typeof (malloc) __libc_malloc;
extern __typeof (free) __libc_free;
@@ -147,7 +146,6 @@ void free (void *ptr) {
return zallocator->free (ptr);
}
}
-#endif
int get_thread_id() {
return bicycle_thread_id;
diff --git a/copyexec/copyexec-err.py b/copyexec/copyexec-err.py
old mode 100644
new mode 100755
index c49f2a0..39c482c
--- a/copyexec/copyexec-err.py
+++ b/copyexec/copyexec-err.py
@@ -1,36 +1,53 @@
#!/usr/bin/python
import sys, os
-def header (f):
- f.write ('/* Generated by python script */\n')
+class SuperFile:
+ def __init__(self, name):
+ self.path = os.path.join(sys.path[0], name)
+ self.lines = ['/* Generated by python script */']
+ def __enter__(self):
+ return self
+ def __exit__(self, type, value, traceback):
+ with open(self.path, 'w') as f:
+ f.write('\n'.join(self.lines) + '\n')
+ def append(self, line):
+ self.lines.append(line)
-errors = ['LSEEK', 'READ', 'CRC32', 'TYPE', 'DECRYPT', 'MALLOC', 'ALIGN', 'SIZE', 'SHA1', 'MKDIR', 'OPEN', 'FSTAT']
-errors += ['ST_DEV', 'ST_INO', 'READIN', 'STATUS', 'FORK', 'CHDIR', 'CREAT', 'STAT', 'PUBKEY_PERMISSIONS']
+errors = [
+ 'LSEEK', 'READ', 'CRC32', 'TYPE', 'DECRYPT', 'MALLOC', 'ALIGN', 'SIZE',
+ 'SHA1', 'MKDIR', 'OPEN', 'FSTAT'
+]
+errors += [
+ 'ST_DEV', 'ST_INO', 'READIN', 'STATUS', 'FORK', 'CHDIR', 'CREAT', 'STAT',
+ 'PUBKEY_PERMISSIONS'
+]
errors += ['INVAL']
########### copyexec-results errors ###########
-errors += ['VOLUME_ID_MISMATCHED', 'HOSTNAME_MISMATCHED', 'DISCONNECT', 'OLD_RESULT']
+errors += [
+ 'VOLUME_ID_MISMATCHED', 'HOSTNAME_MISMATCHED', 'DISCONNECT', 'OLD_RESULT'
+]
-e = [(s, -(i+1)) for i, s in enumerate (errors)]
-e.append (('UNKNOWN', -999))
+errors = [(s, -(i+1)) for i, s in enumerate (errors)]
+errors.append (('UNKNOWN', -999))
-f = open (os.path.join (sys.path[0], 'copyexec-err.h'), 'w')
-header (f)
-for s, i in e:
- f.write ('#define COPYEXEC_ERR_' + s + ' (' + str (i) + ')\n')
-f.write ('char *copyexec_strerror (int err);\n')
-f.close ()
-f = open (os.path.join (sys.path[0], 'copyexec-err.c'), 'w')
-header (f)
-f.write ('#include \n')
-f.write ('#include \n')
-f.write ('#include "copyexec-err.h"\n')
-f.write ('char *copyexec_strerror (int err) {\n')
-f.write (' static char buf[64];')
-f.write (' switch (err) {\n')
-for s, i in e:
- f.write (' case COPYEXEC_ERR_' + s + ': return "COPYEXEC_ERR_' + s + '"; break;\n')
-f.write (' default: assert (snprintf (buf, sizeof (buf), "COPYEXEC_ERR_UNKNOWN (%d)", err) < sizeof (buf));\n')
-f.write (' return buf;\n')
-f.write (' }\n')
-f.write ('}\n')
+with SuperFile('copyexec-err.h') as f:
+ # not using `% tuple_ for tuple_ in errors` just for clarity
+ for error_name, error_code in errors:
+ f.append('#define COPYEXEC_ERR_%s (%d)' % (error_name, error_code))
+ f.append('char *copyexec_strerror (int err);')
+
+with SuperFile('copyexec-err.c') as f:
+ f.append('#include ')
+ f.append('#include ')
+ f.append('#include "copyexec-err.h"')
+ f.append('char *copyexec_strerror (int err) {')
+ f.append(' static char buf[64];')
+ f.append(' switch (err) {')
+ for error_name, error_code in errors:
+ f.append(' case COPYEXEC_ERR_%s: return "COPYEXEC_ERR_%s"; break;'
+ % (error_name, error_name))
+ f.append(' default: assert (snprintf (buf, sizeof (buf), "COPYEXEC_ERR_UNKNOWN (%d)", err) < sizeof (buf));')
+ f.append(' return buf;')
+ f.append(' }')
+ f.append('}')