Archive for the 'c++' Category
gnu g++ compiler bug

Discovered a g++ compiler bug that can be reproduced on (gcc 4.1.2 default instalation on RH5, and gcc 4.3.5).

Given the following code:


template
class Wrapper
{
public: Wrapper( Wrapped *c );

Wrapped *c;
};

class Stream
{

public:
Stream(const Wrapper &cucucucu) {}

Stream &operator << (const std::string &s)
{
std::cout << s << std::endl;
return *this;
}
};

int main()
{
unsigned char *buffer;
//A a(cccc);

Stream str( Wrapper (buffer));

std::string s(”aoeuao”);
str << s;
}

the compiler throws the following misterous error:

t.cpp: In function 'int main()':
t.cpp:35: error: no match for 'operator<<' in 'str << s'

Long life Babelengine, the c++ web framework

A new open-source project started: babelengine. The intention is to design and implement in C++ a highly modular web 2 application framework (CMS, but not only). The framework will make intensive use of the existing WT toolkit.The framework will include powerful language and translation features and should become a powerful tool for multi-language web platforms. Thus the name babel-engine. I hope you will like the name :).

At the moment http://babelengine.org will host a forum, where we can discuss ideas, features, plans about the project.

intel core i7 vs. amd phenom II

Introduction

As always, when buying a new hardware, it is difficult to decide if I should go for intel or amd processors. Funny is that, based on different criteria among others the prices of the processors and the mainboard that is depending on the processor, you decide what to do today, but until you place your order on internet, prices suffer often significant variation.

I am intending to buy a new home server for linux. I want that this server:

  1. Fast file server
  2. Fast C++ build server
  3. Low power consumption, especially in idle
  4. best performance per unit of price

Fast C++ builds require among others memory bandwidth, and here Intel wins as with the new built-in memory controler and 3 channel memory access. However several articles on internet state that the 3rd channel does not bring at the moment any added value.

Power consumption

http://www.tomshardware.com/reviews/phenom-ii-940,2114-7.html

(to be continued)

Build wt app with xml

DC (I do not know if he wants his name being published), implemented a mechanism that allows to assamble the widgets of a generic WT application with help of an XML file. I was thinking to do something similar, I even made reference to it on my earlier post on the mailing list. I was not sure that xml was the best choice. My idea was to create a “wrapper html” file, the stuff that web designers love, and position inside this html file the different controls. This html file would have been the root control, and the application would have assembled the widgets based on the information contained inside the html file. So again this html file would have been the design html for web designer and also the “imput file” for the programmer. Anyway the implementation that DC started is fine, as from the “layout” html file I was mentioning above one could generate the xml configuration file.

After DC published his work on the mailing list I made some comments about some details nice to have.

  • a mechanism to connect signals with slots
  • a mechanism to specify data sources for the widgets

I am afraid that I was not understood regarding the data source. I was writing earlier on the mailing list also about database connectivity, and libraries that would allow such connectivity (I called it data source). Choosing a good database connectivity engine (library), and linking against our generic program, it would be interesting to configure in the same XML file the database and table name (and eventually sql statement) that would feed a certain widget. Exactly as our funny friends Visual Basic or Delphi did. Example, you add to your XML file a new combobox with some country names. You do not want to add code that would only feed the control, recompile, etc., but you would rather specify it in the xml file for that widget something like as “<datasource database=”blahblah” table=”countries” row=”name”/>. When building the widget if such datasources are specified,  with some simple and generic mechanism the widget would be loaded with the “name” column from the countries table.
Or something similar, once the combobox with countries loaded, you add a text view control, and link the <selection changed> signal of the combobox with some slot in the text view control. The view control would have sthg. like <datasource database=”blahblah” view=”select description from countries where name=***selected country***>.

Unfortunatelly I do not have time to go deeper into details, I would love to do so, I would love to find myself the solution, but I believe this would make wt much more fun to use… even for beginners.

I think it would be also a nice marketing stuff for WT. Create wt application in 3 steps. The user would have to download the “generic executable” (that is what windows kidZZ love :) ). Run the executable, it would open port XXX. Then go with browser, http://localhost:XXX/admin. The admin page will show you a simple start control, and some mechanism to add/remove controls, specify signal slot connections, etc. What would be the next step… add some simple python/ruby code to add more functionality ?

Hm… I do not think this is a dream… Isn,t it? :)

Cloud Building Blocks

Intel has initiated Threading Building Blocks (TBB), I will initiate Cloud Building Blocks. I skimmed through the documentation of TBB, and I have an idea about what is happening there, but I have realized that even if the TBB gives me valuable tools for one computer with multiple cores, it fails to give me similar tools to work on a farm of computers. And I think the future is of what is called Cloud computing. I set up therefore CloudBuildingBlocks.org, first as a wiki to collect some ideas there, maybe it will become a project…

Being in rush, I could not resist to reserve another related domain name: CloudComputingForum.org forum about how to build cloud computing…

Another rush move was reserving Cloud Building Forum was also set up, for open discussion about cloud computing.

google gold linker

