Profil de OnegaOnegaBlogListesRéseau Outils Aide

Onega Zhang

Occupation

Onega

www.fruitfruit.com
15 décembre

build boost 1.41 on ubuntu karmic

Download 7zip
Then run unzip command: /usr/bin/p7zip -d boost_1_41_0.7z
~/Downloads/boost_1_41_0/tools/jam/src$ chmod u+x build.sh
~/Downloads/boost_1_41_0/tools/jam/src$ ./build.sh
~/Downloads/boost_1_41_0$ tools/jam/src/bin.linuxx86/bjam  --without-mpi stage --build-type=complete  --layout=versioned

Install latest GCC on ubuntu karmic

g++ is not found on ubuntu karmic, "apt-get install ..." can't find packages, and the following commands worked anyway.
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/cpp-4.4_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/g++-4.4_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/gcc-4.4-base_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/gcc-4.4-doc_4.4.2-5ubuntu1_all.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/gcc-4.4-multilib_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/gcc-4.4_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libstdc++6_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libstdc++6-4.4-dev_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64gcc1_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64gomp1_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libgcc1_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libgomp1_4.4.2-5ubuntu1_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc6-i686_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc6-dev-amd64_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc6-amd64_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc6-dev_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc6_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc-bin_2.10.2-2ubuntu2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/e/eglibc/libc-dev-bin_2.10.2-2ubuntu2_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64stdc++6-4.4-dbg_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64stdc++6_4.4.2-5ubuntu1_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/c/cloog-ppl/libcloog-ppl-dev_0.15.7-1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/universe/p/ppl/libppl0.10-dev_0.10-2_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/c/cloog-ppl/libcloog-ppl0_0.15.7-1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gmp/libgmp3-dev_4.3.1+dfsg-3_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gmp/libgmp3c2_4.3.1+dfsg-3_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gmp/libgmpxx4ldbl_4.3.1+dfsg-3_i386.deb

sudo dpkg -i libc-bin_2.10.2-2ubuntu2_i386.deb
sudo dpkg -i libgcc1_4.4.2-5ubuntu1_i386.deb libc6_2.10.2-2ubuntu2_i386.deb
sudo dpkg -i libc-dev-bin_2.10.2-2ubuntu2_i386.deb
sudo dpkg -i lib64gcc1_4.4.2-5ubuntu1_i386.deb lib64gomp1_4.4.2-5ubuntu1_i386.deb libgcc1_4.4.2-5ubuntu1_i386.deb libgomp1_4.4.2-5ubuntu1_i386.deb libc6-i686_2.10.2-2ubuntu2_i386.deb libc6-dev-amd64_2.10.2-2ubuntu2_i386.deb libc6-amd64_2.10.2-2ubuntu2_i386.deb libc6-dev_2.10.2-2ubuntu2_i386.deb
sudo dpkg -i cpp-4.4_4.4.2-5ubuntu1_i386.deb g++-4.4_4.4.2-5ubuntu1_i386.deb gcc-4.4-base_4.4.2-5ubuntu1_i386.deb gcc-4.4-doc_4.4.2-5ubuntu1_all.deb gcc-4.4-multilib_4.4.2-5ubuntu1_i386.deb gcc-4.4_4.4.2-5ubuntu1_i386.deb libstdc++6_4.4.2-5ubuntu1_i386.deb libstdc++6-4.4-dev_4.4.2-5ubuntu1_i386.deb libstdc++6-4.4-dev_4.4.2-5ubuntu1_i386.deb

sudo dpkg -i g++-4.4_4.4.2-5ubuntu1_i386.deb
sudo dpkg -i lib64stdc++6_4.4.2-5ubuntu1_i386.deb

sudo dpkg -i libcloog-ppl-dev_0.15.7-1_i386.deb libppl0.10-dev_0.10-2_i386.deb libcloog-ppl0_0.15.7-1_i386.deb libgmp3-dev_4.3.1+dfsg-3_i386.deb libgmp3c2_4.3.1+dfsg-3_i386.deb libgmpxx4ldbl_4.3.1+dfsg-3_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libgcc1-dbg_4.4.2-5ubuntu1_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libstdc++6-4.4-dbg_4.4.2-5ubuntu1_i386.deb

sudo dpkg -i libgcc1-dbg_4.4.2-5ubuntu1_i386.deb libstdc++6-4.4-dbg_4.4.2-5ubuntu1_i386.deb

wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/g++-4.4-multilib_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64stdc++6-4.4-dbg_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/libgcc1-dbg_4.4.2-5ubuntu1_i386.deb
wget http://mirrors.163.com/ubuntu/pool/main/g/gcc-4.4/lib64gcc1-dbg_4.4.2-5ubuntu1_i386.deb

