Skip to content

Commit

Permalink
Fixes for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
brianegge committed Dec 9, 2024
1 parent 9dcd38f commit ca7f113
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM mcr.microsoft.com/vscode/devcontainers/base:jammy
FROM mcr.microsoft.com/devcontainers/base:dev-ubuntu-22.04

# These dependencies are required by Nix.
RUN apt update -y
RUN apt -y install --no-install-recommends curl xz-utils cmake libreadline-dev libncurses-dev llvm-12 llvm-12-dev ack
RUN apt -y install --no-install-recommends curl xz-utils cmake libreadline-dev libncurses-dev llvm-12 llvm-12-dev
RUN [ -e /usr/bin/gmake ] || sudo ln -s /usr/bin/make /usr/bin/gmake

# Install Nix
ARG NIX_INSTALL_SCRIPT=https://github.com/nix-community/nix-unstable-installer/releases/download/nix-2.23.0pre20240603_da92ad7/install
# Install Nix
ARG NIX_INSTALL_SCRIPT=https://nixos.org/nix/install
RUN curl -L ${NIX_INSTALL_SCRIPT} | sudo -u vscode NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh

# Configuration for Nix from the repository shared amongst developers.
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/podman/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"containerEnv": {
"HOME": "/home/vscode"
},
"mounts": [
"type=bind,readonly,source=/etc/localtime,target=/etc/localtime"
],
"customizations": {
"vscode": {
"extensions": [
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.sw?
/build/
scripts/*.pyc
__pycache__/
*.py[cod]
CMakeCache.txt
CMakeFiles/
/doc/en/_build/
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ elseif(${LLVM_PACKAGE_VERSION} VERSION_LESS "11.0")
else()
set(jit_lib mcjit orcjit)
endif()
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(llvm_arch_lib x86)
ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(llvm_arch_lib aarch64)
ENDIF()

find_program(llvm-config llvm-config PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
find_program(llvm-config llvm-config)
message(STATUS "Using LLVM config: ${llvm-config}")
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "4.0")
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib}
execute_process(COMMAND ${llvm-config} --libs ipo ${llvm_arch_lib} ${jit_lib}
OUTPUT_VARIABLE llvm_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${llvm-config} --ldflags
Expand All @@ -46,7 +51,7 @@ if (${LLVM_PACKAGE_VERSION} VERSION_LESS "4.0")
OUTPUT_VARIABLE sys_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib} --link-static
execute_process(COMMAND ${llvm-config} --libs ipo ${llvm_arch_lib} ${jit_lib} --link-static
OUTPUT_VARIABLE llvm_libs
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
Expand Down
63 changes: 59 additions & 4 deletions include/hobbes/storage.H
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,69 @@ static inline unsigned spin(unsigned count) {
return (count << 1);
}

#if defined(__aarch64__)
//https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2arm64_2include_2asm_2cmpxchg_8h_source.html
#define uxchg(ptr,x) \
__xchg((x),(ptr),sizeof(*(ptr)))

static inline void __xchg(volatile unsigned long x, volatile void *ptr, std::size_t size)
{
unsigned long ret, tmp;

switch (size) {
case 1:
asm volatile("// __xchg1\n"
"1: ldaxrb %w0, [%3]\n"
" stlxrb %w1, %w2, [%3]\n"
" cbnz %w1, 1b\n"
: "=&r" (ret), "=&r" (tmp)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
case 2:
asm volatile("// __xchg2\n"
"1: ldaxrh %w0, [%3]\n"
" stlxrh %w1, %w2, [%3]\n"
" cbnz %w1, 1b\n"
: "=&r" (ret), "=&r" (tmp)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
case 4:
asm volatile("// __xchg4\n"
"1: ldaxr %w0, [%3]\n"
" stlxr %w1, %w2, [%3]\n"
" cbnz %w1, 1b\n"
: "=&r" (ret), "=&r" (tmp)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
case 8:
asm volatile("// __xchg8\n"
"1: ldaxr %0, [%3]\n"
" stlxr %w1, %2, [%3]\n"
" cbnz %w1, 1b\n"
: "=&r" (ret), "=&r" (tmp)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
default:
assert(0);
}
}
#else
static inline void uxchg(volatile uint32_t* px, uint32_t nx) {
__asm__ __volatile__(
"xchgl %0,%1"
:"=r" (nx)
:"m" (*px), "0" (nx)
:"memory"
"1: ldxr %w0, [%1]\n"
" stxr w2, %w3, [%1]\n"
" cbnz w2, 1b\n"
: "=&r" (nx)
: "r" (px), "r" (nx)
: "memory", "w2"
);
}
#endif

#define xchg __sync_lock_test_and_set

// define a local socket for registering new storage queues
Expand Down
42 changes: 22 additions & 20 deletions scripts/fregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __str__(self):
return "{}".format(self.fn(*self.args, **self.kw))

def reader(self):
return self.fn.im_self
return self.fn.__self__

def LazyRead(enable):
"""
Expand Down Expand Up @@ -302,7 +302,7 @@ def freeVars(ty):
return m
def dictFreeVars(m):
lm={}
for n, ty in m.items():
for n, ty in list(m.items()):
freeVarsInto(lm,ty)
return lm
def freeName(m):
Expand Down Expand Up @@ -358,7 +358,7 @@ def substituteInAbs(m,a):
def substitute(m,ty):
tyDisp = {
"prim": lambda p: Prim(p.name,substitute(m,p.rep)) if (p.rep != None) else p,
"var": lambda v: m[v.name] if (v.name in m.keys()) else v,
"var": lambda v: m[v.name] if (v.name in list(m.keys())) else v,
"farr": lambda fa: FixedArr(substitute(m,fa.ty), substitute(m,fa.tlen)),
"arr": lambda a: Arr(substitute(m,a.ty)),
"variant": lambda v: substituteInVariant(m,v),
Expand Down Expand Up @@ -532,7 +532,7 @@ def decodeLong(d, p):

def decodeStr(d, p):
n = decodeLong(d,p)
s = str(d[p.pos:p.pos+n])
s = (d[p.pos:p.pos+n]).decode("utf-8")
p.pos += n
return s

Expand Down Expand Up @@ -670,7 +670,7 @@ def __init__(self, fpath):

# if reading the old format, we need to reinterpret recorded types
if (self.version == 1):
for vn, b in self.env.items():
for vn, b in list(self.env.items()):
b.ty = V1toV2Type(b.ty)

# read page data entries into the 'pages' argument
Expand Down Expand Up @@ -710,7 +710,7 @@ def readEnvRecord(self, env, offset):
vnlen = struct.unpack('Q', self.m[offset:offset+8])[0]
offset += 8

vn = str(self.m[offset:offset+vnlen])
vn = (self.m[offset:offset+vnlen]).decode("utf-8")
offset += vnlen

tylen = struct.unpack('Q', self.m[offset:offset+8])[0]
Expand Down Expand Up @@ -821,7 +821,8 @@ def read(self,m,offset):
if (t == 0):
return None
else:
return self.jr.read(m,offset+self.poff)
x = self.jr.read(m,offset+self.poff)
return x

class EnumView:
def __init__(self, ns, t):
Expand Down Expand Up @@ -879,7 +880,7 @@ def __init__(self):
self.nr = UnpackReader('Q',8)
def read(self,m,offset):
n=self.nr.read(m,offset)
return m[offset+8:offset+8+n]
return m[offset+8:offset+8+n].decode("utf-8")

class ArrReaderGenerator:
def __init__(self, m, reader, size, offset):
Expand All @@ -894,13 +895,13 @@ def __len__(self):

def __call__(self):
o = self.offset
for i in xrange(0, self.size):
for i in range(0, self.size):
tv = self.get(i)
o += self.vlen
yield(tv)

def __getitem__(self, i):
if not isinstance(i, (int,long)):
if not isinstance(i, int):
raise StopIteration
return self.get(i)

Expand Down Expand Up @@ -969,7 +970,7 @@ def makeArrReader(renv,a):
def makeVariantReader(renv,v):
if (len(v.ctors)==2 and v.ctors[0][0] == ".f0" and v.ctors[0][1] == 0 and isinstance(v.ctors[0][2],Prim) and v.ctors[0][2].name == "unit"):
return MaybeReader(renv,v.ctors[1][2])
elif (all(map(lambda c: isinstance(c[2],Prim) and c[2].name=="unit", v.ctors))):
elif (all([isinstance(c[2],Prim) and c[2].name=="unit" for c in v.ctors])):
return EnumReader(v.ctors)
else:
return VariantReader(renv,v.ctors)
Expand All @@ -978,9 +979,9 @@ def makeStructReader(renv,s):
if (len(s.fields) == 0):
return UnitReader()
elif (s.fields[0][0][0] == '.'): # should we read this as a tuple?
return TupleReader(renv, map(lambda f:f[2], s.fields))
return TupleReader(renv, [f[2] for f in s.fields])
else:
return StructReader(renv, map(lambda f:f[0], s.fields), map(lambda f:f[2], s.fields))
return StructReader(renv, [f[0] for f in s.fields], [f[2] for f in s.fields])

def makeAppReader(renv,app):
if (isinstance(app.f,Prim)):
Expand Down Expand Up @@ -1064,7 +1065,7 @@ class FRegion:
def __init__(self, fpath):
self.rep = FREnvelope(fpath)

for vn, bind in self.rep.env.items():
for vn, bind in list(self.rep.env.items()):
bind.reader = makeReader({}, bind.ty)

@staticmethod
Expand All @@ -1077,10 +1078,10 @@ def __repr__(self):
vns = []
hts = []
tds = []
for vn, bind in self.rep.env.items():
for vn, bind in list(self.rep.env.items()):
vns.append(vn)
hts.append(' :: ')
tds.append(str(bind.ty))
tds.append((bind.ty).decode("utf-8"))
return tableFormat([vns, hts, tds])

def __getattr__(self, attr):
Expand Down Expand Up @@ -1133,7 +1134,8 @@ def read(self,m,offset):
if (o==0):
return None
else:
return self.r.read(m,o)
x = self.r.read(m,o)
return x

# carrays (variable-length arrays stored with a static capacity)
FRegion.addType("carray", lambda renv, ty, repty: makeArrReader(renv, Arr(ty.args[0])))
Expand Down Expand Up @@ -1178,7 +1180,7 @@ def __contains__(self,k):
if (self.sl.count==0):
return False
else:
n=SLView.findNextGLEB(self.sl.root, len(self.sl.root.next)-1, k)
n=SLView.findNextGLEB(self.sl.root, len(self.sl.root.__next__)-1, k)
return (not(n==None) and n.key==k)
def __iter__(self):
n=self.sl.root.next[0]
Expand All @@ -1193,9 +1195,9 @@ def __repr__(self):
vs=[]
n=self.sl.root().next[0]
while (not(n == None)):
ks.append(str(n.key))
ks.append(n.key.decode("utf-8"))
eqs.append(' = ')
vs.append(str(n.value))
vs.append(n.value.decode("utf-8"))
n=n.next[0]
return tableFormat([ks,eqs,vs])

Expand Down
9 changes: 6 additions & 3 deletions test/Python.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public:
PythonProc(const std::string& py, const std::string& moddir, const std::string& script, const std::string& db) : py(py), moddir(moddir), script(script), db(db)
{
if(this->py.empty())
this->py = "/usr/bin/python"; // Give a default python execute path
this->py = "/usr/bin/python3"; // Give a default python execute path
this->argv.push_back(this->py.c_str());
this->argv.push_back(this->script.c_str());
this->argv.push_back(this->db.c_str());
Expand Down Expand Up @@ -246,8 +246,11 @@ def explode(s):
r.append(s[i])
return r

expectCB=explode('chickens')
if (f.cbuffer[0:len(expectCB)] != expectCB):
expectCB='chickens'
if (b''.join(f.cbuffer[0:len(expectCB)]).decode('utf-8') != expectCB):
from pprint import pprint
pprint(f.cbuffer[0:len(expectCB)])
pprint(expectCB)
print("Expected 'cbuffer' to equal 'chickens': " + str(f.cbuffer))
sys.exit(-1)

Expand Down

0 comments on commit ca7f113

Please sign in to comment.