Ian Lance Taylor from google announced already one year ago a new linker which is a complete rewrite. I gave it a try on one of the projects I am working an which contains more than 2 milion lines of C++ code + lot of libraries. It links in 14 seconds, compared to 10 minutes the default linker from binutils-2.17.50.0.6 needs. There is however a patch arond for the default linker that reduces link time for the same executable from 10 minutes to 40 seconds. As I link often, it makes a difference between 40 seconds and 14 seconds…

vim++

I am sure there are people who thought about writing a new vim in c++ (vim++ sounds good?, isn’t it?), where features could be added much easier through some plugin mechanism. I love the philosophy of vim, but its evolution is limited as it is now…

Imagine the buffers for example would be some polymorphic stuff, or some template magic where one would provide some interfaces, and beside some default imlementations one could implement that interface to read a file from disk, iterate through a huge resultset of a database… etc. Imagine you could plugin a search engine, that would be complementary to the existing one. Indeed lot of stuff can be done through scripting, but the scripts have their limitations…

So imagine a nicelly designed editor, that would be far from an overdesigned eclipse, would still keep simplicity as it’s feature no 1.

caching with wt

in an elegant design a web applications presentation layer (or equivalent ones) should not make tricks about caching. I see often bad code like following everywhere, especiall written by php kids:

HTML Page::getHtml() {
if(cached)
data = getFramCache()
else
data = getDataFromDatabase()
}

one should create polymorfic database, or use templates to hide caching in the data source pattern.

Widget::onEvent(IdClass id)
{
Datasource *datasoure = Datasource::singleton();
datasource->getData();
}

Datasource::getData(Key &key)
{
//do some sql
}

then you could have
class DatasourceWithCache: public Datasource
********
Data *DatasourceWithCache::getData(Key &key)
{
Data *data = getFromCache();
if(!data)
Datasource::getData(key);
return data;
}

The cache could be shared between threads or processes (!!security issues!!), or just one process.
Your framework should initialize the singleton with the correct datasource. You could create a config file, and specify the activation of the cache. You can implement a datasource based on sthg. like memcache (so much venerated by php kids).

Let’s take a simple example with a web application that would have different views (pages) of the same table data. If you change one cell in the table, all the other cached views should be invalidated in the “classical” approach, whereas with ajax approach, you should invalidate the cache only for that particular cell. If this level of cache is not enough, you could always find a compromise and with a bit more complex cache, one could cache the whole rendered widget data, but here the widget code itself would probably need to help. (and thus a bit in contradiction with the first statement). Anyway there should be a balance between the necessity of the cache.

Another example, a wiki engine, or blog engine. With wt, one would need to cache the pages data, not the decoration around. The decoration would not change during going from one page to another one. So one could specialize the datasource by providing rendered (converted from wiki syntax to html). And thus one would just feed the wiki widget with cached data.

database access within wt applications

wt rocks…:).

It has the standalone http server engine, it has also fcgi implementation.

