dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[DotGNU]Evil, Sick, and Wrong


From: Glenn Chambers
Subject: [DotGNU]Evil, Sick, and Wrong
Date: Thu, 12 Dec 2002 22:07:27 -0500

(which is what a former coworker said when one of us came up with stuff like this.)

I've been playing with a couple of my favorite toys, and came up with this as a
'proof-of-concept':

address@hidden pnetjava]$ ./doIt
Hello, C#
Hello, Java
address@hidden pnetjava]$

The admitted kludged details are as follows.

Using the latest released Portable.Net, and the latest released GCC (3.2.1), with
the latter configured with '--enable-threads=pthreads --enable-
languages=c++,java',
you can build a copy of "ilrun" that includes a (compiled!) Java runtime environment.

Sources are shown below, for your amusement or disgust. The patch that converts
'ilrun.c' into 'iljrun.c' is also appended.

I've gotten as far as verifying that the output happens properly. I have not yet confirmed or denied that (1) the garbage collector or (2) the libffi library are compatible between the two systems. Rhys imported Portable.Net's libffi library from libgcj recently, but I don't know if the two have diverged. The garbage collectors are both versions of the Boehm collector, but again, I don't know yet
if they're really compatible.

The biggest 'crock' here is using Pnet's libffi and Boehm collector headers with libgcj's libraries. I should probably use libgcj's instead. Doing that properly
would require convincing the gcc team to install them.

We now return you to your regularly scheduled lives.

Glenn Chambers
Toledo, OH

- - - Snip - - -

2002-12-12 21:20                      ./doIt                      Page 1

#! /bin/bash
export LD_LIBRARY_PATH=`pwd`
./iljrun hello.exe

2002-12-12 21:39                    ./hello.cs                    Page 1

namespace Sample {
  using System;
  using System.Runtime.InteropServices;

  class Hello {
    [DllImport("libiljava.so")]
    extern public static void HelloJava();

    private static void Main() {
      System.Console.WriteLine("Hello, C#");
      HelloJava();
    }
  }
}

2002-12-12 21:38                   ./iljava.cc                    Page 1

#include <gcj/cni.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>

void init_java() {
  JvCreateJavaVM(NULL);
  JvAttachCurrentThread(NULL, NULL);
}

extern "C" {
  void HelloJava() {
    using namespace java::lang;

    System::out->println(JvNewStringLatin1("Hello Java"));
  }
}

2002-12-12 21:11                   ./iljmain.cc                   Page 1

#include <gcj/cni.h>

extern void init_java(void);

extern "C" {
  extern int clr_main(int argc, char **argv);
}

int main(int argc, char *argv[]) {
  init_java();

  int i = clr_main(argc, argv);

  return i;
}

2002-12-12 21:19                    ./Makefile                    Page 1

all:    iljrun hello.exe

clean:
        rm -f iljrun.o iljmain.o iljrun iljava.o libiljava.so hello.exe

iljrun: iljrun.o iljmain.o libiljava.so
        g++ -g -o iljrun iljrun.o iljmain.o -L/usr/local/lib \
                -lILEngine -lILDumpAsm -lILImage \
                -lILSupport -lnsl -ldl -lm  -lpthread libiljava.so

libiljava.so:   iljava.o
        g++ -shared -o libiljava.so iljava.o -lgcj

iljmain.o:      iljmain.cc
        g++ -g -c iljmain.cc

iljava.o:       iljava.cc
        g++ -g -c iljava.cc

iljrun.o:       iljrun.c
        gcc -I /usr/local/include/pnet \
                -I/home/glenn/pnet/pnet-0.4.7/libffi/include -fno-gcse \
                -I../include -c iljrun.c

hello.exe:      hello.cs
        cscc -o hello.exe hello.cs

*** iljrun.c    Sat Dec  7 20:44:06 2002
--- ../pnet/pnet-0.4.7/engine/ilrun.c   Thu Nov 21 20:32:43 2002
***************
*** 18,27 ****
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   */

! #include <il_engine.h>
! #include <il_system.h>
! #include <il_image.h>
! #include <il_utils.h>
  #if HAVE_UNISTD_H
  #include <unistd.h>
  #endif
--- 18,27 ----
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   */

! #include "il_engine.h"
! #include "il_system.h"
! #include "il_image.h"
! #include "il_utils.h"
  #if HAVE_UNISTD_H
  #include <unistd.h>
  #endif
***************
*** 102,108 ****
  static void usage(const char *progname);
  static void version(void);

! int clr_main(int argc, char *argv[])
  {
        char *progname = argv[0];
        unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE;
--- 102,108 ----
  static void usage(const char *progname);
  static void version(void);

! int main(int argc, char *argv[])
  {
        char *progname = argv[0];
        unsigned long heapSize = IL_CONFIG_GC_HEAP_SIZE;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]