Commits

ariovistus committed 614c9fb

added build_deimos extension flag
fixed global data linking for ldc.
missed an override for incoming 2.061
initialize pyd.RangeWrapper in extensions.

  • Participants
  • Parent commits 5de7890

Comments (0)

Files changed (22)

File dcompiler.py

     'replace.d',
 ]
 
+_deimosFiles = [
+    'abstract_.d',
+    'ast.d',
+    'boolobject.d',
+    'bufferobject.d',
+    'bytearrayobject.d',
+    'bytesobject.d',
+    'cellobject.d',
+    'ceval.d',
+    'classobject.d',
+    'cobject.d',
+    'codecs.d',
+    'code.d',
+    'compile.d',
+    'complexobject.d',
+    'cStringIO.d',
+    'datetime.d',
+    'descrobject.d',
+    'dictobject.d',
+    'enumobject.d',
+    'errcode.d',
+    'eval.d',
+    'fileobject.d',
+    'floatobject.d',
+    'frameobject.d',
+    'funcobject.d',
+    'genobject.d',
+    'grammar.d',
+    'import_.d',
+    'intobject.d',
+    'intrcheck.d',
+    'iterobject.d',
+    'listobject.d',
+    'longintrepr.d',
+    'longobject.d',
+    'marshal.d',
+    'memoryobject.d',
+    'methodobject.d',
+    'modsupport.d',
+    'moduleobject.d',
+    'node.d',
+    'object.d',
+    'objimpl.d',
+    'parsetok.d',
+    'pgenheaders.d',
+    'pyarena.d',
+    'pyatomic.d',
+    'pycapsule.d',
+    'pydebug.d',
+    'pyerrors.d',
+    'pymem.d',
+    'pyport.d',
+    'pystate.d',
+    'pystrcmp.d',
+    'pystrtod.d',
+    'Python.d',
+    'pythonrun.d',
+    'pythread.d',
+    'rangeobject.d',
+    'setobject.d',
+    'sliceobject.d',
+    'stringobject.d',
+    'structmember.d',
+    'structseq.d',
+    'symtable.d',
+    'sysmodule.d',
+    'timefuncs.d',
+    'traceback.d',
+    'tupleobject.d',
+    'unicodeobject.d',
+    'weakrefobject.d',
+]
+
 _pyVerXDotY = '.'.join(str(v) for v in sys.version_info[:2]) # e.g., '2.4'
 _pyVerXY = _pyVerXDotY.replace('.', '') # e.g., '24'
 
                 sources.append((winpath(source, self.winonly), 'outside'))
 
         # flags = (with_pyd, with_st, with_meta, with_main)
-        with_pyd, with_st, with_meta, with_main = [f for f, category in macros if category == 'aux'][0]
+        with_pyd, with_st, with_meta, with_main, build_deimos = [f for f, category in macros if category == 'aux'][0]
         # And Pyd!
         if with_pyd:
             # If we're not using StackThreads, don't use iteration.d in Pyd
                         " missing." % filePath
                     )
                 sources.append((winpath(filePath,self.winonly), 'infra'))
+        if build_deimos:
+            for file in _deimosFiles:
+                filePath = os.path.join(_infraDir, 'deimos', 'python', file)
+                if not os.path.isfile(filePath):
+                    raise DistutilsPlatformError("Required deimos header "
+                        "file '%s' is missing." % filePath
+                    )
+                sources.append((winpath(filePath,self.winonly), 'infra'))
         # If using PydMain, parse the template file
         if with_main:
             name = [n for n, category in macros if category == 'name'][0]

File examples/arraytest/makefile

 all: 
 	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
 	cat setup.py >> tsetup.py
-	python tsetup.py build
+	python tsetup.py build --compiler=ldc
 
 clean:
 	rm -rf build

File examples/arraytest/setup.py

     name=projName,
     version='0.1',
     ext_modules=[
-        Extension(projName, ['arraytest.d'])
+        Extension(projName, ['arraytest.d'], build_deimos=True)
     ],
 )

File examples/deimos_unittests/makefile

 	     -version=Python_2_5_Or_Later \
 	     -version=Python_2_4_Or_Later \
 	     -L-lpython2.7
-DC = dmd -unittest -property -debug -gc
+PYTHON_2_7_LDC = -d-version=Python_2_7_Or_Later \
+             -d-version=Python_2_6_Or_Later \
+	     -d-version=Python_2_5_Or_Later \
+	     -d-version=Python_2_4_Or_Later \
+	     -L-lpython2.7
+PYD_FILES = $(shell find $(PYD_DIR)/deimos/ -name \*.d )
+DC = dmd -unittest -property -debug -gc 
+LDC = ldc2 -unittest -property -d-debug=1 -gc 
 
 all: object_.x
 
 	rm -f *.o
 
 %.x: %.d
