Re: building shared libraries for native
Hi Craig, No, you don't need to compile with -O to build a shared object. But you *do* need to compile with -fpic to get position-independent code. Then use -shared when loading the object, as you already do. I have successfully built a number of shared objects using no other special options (for use with Tcl rather than Java, but that should make no difference). BTW to save renaming a.out, use "-o .so" Cheers ... Duncan. On Fri, May 22, 1998 at 11:48:05PM -, Felix Morley Finch wrote: > >>In article <[EMAIL PROTECTED]>, Craig E Rasmussen ><[EMAIL PROTECTED]> writes: > > > I'm having trouble getting native calls to work. I'm using JDK-1.1.3 > > and the simple HelloWorld example segfaults. My guess is that the > > problem is that I'm not creating the shared objects correctly. I'm > > using gcc with the -shared option to create an a.out file which I rename > > to libhello.so. I think this is not the right thing to do. > > I have no idea if or why, but I was told you need to optimize to make > a dynamic library. Add -O and see if that helps any.
Re: building shared libraries for native
Hi Craig, "info gcc" describes this better. It states that FPIC only makes a difference on the m68k, m88k and the Sparc. N.b. use info! It is kept up to date, while the man page (sometimes) isn't. There was some discussion of how shared libraries work without pic, but I remain bemused that they do. (I discovered that one of mine picks up non-pic code from a .a archive, on both linux & Solaris. I wouldn't recommend the practice, all the same). Cheers ... Duncan. On Tue, May 26, 1998 at 04:50:21PM +0200, B. Craig Taverner wrote: > >in ".o". Example:gcc -fPIC -c -I file1.c -o > > Based solely on looking at other peoples makefiles and code, I've been > using -fpic under linux and -fPIC under solaris. > > The gcc man pages say the following: > >-fpic If supported for the target machines, generate po > sition-independent code, suitable for use in a > shared library. > >-fPIC If supported for the target machine, emit position- > independent code, suitable for dynamic linking, > even if branches need large displacements. > > I'm not completely sure I understand the differences here. Does anyone > know what the effect of interchanging -fpic and -fPIC really is?
Re: jdk1.1.5: Using jdb under Linux
Hi Larry, jdb works quite well for me. I find its behaviour a little quirky at times, but basically it seems to work. I have jdk1.1.5v7 and libc 5.4.44. Some examples follow. Actually you can see from the exampes, it really *is* a bit temperamental. If anyone can spot what I'm doing wrong, please let the list know Cheers ... Duncan. EXAMPLE: the recently-discussed clipboard application 18:16:45~/java/1.1$ javac -g clipboard.java Note: clipboard.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning 18:17:27~/java/1.1$ jdb clipboard Initializing jdb... 0x406e72d0:class(clipboard) > stop at clipboard:61 No code at line 61, or class is optimized. Don't know what's going on here, but the following line works... > stop at clipboard$2:61 Breakpoint set at clipboard$2:61 > run run clipboard running ... main[1] isDataFlavorSupported Method called with: Mime Type: text/insidejava Human Name: Test on InsideJava Transferable supports text/insidejava Mime Type. isDataFlavorSupported Method called with: Mime Type: application/x-java-serialized-object Human Name: Unicode String Transferable supports application/x-java-serializedobject Mime Type Breakpoint hit: clipboard$2.actionPerformed (clipboard$2:61) AWT-EventQueue-0[1] print result result = null AWT-EventQueue-0[1] next AWT-EventQueue-0[1] Breakpoint hit: clipboard$2.actionPerformed (clipboard$2:65) AWT-EventQueue-0[1] locals Method arguments: this = clipboard$2@80dd0d0 e = java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Paste] on button1 Local variables: data = Transfer@80dd9ef result = null s = null c is not in scope AWT-EventQueue-0[1] print s Don't know why jdb doesn't simply report "s = null" again:- [Internal debug-agent error: operation failed to complete - deadlock avoided] Internal exception: java.lang.InterruptedException at sun.tools.debug.RemoteAgent.getClassInfo(RemoteAgent.java:627) at sun.tools.debug.RemoteClass.getClassInfo(RemoteClass.java:52) at sun.tools.debug.RemoteClass.getName(RemoteClass.java:87) at sun.tools.debug.RemoteAgent.findClass(RemoteAgent.java:463) at sun.tools.debug.RemoteDebugger.findClass(RemoteDebugger.java:115) at sun.tools.ttydebug.TTY.print(TTY.java:1094) at sun.tools.ttydebug.TTY.executeCommand(TTY.java:1321) at sun.tools.ttydebug.TTY.(TTY.java:1469) at sun.tools.ttydebug.TTY.main(TTY.java:1590) "locals" still gets it right:- AWT-EventQueue-0[1] locals Method arguments: this = clipboard$2@80dd0d0 e = java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Paste] on button1 Local variables: data = Transfer@80dd9ef result = null s = null c is not in scope AWT-EventQueue-0[1] next AWT-EventQueue-0[1] Breakpoint hit: clipboard$2.actionPerformed (clipboard$2:71) AWT-EventQueue-0[1] quit 19:36:21~/java/1.1$ You can also debug applets, although the error message had me fooled for a while. The Scribble applet from Javanut2 (or 1):- 20:12:07~/java/1.1$ javac -g Scribble.java Note: Scribble.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning 20:14:08~/java/1.1$ appletviewer -debug Scribble.html Initializing jdb... [Internal debug-agent error: operation failed to complete - deadlock avoided] sun.applet.AppletViewer not found (try the full name) It seems to be "safe" to ignore this error message > run run sun.applet.AppletViewer Scribble.html running ... For now, I have only had success in setting breakpoints *after* the applet is started (so the target classes are loaded). I have not yet been able to load them myself with the "load" command. main[1] stop in Scribble.action [Internal debug-agent error: operation failed to complete - deadlock avoided] Internal exception: java.lang.InterruptedException at sun.tools.debug.RemoteAgent.getClassInfo(RemoteAgent.java:627) at sun.tools.debug.RemoteClass.getClassInfo(RemoteClass.java:52) at sun.tools.debug.RemoteClass.getName(RemoteClass.java:87) at sun.tools.debug.RemoteAgent.findClass(RemoteAgent.java:463) at sun.tools.debug.RemoteDebugger.findClass(RemoteDebugger.java:115) at sun.tools.ttydebug.TTY.getClassFromToken(TTY.java:695) at sun.tools.ttydebug.TTY.stop(TTY.java:755) at sun.tools.ttydebug.TTY.executeCommand(TTY.java:1376) at sun.tools.ttydebug.TTY.(TTY.java:1469) at sun.tools.ttydebug.TTY.main(TTY.java:1590) I thought *that* worked last time I tried. Ho hum, try it the other way:- main[1] stop at Scribble:51 Breakpoint set at Scribble:51 main[1] Invoke the Colour Choice button in the applet window, which hits the breakpoint: Breakpoint hit: Scribble.action (Scribble:51) AWT-EventQueue-0[1] locals Method arguments: this = Scribble[panel1,0,0,500x300,layout=java.awt.FlowLayout] event = java.awt.Event[id=1001,x=274,y=5,target=java.awt.Choice
Re: bug - system clipboard does not work
The application now works for me after changing 2 lines. At least, after Copy of
slected text in pane 1 and "Paste", both panes display the text and nothing else
- was that the intention?
Using jdb, I found that the mime-type of the message was "text/plain;
charset=unicode", which Transfer's getTransferData method didn't recognise,
therefore returning null.
The second problem was that once getTransferData returned a non-null object, the
cast of it to StringReader caused a runtime exception. A cast to String is OK
however.
The changes are appended. Why it worked as-is on the other platforms is another
question.
-Duncan
On Wed, May 13, 1998 at 04:36:24PM +0100, Steve Zara wrote:
> This example code works fine on Solaris and Win95/NT:
>
>
> import java.net.*;
> import java.awt.*;
> import java.awt.datatransfer.*;
> import java.io.*;
> import java.awt.event.*;
>
> class clipboard extends Frame implements ClipboardOwner{
> TextArea t1=new TextArea("Area 1...",20,20);
> TextArea t2=new TextArea("Area 2...",20,20);
> Button b1=new Button("Copy");
> Button b2=new Button("Paste");
> Panel pA=new Panel();
> Panel pB=new Panel();
> ClipboardOwner owner=this;
> Clipboard Clip=getToolkit ().getSystemClipboard ();
>
> public void lostOwnership(Clipboard b,Transferable c)
> {
> System.out.println("We lost ownership!");
> }
>
> public static void main(String args[])
> {
> clipboard c=new clipboard();
> c.resize(new Dimension(300,300));
> c.show();
> }
>
> clipboard()
> {
> setLayout(new BorderLayout(10,10));
> pA.setLayout(new FlowLayout());
> pB.setLayout(new FlowLayout());
> pA.add("West",t1);
> pA.add("East",t2);
>
> b1.addActionListener( new ActionListener() {
>
> public void actionPerformed(ActionEvent e)
> {
> Transfer trans=new Transfer(t1.getSelectedText());
> Clip.setContents(trans,owner);
> }
> });
>
>
> b2.addActionListener( new ActionListener() {
> public void actionPerformed(ActionEvent e)
> {
>
> Transferable data=Clip.getContents(this);
> StringReader s;
> if (data.isDataFlavorSupported(new
>DataFlavor("text/insidejava","Test on InsideJava")))
> System.out.println("Transferable supports
>text/insidejava Mime Type.");
>
> if
>(data.isDataFlavorSupported(DataFlavor.stringFlavor))
> System.out.println("Transferable supports
>application/x-java-serializedobject Mime Type");
> try {
>
> String result = "";
>
>s=(StringReader)data.getTransferData(DataFlavor.plainTextFlavor);
>
> try {
> for (;;) {
> int c = s.read ();
> if (c == -1)
> break;
>
> result += (char) c;
> }
> } catch (Exception ioe) {
> }
> t2.setText (result);
> t1.setText (result);
>
>
> }
> catch (UnsupportedFlavorException ex)
>{System.out.println("Unsupported Flavor!");}
> catch (IOException ex)
>{System.out.println("IOException!");}
>
> }
> });
>
> pB.add(b1);
> pB.add(b2);
>
> add("South",pB);
> add("Center",pA);
> }
> }
>
>
>
> class Transfer implements Transferable
> {
> String s;
>
> public Transfer(String s)
> {
> this.s=s;
> }
>
> public Object getTransferData(DataFlavor flavor) throws
>UnsupportedFlavorException, IOException
> {
> if (flavor.getMimeType().equals("text/insidejava")) return s;
> if (flavor==DataFlavor.stringFlavor) return s;
> return null;
> }
>
> public boolean isDataFlavorSupported(DataFlavor flavor)
> {
> System.out.println("isDataFlavorSupported Method called with:");
> System.out.println(" Mime Type: "+flavor.getMimeType());
> System.out.println(" Human Name: "+flavor.getHumanPresentableName());
Re: bug - system clipboard does not work
Hi Robert,
On Thu, May 14, 1998 at 09:53:24PM -0700, Robert Lynch wrote:
>
>
> Say I highlight a couple of words in your e-mail and then use the paste
> button in Steve's java application (with your mods), then I get:
> -
> Exception occurred during event dispatching:
> java.lang.NullPointerException:
> at
> sun.awt.motif.X11Selection.isDataFlavorSupported(X11Selection.java:223)
> at clipboard$2.actionPerformed(clipboard.java:53)
> at java.awt.Button.processActionEvent(Button.java:257)
> at java.awt.Button.processEvent(Button.java:230)
> at java.awt.Component.dispatchEventImpl(Component.java:1781)
> at java.awt.Component.dispatchEvent(Component.java:1708)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)
>
> i.e., more or less what Steve was getting.
Yes, I get this too, *if* I use "paste" before I ever used "copy".
In this case the app receives an (almost) empty object:-
AWT-EventQueue-0[1] dump data
data = (sun.awt.motif.X11Selection)0x406e4ca8 {
int atom = 161
X11SelectionHolder holder = null
Transferable contents = null
String dataString = null
int targetArray[] = null
Object data = null
}
After pressing copy (so, invoking Clipboard.setContents()), an object containing
a String is obtained:
AWT-EventQueue-0[1] dump data
data = (Transfer)0x406ec170 {
String s = null
}
This string is either null or whatever was highlighted *inside the application*
when copy was pressed.
>
> Whereas, if one makes the change to (gutting of!) his button method as I
> mentioned:
> -
> ...
> b2.addActionListener( new ActionListener() {
> public void actionPerformed(ActionEvent e)
> {
>
> Transferable data=Clip.getContents(this);
> //System.out.println("data is: "+data);
> String result = "";
> try {
> result =
> (String)data.getTransferData(DataFlavor.stringFlavor);
> }
> catch (Exception ex) {;}
> t2.setText (result);
> t1.setText (result);
> }
> });
> ...
> ---
Not for me! I don't see data from the system clipboard, even after making the
above change. And with the 2 lines I changed earlier, it still copies and pastes
data that is highlighted in the app.
The book (Javanut2) says you get system clipboard data from
Toolkit.getSystemClipboard() and that Clipboard() is for intra-application cut &
paste. That is the behaviour I am seeing with or without your changes.
Without your changes however, I do get the original error if paste is
"accidentally" done before copy.
> Matters are a bit confused here, IMO because there's not a lot of
> agreement on what's being attempted. ;-)
I'LL SAY
>
> FWIW.
>
> Bob L.
Cheers ... Duncan.
import java.net.*;
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.awt.event.*;
class clipboard extends Frame implements ClipboardOwner{
TextArea t1=new TextArea("Area 1...",20,20);
TextArea t2=new TextArea("Area 2...",20,20);
Button b1=new Button("Copy");
Button b2=new Button("Paste");
Panel pA=new Panel();
Panel pB=new Panel();
ClipboardOwner owner=this;
Clipboard Clip=getToolkit ().getSystemClipboard ();
public void lostOwnership(Clipboard b,Transferable c)
{
System.out.println("We lost ownership!");
}
public static void main(String args[])
{
clipboard c=new clipboard();
c.resize(new Dimension(300,300));
c.show();
}
clipboard()
{
setLayout(new BorderLayout(10,10));
pA.setLayout(new FlowLayout());
pB.setLayout(new FlowLayout());
pA.add("West",t1);
pA.add("East",t2);
b1.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Transfer trans=new Transfer(t1.getSelectedText());
Clip.setContents(trans,owner);
}
});
b2.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
Transferable data=Clip.getContents(this);
//System.out.println("data is: "+data);
String result = "";
try {
result = (String)data.getTransferData(DataFlavor.stringFlavor);
}
catch (Exception ex) {;}
t2.setText (result);
t1.setText (result);
}
});
pB.add(b1);
pB.add(b2);
add("South",pB);
add("Center",pA);
}
}
class Transfer implements Transferable
{
String s;
public Transfer(String s)
{
this.s=s;
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,
IOException
{
if (flavor.getMimeType().equals("text/insidejava")) return s;
if (flavor.getMimeType().equals("text/plain; charset=unicode")) return s;
if (flavor==DataFlavor.stringFlavor) return s;
return null;
}
public boolean isDataFlavorSupported(DataFlavo
Re: bug - system clipboard does not work
Hi Robert, On Fri, May 15, 1998 at 07:25:26PM +1000, Duncan Roe wrote: > > Not for me! I don't see data from the system clipboard, even after making the > above change. And with the 2 lines I changed earlier, it still copies and pastes > data that is highlighted in the app. > > The book (Javanut2) says you get system clipboard data from > Toolkit.getSystemClipboard() and that Clipboard() is for intra-application cut & > paste. That is the behaviour I am seeing with or without your changes. > I missed the call to getSystemClipboard circa line 12. So it looks as if that is just not working here. What window manager are you using? - I use fvwm95 Cheers ... Duncan.
