Commits

Maciej Fijalkowski  committed 428edf0

independence from the directory where it's run

  • Participants
  • Parent commits 95d9518

Comments (0)

Files changed (3)

File pypyembed/embed.py

 
 from ctypes import py_object, addressof, CDLL, c_long, c_char_p, c_int,\
      POINTER, cast, c_char
-import inspect, numpy
+import inspect, numpy, os
 
-pypy = CDLL('./libpypy-c.so')
+dirpath = os.path.abspath(os.path.dirname(__file__))
+pypy = CDLL(os.path.join(dirpath, 'libpypy-c.so'))
 pypy_main_startup = pypy.pypy_main_startup
 pypy_main_startup.argtypes = (c_int, c_char_p * 3)
 pypy_main_startup.restype = c_int
 def addr(obj):
     return addressof(py_object(obj))
 
-pypy_prepare_function(open('inner.py').read())
+pypy_prepare_function('__dir__ = "%s"\n' % dirpath + open(os.path.join(dirpath, 'inner.py')).read())
 
 def wrap(arg):
     if not isinstance(arg, numpy.ndarray):

File pypyembed/example.py

 
+import numpy
 from embed import export_function
 
 @export_function
     return numpy.arange(size)
 
 print returning_numarray(100)
+
+@export_function
+def passing_numarray_multidim(a):
+    s = 0
+    for i in range(a.shape[0]):
+        for j in range(a.shape[1]):
+            s += a[i, j]
+    return s
+
+print passing_numarray_multidim(numpy.arange(100).reshape(10, 10))

File pypyembed/inner.py

 
+import os
 import traceback, sys
 try:
     import ctypes
         return func
 
     eci = ExternalCompilationInfo(
-        separate_module_files=('emb.c',),
+        separate_module_files=(os.path.join(__dir__, 'emb.c'),),
         include_dirs=['/usr/include/python2.6'],
     )
     soname = eci.compile_shared_lib().libraries[0]