sudo dpkg -i g++-4.4-multilib_4.4.2-5ubuntu1_i386.deb lib64stdc++6-4.4-dbg_4.4.2-5ubuntu1_i386.deb libgcc1-dbg_4.4.2-5ubuntu1_i386.deb lib64gcc1-dbg_4.4.2-5ubuntu1_i386.deb

show gcc version:
dpkg --list | grep gcc

create a link with name g++ from g++-4.4:
ln /usr/bin/g++-4.4 /usr/bin/g++


14 décembre

ubuntu 9.10 experience

Installed ubuntu 9.10 on laptop. The installation package is an iso file for CD-image, then I have to record it via InfraRecorder to write to DVD-R/W since a commercial software refused to write CD-image into DVD. The installation process is simple. I have to change my wireless router settings to allow it broadcast so that ubuntu can connect to it successfully. Firefox hung up the system when I clicked eclipse download link - first system cold reset. Open jre-6u17-linux-i586.bin via Archive Manager leads to second system hang up and cold reset. It took me days to find out the right guide (Sun Java JRE) to install JRE.  unpack eclipse-cpp-galileo-SR1-linux-gtk.tar.gz and install it according to this post (Install Eclipse Galileo (3.5) on Ubuntu Jaunty (9.04)). it can't create new C++ project - no effect after hit "Next" or "Finish" button, no error message too. Some people posted a workaround - Problems with Eclipse buttons in Ubuntu 9.10.
Another GUI hang up: click on "Go" menu of "File Browser", Drop down menu of "Edit" was transparently drawn on screen and then the whole screen lock up. Although mouse is still active, but "Ctrl+Alt+Backspace" and "Ctrl+Alt+F1" do not work.

12 décembre

Web Technologies in Desktop Application

Most desktop application are developed in single language like C++, or Java, but sometimes integrating with other languages like script and XML/XSL also has prominent advantages:

  • Some tasks can be easily implemented in script language, but requires much more efforts doing via C++;
  • Script is easier to change and maintain to meet fast changing customer requirement;
  • it takes less efforts doing representation in XSLT/HTML than traditional OS UI development.
Here is a concept design in VC++. msscript.ocx can be used to embed vbscript/jscript in VC++ application, reference: How To Call Run() Method of the Microsoft Script Control in C++. script is much more efficient than VC++ when doing OS administrative tasks via WMI. Script can convert WMI resultset into XML, and then using XSLT to transform XML into HTML and display it in a WebBrowser control. Reference: XSLT – Transformation.
10 décembre

Layout managers

Java Objective Toolkit Qt wxWidgets
  Alignment Layout    
  Scale Layout    
BoxLayout   QBoxLayout,
QHBoxLayout
QVBoxLayout
wxBoxSizer wxStaticBoxSizer
GridLayout Grid Layout QFormLayout wxGridSizer wxFLexGridSizer
GridBagLayout GridBag Layout QGridLayout

wxGridBagSizer

  Relatvie Layout    
BorderLayout      
CardLayout      
FlowLayout      
GroupLayout      
SpringLayout      
    QStackedLayout  
MFC does not provide built-in layout managers. There are some contributed solutions online.
WinMgr
A Simple C++ Layout Manager
EasySize - Dialog resizing in no time!

ResizableLib

9 décembre

suspicious file c:\temp\Perflib_Perfdata_5d4.dat

use handle.exe to find out the process that opens it:

C:\tools\sysinternals>handle Perflib_Perfdata_5d4.dat

Handle v3.42
Copyright (C) 1997-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

jqs.exe            pid: 1492    100: C:\temp\Perflib_Perfdata_5d4.dat

 

Then use procexp.exe to examine process of PID 1492, which turns out to be

C:\Program Files\Java\jre6\bin\jqs.exe

WebBrowser in Desktop Application

IE is using Asynchronous Pluggable Protocol to support customized protocol. Here are some reference materials:
Asynchronous Pluggable Protocols
INFO: Implementing HTTP-like Asynchronous Pluggable Protocols

Custom Hyperlinks Using Asynchronous Pluggable Protocols
An Asynchronous Pluggable Protocol Handler for data: URLs
Firefox is a totally different. Here are some materials:
Notes on NPAPI based plugins
Adding a New Protocol to Mozilla
mozilla/ extensions/ datetime/

mozilla/ extensions/ finger/

Usage: It can be implemented in a desktop application to display complex content to user. WebBrowser is a powerful representation control, but it is not convenient to setup a web server to feed the content within a desktop application framework. Then a new protocol can be created to implement a rich client application that takes advantage of powerful layout capability of html without the burden of http server.

Another technique is using DHTML event handling to interactive with webbrowser: Simple VC++ DHTML Hooking Technique
Integrating DHTML into MFC Views
How To Set DHTML Event Properties from C++
Calling C++ Code from DHTML
Building Dynamic Visual C++ Programs with DHTML