It’s value would probably be significantly increased if some generic database access would be provided (some crazily fancy templates, or polymorfic DAO classes, that could be inelligently connected to widgets. (Yes, the way microsoft does with ocx controls). Another obvious requirement would be to support differet database backends. 

There are some libraries out there, everyone with pluses and minuses. Myself I was spending some time to understand what would fit the best. After studying these libraries I found that on boost’s mailinglist there was already a discussion about the topic. I will write my conclusions soon, but I wanted to ask the wt commmunity what each one uses, and if it would make sense to invent a something and eventually integrate into wt.

the following libraries can be found on internet:

So, can we use or learn something from these libraries?

 

makefile for boost

boost is a wonderfull library, but bjam sucks! The documentation of the config files is ambiguous. I spent few hours to find out how to capture the command lines during build (without hack), and how to influence cxxflags. Did not work. On the other annoying part of bjam is that parallel build does not work either. So I packed together a makefile. This is version 0.0.0.0.1, I will add later several other variables (CXXFLAGS, VERSION, LDFLAGS etc.)… At the moment there are 2 control variables, and they are the source directory and the build directory.

 

BOOST_SRCDIR=/data/build/boost/boost
BOOST_BUILDDIR=/data/build/boost/boostbuild
BOOST_INCLUDEDIR=$(BOOST_SRCDIR)

 

SYSTEM_SOURCEDIR=$(BOOST_SRCDIR)/libs/system/src
SYSTEM_OBJECT_NAMES=error_code.o
SYSTEM_BUILDDIR=$(BOOST_BUILDDIR)/system
SYSTEM_OBJECTS=$(patsubst %.o,$(SYSTEM_BUILDDIR)/%.o, $(SYSTEM_OBJECT_NAMES))
SYSTEM_LIBNAME=system.so
SYSTEM_LIB=$(SYSTEM_BUILDDIR)/$(SYSTEM_LIBNAME)

$(SYSTEM_LIB): $(SYSTEM_BUILDDIR) $(SYSTEM_OBJECTS)
 gcc $(SYSTEM_OBJECTS) -shared  -o $@

$(SYSTEM_BUILDDIR):
 mkdir $(SYSTEM_BUILDDIR)
 
$(SYSTEM_OBJECTS): $(SYSTEM_BUILDDIR)/%.o: $(SYSTEM_SOURCEDIR)/%.cpp
 gcc -c $< -o $@ -I $(BOOST_INCLUDEDIR) -c  -fPIC -fno-stack-protector

 

FILESYSTEM_SOURCEDIR=$(BOOST_SRCDIR)/libs/filesystem/src
FILESYSTEM_OBJECT_NAMES= operations.o \
         path.o \
         portability.o \
         utf8_codecvt_facet.o
FILESYSTEM_BUILDDIR=$(BOOST_BUILDDIR)/filesystem
FILESYSTEM_OBJECTS=$(patsubst %.o,$(FILESYSTEM_BUILDDIR)/%.o, $(FILESYSTEM_OBJECT_NAMES))
FILESYSTEM_LIBNAME=filesystem.so
FILESYSTEM_LIB=$(FILESYSTEM_BUILDDIR)/$(FILESYSTEM_LIBNAME)

$(FILESYSTEM_LIB): $(FILESYSTEM_BUILDDIR) $(FILESYSTEM_OBJECTS)
 gcc $(FILESYSTEM_OBJECTS) -shared  -o $@

$(FILESYSTEM_BUILDDIR):
 mkdir $(FILESYSTEM_BUILDDIR)
 
$(FILESYSTEM_OBJECTS): $(FILESYSTEM_BUILDDIR)/%.o: $(FILESYSTEM_SOURCEDIR)/%.cpp
 gcc -c $< -o $@ -I $(BOOST_INCLUDEDIR) -c  -fPIC -fno-stack-protector

 

REGEX_SOURCEDIR=$(BOOST_SRCDIR)/libs/regex/src
REGEX_OBJECT_NAMES=cpp_regex_traits.o \
       cregex.o \
       c_regex_traits.o \
       fileiter.o \
       icu.o \
       instances.o \
       posix_api.o \
       regex.o \
       regex_debug.o \
       regex_raw_buffer.o \
       regex_traits_defaults.o \
       static_mutex.o \
       usinstances.o \
       w32_regex_traits.o \
       wc_regex_traits.o \
       wide_posix_api.o \
       winstances.o
REGEX_BUILDDIR=$(BOOST_BUILDDIR)/regex
REGEX_OBJECTS=$(patsubst %.o,$(REGEX_BUILDDIR)/%.o, $(REGEX_OBJECT_NAMES))
REGEX_LIBNAME=regex.so
REGEX_LIB=$(REGEX_BUILDDIR)/$(REGEX_LIBNAME)

$(REGEX_LIB): $(REGEX_BUILDDIR) $(REGEX_OBJECTS)
 gcc $(REGEX_OBJECTS) -shared  -o $@

$(REGEX_BUILDDIR):
 mkdir $(REGEX_BUILDDIR)
 
$(REGEX_OBJECTS): $(REGEX_BUILDDIR)/%.o: $(REGEX_SOURCEDIR)/%.cpp
 gcc -c $< -o $@ -I $(BOOST_INCLUDEDIR) -c  -fPIC -fno-stack-protector

 
PROGRAM_OPTIONS_SOURCEDIR=$(BOOST_SRCDIR)/libs/program_options/src
PROGRAM_OPTIONS_OBJECT_NAMES= cmdline.o \
           config_file.o \
           convert.o \
           options_description.o \
           parsers.o \
           positional_options.o \
           utf8_codecvt_facet.o \
           value_semantic.o \
           variables_map.o \
           winmain.o
PROGRAM_OPTIONS_BUILDDIR=$(BOOST_BUILDDIR)/program_options
PROGRAM_OPTIONS_OBJECTS=$(patsubst %.o,$(PROGRAM_OPTIONS_BUILDDIR)/%.o, $(PROGRAM_OPTIONS_OBJECT_NAMES))
PROGRAM_OPTIONS_LIBNAME=program_options.so
PROGRAM_OPTIONS_LIB=$(PROGRAM_OPTIONS_BUILDDIR)/$(PROGRAM_OPTIONS_LIBNAME)

$(PROGRAM_OPTION_SLIB): $(PROGRAM_OPTIONS_BUILDDIR) $(PROGRAM_OPTIONS_OBJECTS)
 gcc $(PROGRAM_OPTIONSOBJECTS) -shared  -o $@

$(PROGRAM_OPTIONS_BUILDDIR):
 mkdir $(PROGRAM_OPTIONS_BUILDDIR)
 
$(PROGRAM_OPTIONS_OBJECTS): $(PROGRAM_OPTIONS_BUILDDIR)/%.o: $(PROGRAM_OPTIONS_SOURCEDIR)/%.cpp
 gcc -c $< -o $@ -I $(BOOST_INCLUDEDIR) -c  -fPIC -fno-stack-protector

 

LIBS=$(SYSTEM_LIB) $(FILESYSTEM_LIB) $(REGEX_LIB) $(PROGRAM_OPTIONSLIB)

all: $(LIBS)
# echo $(LIBS) $(SYSTEM_LIB) $(SYSTEM_OBJECTS) $(SYSTEM_BUILDDIR)/%.o: $(SYSTEM_SOURCEDIR)/%.cpp