-	$(DC) $(PYTHON_2_7) $< -of$@  -I$(PYD_DIR)
+	#$(DC) $(PYTHON_2_7) $< -of$@  -I$(PYD_DIR)
+	$(LDC) -of $@ $(PYTHON_2_7_LDC) $< -I$(PYD_DIR) $(PYD_FILES)
+

File examples/deimos_unittests/object_.d

 import std.string;
 
+import std.stdio;
 import deimos.python.Python;
 
 shared static this() {
     // breaks linking?
     Py_XINCREF(Py_None());
     // breaks linking?
-    Py_XDECREF(cast(PyObject*) null);
+    Py_XDECREF(cast(PyObject*) Py_None());
     // breaks linking?
     PyObject_TypeCheck(cast(PyObject*) Py_None(), &PyType_Type);
     

File examples/hello/makefile

 all: 
 	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
-	cat setup.py >> tsetup.py
-	python tsetup.py build
-	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
-	cat setup2.py >> tsetup.py
-	python tsetup.py build
+	cat setup.py >> tsetup.py 
+	python tsetup.py build --compiler=ldc
+	#echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
+	#cat setup2.py >> tsetup.py
+	#python tsetup.py build
 
 clean:
 	rm -rf build

File examples/hello/setup.py

     name=projName,
     version='0.1',
     ext_modules=[
-        Extension(projName, ['hello.d'])
+    Extension(projName, ['hello.d'],
+        build_deimos=True,
+        )
     ],
 )

File examples/inherit/makefile

 all: 
 	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
 	cat setup.py >> tsetup.py
-	python tsetup.py build
+	python tsetup.py build --compiler=ldc
 
 clean:
 	rm -rf build

File examples/inherit/setup.py

     name=projName,
     version='0.1',
     ext_modules=[
-        Extension(projName, ['inherit.d'])
+        Extension(projName, ['inherit.d'], build_deimos=True)
     ],
 )

File examples/pyind/makefile

 PYD_FILES = $(shell find ../../infrastructure/pyd/ -name \*.d) \
 $(shell find ../../infrastructure/meta/ -name \*.d) \
 $(shell find ../../infrastructure/util/ -name \*.d) 
+DEIMOS_FILES = $(shell find ../../infrastructure/deimos/ -name \*.d) 
+PYTHON_2_7_LDC = -d-version=Python_2_7_Or_Later \
+             -d-version=Python_2_6_Or_Later \
+	     -d-version=Python_2_5_Or_Later \
+	     -d-version=Python_2_4_Or_Later \
+	     -L-lpython2.7
 PYTHON_2_7 = -version=Python_2_7_Or_Later \
              -version=Python_2_6_Or_Later \
 	     -version=Python_2_5_Or_Later \
 	     -version=Python_2_4_Or_Later \
 	     -L-lpython3.2mu
 DC = dmd -m64 -unittest -property -debug  
+LDC = ldc2 -unittest -property 
 #DC = ldmd2 -unittest -property -debug -gc
 all: pyind pyind3
 clean:
 	$(DC) $(PYTHON_3_2) $(PYD_FILES) $^ -of$@ -I../../infrastructure/ 
 pyind: pyind.d
 	$(DC) $(PYTHON_2_7) $(PYD_FILES) $^ -of$@ -I../../infrastructure/ 
+	#$(LDC) $(PYTHON_2_7_LDC) $(PYD_FILES) $(DEIMOS_FILES) $^ -of $@ -I../../infrastructure/

File examples/pyind/pyind.d

             def!(knock, ModuleName!"office", 
                 Docstring!"a brain specialist works here")(); 
             add_module!(ModuleName!"office")();
-            });
+    });
     py_init();
 
     wrap_class!(Y, 

File examples/pyind/pyind3.d

 
 static this() {
     on_py_init({
-            def!(knock, ModuleName!"office", Docstring!"a brain specialist works here")(); 
+            def!(knock, ModuleName!"office", 
+                Docstring!"a brain specialist works here")(); 
             add_module!(ModuleName!"office")();
     });
+
     on_py_init({
     wrap_class!(Y, 
         Def!(Y.query),
         Property!(Y.resolution, Mode!"r"),
     )();
     }, PyInitOrdering.After);
+
     py_init();
 }
 

File examples/rawexample/makefile

 all: 
 	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
 	cat setup.py >> tsetup.py
-	python tsetup.py build
+	python tsetup.py build --compiler=ldc
 
 clean:
 	rm -rf build

File examples/rawexample/setup.py

     name=projName,
     version='0.1',
     ext_modules=[
-        Extension(projName, ['rawexample.d'], raw_only=True)
+        Extension(projName, ['rawexample.d'], raw_only=True, build_deimos=True)
     ],
 )