8 décembre

py2exe

I have written a wxPython script to create a GUI prototype for review, but it is not convenient to ask user installing python. Fortunately py2exe is able to rescue. Install py2exe, create setup.py according to the Tutorial.Run the following command:

D:\test\python>c:\Python26\python.exe setup.py py2exe

got error: error: MSVCP90.dll: No such file or directory

copy C:\Program Files\Microsoft Visual Studio 9.0\vc\redist\x86\Microsoft.VC90.CRT\msvcp90.dll to D:\test\python\msvcp90.dll and run above command again, now it successfully build python script as Windows executable under D:\test\python\dist. There are a bunch of files, but it is better than installing python on user’s machine.

3 décembre

Using MinGW

Downloaded MinGW-5.1.6.exe and installed to default location, then downloaded and installed gcc 4.4.0:

gcc-core-4.4.0-mingw32-bin.tar.gz
gcc-c++-4.4.0-mingw32-bin.tar.gz
gcc-core-4.4.0-mingw32-dll.tar.gz
gcc-c++-4.4.0-mingw32-dll.tar.gz

After this, g++ operator-test.cpp -o a.exe output nothing in console window, also does not product output file. “g++ –v” confirmed that I was using 4.4.0. At last, I found gcc-4.4.0-mingw32-notes.txt and followed its instruction to install other [required] components:

GMP Runtime [REQUIRED]
  gmp-4.2.4-mingw32-dll.tar.gz

libiconv Runtime [REQUIRED]
  libiconv-1.13-mingw32-dll-2.tar.gz

MPFR Runtime [REQUIRED]
  mpfr-2.4.1-mingw32-dll.tar.gz

POSIX Threads for Win32 Runtime [REQUIRED]
  pthreads-w32-2.8.0-mingw32-dll.tar.gz

Now “g++ operator-test.cpp -o a.exe ” worked as expected.
30 novembre

why do I use alloca

alloca function allocates memory from stack, thus is much faster than heap and is released automatically when function exit. At first look it like like declare a char array, but the difference is that you can only declare array of fixed size on stack, but you can get variable size memory (although limited by available stack size) via alloca.

#include <windows.h>
#include <iostream>
#include <iomanip>
#include <exception>
void test_stackoverflow(int size)
{
    std::cout << __FUNCTION__ << "("<<size<<")\n";
    char* ptr = static_cast<char*>(alloca(size));
    ptr[0]='a';
    std::cout << __FUNCTION__ << "()\n";
}

void test_with_std_exception()
{
    try
    {
        for(int i=102; ;i++ )
            test_stackoverflow(i*10240);
    }
    catch (std::exception& e)
    {
        std::cout << e.what()<<std::endl;
    }

}
void main(int argc, char* argv[])
{
    __try{
        for(int i=102; ;i++ )
            test_stackoverflow(i*10240);

    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        std::cout<<"Exception code 0x"<<std::hex<< _exception_code()<<std::endl;
    }
    if (argc>1)
        test_with_std_exception();
}
// cl -EHa overflow.cpp
// D:\test\stl>overflow.exe
//test_stackoverflow(1044480)
//  Exception code 0xc00000fd

17 novembre

std::stack, std::queue and std::priority_queue

The interesting fact is that std::queue and std::priority_queue has different interface – std::queue has front(), but std::priority_queue has top().

#include <stack>
#include <list>
#include <iostream>
#include <string>
#include <queue>

template<typename ContainerType>
void fill_container(ContainerType& cnt)
{
    cnt.push('a');
    cnt.push('0');
    cnt.push('b');
    cnt.push('c');
}

void main()
{
    typedef std::stack< char, std::list<char> > char_list_stack;
    char_list_stack mystack; fill_container(mystack);
    std::cout << "\ncontent in stack:";
    while(mystack.size())
    {
        std::cout << mystack.top() << " ";
        mystack.pop();
    }

    std::queue<char, std::list<char> > myqueue;
    fill_container(myqueue);
    std::cout << "\ncontent in queue:";
    while(myqueue.size())
    {
        std::cout << myqueue.front() << " ";
        myqueue.pop();
    }

    //std::priority_queue<char, std::deque<char> > mypqueue;
    std::priority_queue<char, std::vector<char> > mypqueue;
    fill_container(mypqueue);
    std::cout << "\ncontent in priority_queue:";
    while(mypqueue.size())
    {
        std::cout << mypqueue.top() << " ";
        mypqueue.pop();
    }

}
// cl -EHsc stack.cpp -link -verbose:lib
// content in stack:c b 0 a
// content in queue:a 0 b c
// content in priority_queue:c b a 0

exception in ctor

operator new return NULL if ctor throw exception, this will leads to resource leak, and other possible problem like lock is not released.

