Muennighoff commited on
Commit
9382ca3
1 Parent(s): 2e80bdf
Files changed (1) hide show
  1. execute.py +31 -35
execute.py CHANGED
@@ -100,44 +100,40 @@ def unsafe_execute_cpp(check_program, result, timeout):
100
  with create_tempdir():
101
  open(f"test.cpp", 'w').write(check_program)
102
 
103
- # Run program.
104
- try:
105
- exec_globals = {}
106
-
107
- # -lcrypto & -lssl are needed for the crypto library required by HumanEval-X-Bugs Task 162
108
- compilation_result = subprocess.run(
109
- ["/usr/bin/g++", "-std=c++11", "test.cpp", "-lcrypto", "-lssl"],
110
- timeout=timeout,
111
- capture_output=True,
112
- )
113
- if compilation_result.returncode != 0:
114
- if compilation_result.stderr:
115
- err = compilation_result.stderr.decode()
116
- else:
117
- err = compilation_result.stdout.decode()
118
- result.append(f"failed: compilation error: {err}")
119
  else:
120
- try:
121
- with time_limit(timeout):
122
- exec_result = subprocess.run(["./a.out"], timeout=timeout, capture_output=True)
 
 
 
123
 
124
- if exec_result.returncode == 0:
125
- result.append("passed")
 
 
 
 
 
 
126
  else:
127
- if exec_result.stderr:
128
- try:
129
- err = exec_result.stderr.decode()
130
- except:
131
- err = exec_result.stderr
132
- else:
133
- try:
134
- err = exec_result.stdout.decode()
135
- except:
136
- err = exec_result.stdout
137
- result.append(f"failed: {err}")
138
-
139
- except TimeoutException:
140
- result.append("timed out")
141
 
142
  def unsafe_execute_js(check_program, result, timeout):
143
 
 
100
  with create_tempdir():
101
  open(f"test.cpp", 'w').write(check_program)
102
 
103
+ # -lcrypto & -lssl are needed for the crypto library required by HumanEval-X-Bugs Task 162
104
+ compilation_result = subprocess.run(
105
+ ["/usr/bin/g++", "-std=c++11", "test.cpp", "-lcrypto", "-lssl"],
106
+ timeout=timeout,
107
+ capture_output=True,
108
+ )
109
+ if compilation_result.returncode != 0:
110
+ if compilation_result.stderr:
111
+ err = compilation_result.stderr.decode()
 
 
 
 
 
 
 
112
  else:
113
+ err = compilation_result.stdout.decode()
114
+ result.append(f"failed: compilation error: {err}")
115
+ else:
116
+ try:
117
+ with time_limit(timeout):
118
+ exec_result = subprocess.run(["./a.out"], timeout=timeout, capture_output=True)
119
 
120
+ if exec_result.returncode == 0:
121
+ result.append("passed")
122
+ else:
123
+ if exec_result.stderr:
124
+ try:
125
+ err = exec_result.stderr.decode()
126
+ except:
127
+ err = exec_result.stderr
128
  else:
129
+ try:
130
+ err = exec_result.stdout.decode()
131
+ except:
132
+ err = exec_result.stdout
133
+ result.append(f"failed: {err}")
134
+
135
+ except TimeoutException:
136
+ result.append("timed out")
 
 
 
 
 
 
137
 
138
  def unsafe_execute_js(check_program, result, timeout):
139