File examples/testdll/makefile

 all: 
 	echo 'import sys; sys.path.append("../../build/lib/");' > tsetup.py
 	cat setup.py >> tsetup.py
-	python tsetup.py build 
+	python tsetup.py build --compiler=ldc
 
 clean:
 	rm -rf build

File examples/testdll/setup.py

     name=projName,
     version='0.1',
     ext_modules=[
-        Extension(projName, [projName + '.d'])
+        Extension(projName, [projName + '.d'], build_deimos=True)
     ],
   )

File infrastructure/deimos/python/pyport.d

     alias int Py_ssize_t;
 }
 
+version(linux) version(DigitalMars) version = dmd_linux;
 template PyAPI_DATA(string decl) {
-    version(Windows) {
-    enum PyAPI_DATA = (q{
-        extern(C)
-        extern
-        export
-        __gshared
-    } ~ decl ~ ";");
+    
+    version(dmd_linux) {
+        // has to be special
+
+        // todo: why does ldc/linux not work this way? 
+        //  --export-dynamic seems not to change anything
+        enum PyAPI_DATA = (q{
+            extern(C)
+            __gshared
+        } ~ decl ~ ";");
     }else{
-    // todo: check that extern export doesn't break linux build somehow
-    enum PyAPI_DATA = (q{
-        extern(C)
-        __gshared
-    } ~ decl ~ ";");
+        enum PyAPI_DATA = (q{
+            extern(C)
+            extern
+            export
+            __gshared
+        } ~ decl ~ ";");
     }
 }

File infrastructure/pyd/class_wrap.d

 import std.functional;
 import std.metastrings;
 import std.typetuple;
-import std.string: format;
+import std.string: format = xformat;
 import std.typecons: Tuple;
 import util.typelist;
 import util.multi_index;
             }
             static if(countUntil(parts.mode, "w") != -1) {
                 enum setter = Replace!(q{
-                ReturnType!(__pyd_p$i.set_t) $realname(ParameterTypeTuple!(__pyd_p$i.set_t) t) {
+                override ReturnType!(__pyd_p$i.set_t) $realname(ParameterTypeTuple!(__pyd_p$i.set_t) t) {
                     return __pyd_get_overload!("$realname", __pyd_p$i.set_t).func("$name", t);
                 }
                 }, "$i", i, "$realname",realname, "$name", pyname);

File infrastructure/pyd/exception.d

 module pyd.exception;
 
 import std.conv;
+import std.string: format = xformat;
 import std.string;
 import deimos.python.Python;
 import meta.Nameof : prettytypeof;

File infrastructure/pyd/make_object.d

 
 
 shared static this() {
+    init_rangewrapper();
+}
+
+void init_rangewrapper() {
     on_py_init( {
             add_module!(
                 ModuleName!"pyd", 
                 ModuleName!"pyd",
                 Def!(RangeWrapper.iter, PyName!"__iter__"),
                 Def!(RangeWrapper.next))();
+            rangeWrapperInited = true;
             }, PyInitOrdering.After);
 }
 
+bool rangeWrapperInited = false;
+
 class to_conversion_wrapper(dg_t) {
     alias ParameterTypeTuple!(dg_t)[0] T;
     alias ReturnType!(dg_t) Intermediate;
 T python_to_d(T) (PyObject* o) {
     // This ordering is somewhat important. The checks for Tuple and Complex
     // must be before the check for general structs.
+    version(PydPythonExtension) {
+        // druntime doesn't run module ctors :(
+        if(!rangeWrapperInited) {
+            init_rangewrapper();
+        }
+    }
 
     static if (is(PyObject* : T)) {
         return o;

File infrastructure/pyd/op_wrap.d

 
 import std.algorithm: startsWith, endsWith;
 import std.traits;
+import std.exception: enforce;
+import std.string: format = xformat;
 import std.conv: to;
 import pyd.class_wrap;
 import pyd.func_wrap;
             kwargs['with_main'] = False
             del kwargs['raw_only']
         with_pyd  = kwargs.pop('with_pyd', True)
+        build_deimos = kwargs.pop('build_deimos', False)
         with_st   = kwargs.pop('with_st', False) # 5/23/07 st off by default.
         # StackThreads doesn't work with Tango at the moment.
         if with_tango:
             # The special PydMain function should only be used when using Pyd
             with_main = False
 
-        define_macros.append(((with_pyd, with_st, with_meta, with_main), 'aux'))
+        define_macros.append(((with_pyd, with_st, with_meta, with_main, build_deimos), 'aux'))
 
         std_Extension.__init__(self, *args, **kwargs)