// ctor.cpp : test throw exception in ctor.
// cl -EHsc -d1reportSingleClassLayoutCtorWithException ctor.cpp

#define _CRTDBG_MAP_ALLOC
#include <tchar.h>
#include <stdlib.h>
#include <crtdbg.h>
#include <iostream>
#include <iomanip>

class CtorWithException
{
public:
    CtorWithException(bool throw_exception):m_buf(new char[10240])
    {
        std::cout << __FUNCTION__ << " this=" << std::hex << (int)this <<std::endl;
        if (throw_exception)
        throw std::runtime_error("exception in ctor");
    }
    ~CtorWithException()
    {
        delete[] m_buf;
        std::cout << __FUNCTION__ << " this=" << std::hex << (int)this <<std::endl;
    }
private:
    char* m_buf;
};

class TestCtorWithException
{
public:
    TestCtorWithException():m_buf(new char[1024*1024]),m_no_exp(false),m_has_exp(true),m_uninitialized(false)
    {
        std::cout << __FUNCTION__ << " this=" << std::hex << (int)this <<std::endl;
    };
    ~TestCtorWithException()
    {
        delete[] m_buf;
        std::cout << __FUNCTION__ << " this=" << std::hex << (int)this <<std::endl;
    };
private:
    char *m_buf;
    CtorWithException m_no_exp;
    CtorWithException m_has_exp;
    CtorWithException m_uninitialized;
};

int _tmain(int argc, _TCHAR* argv[])
{
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT );
    TestCtorWithException* testobj=NULL;
    try
    {
        //TestCtorWithException test_obj;
        testobj=new TestCtorWithException;
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
    std::cout << "new return " << std::hex << testobj << std::endl;
    _CrtDumpMemoryLeaks();
    return 0;
}
// program output
//CtorWithException::CtorWithException this=38cf34
//CtorWithException::CtorWithException this=38cf38
//CtorWithException::~CtorWithException this=38cf34
//exception in ctor
//new return 00000000
//Detected memory leaks!
//Dumping objects ->
//{225} normal block at 0x00530068, 10240 bytes long.
//Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
//{203} normal block at 0x00420040, 1048576 bytes long.
//Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
//      Object dump complete.

boost.program_options crash

A program linking with libboost_program_options-vc90-mt-gd-1_35.lib crashed at desc.add_options(), but the release version worked. At last it turned out to be due to mixed usage of debug version CRT and release version CRT – the program in trouble linked to some release version library in its debug build. The interesting fact is that VC++ 2008 does not complain during compilation, but boost.program_options raised obscure run-time error.

27 octobre

Join sample on PostgreSQL

Here is a simple example that demonstrate usage of INNER, FULL, LEFT and RIGHT JOIN.

Create 2 tables
create table p1(pid integer, pname varchar(20));
create table p2(pid integer, ptype varchar(10));
insert some data into the tables.
insert into p1(pid, pname) values(1,'p1');
insert into p1(pid, pname) values(2, 'p2');
insert into p1(pid, pname) values(4, 'p4');
insert into p2(pid, ptype) values(1,'t1');
insert into p2(pid, ptype) values(2, 't2');
insert into p2(pid, ptype) values(3, 't3');

select * from p1;

  pid pname
1 1 p1
2 2 p2
3 4 p4


select * from p2;

  pid ptype
1 1 t1
2 2 t2
3 4 t4

inner join is implicit. The following two produce the same result.

select * from p1,p2 where p1.pid=p2.pid;
select * from p1 inner join p2 on p1.pid=p2.pid;

  pid pname pid ptype
1 1 p1 1 t1
2 2 p2 2 t2

select * from p1 left join p2 on p1.pid=p2.pid;

  pid pname pid ptype
1 1 p1 1 t1
2 2 p2 2 t2
3 4 p4    


 

1;"p1";1;"t1"
2;"p2";2;"t2"
4;"p4";;""
select * from p1 right join p2 on p1.pid=p2.pid;

  pid pname pid ptype
1 1 p1 1 t1
2 2 p2 2 t2
3     3 t3


select * from p1 full join p2 on p1.pid=p2.pid;

  pid pname pid ptype
1 1 p1 1 t1
2 2 p2 2 t2
3     3 t3
4 4 p4    

CORBA, COM and WebService

Compare aspects of CORBA and COM

  CORBA COM WebService
interface IDL IDL WSDL
  Interface Repository typelib WSDL
  POA ClassFactory  
  Active Object Map GIT, ROT  
Locate the server Implementation Repository;
IIOP
Interoperable Object Reference (IOR)
Registry UDDI
  CORBA::object to string    
  static invocation interface (SII)    
  dynamic invocation interface IDispatch  
  Dynamic Skeleton Interface (DSI)