NBFFI version of the OpenDBXDriver

Posted on Updated on

Hi!

We have built a NBFFI version of the OpenDBXDriver. The main idea of this is to provide a backward compatibility layer to people that  use OpenDBX, while letting us move forward dropping the old FFI implementation. SLIDES

The configuration still supports to load the former version of the driver (no NBFFI)

  Gofer it
	smalltalkhubUser: 'DBXTalk' project: 'Configurations';
	configurationOf: 'OpenDBXDriver';
	load.
(((Smalltalk at: #ConfigurationOfOpenDBXDriver)
   perform: #project)
       perform: #version: with: ‘1.3’)
           load: 'FFIDriver'.
 

And the configuration with only NBFFI version.

 Gofer it
	smalltalkhubUser: 'DBXTalk' project: 'Configurations';
	configurationOf: 'OpenDBXDriver';
	load.
(((Smalltalk at: #ConfigurationOfOpenDBXDriver)
   perform: #project)
       perform: #version: with: ‘1.3’)
           load:  'NBFFIDriver'.
 

To use, writte in the Workspace and DoIt:

“to set the NBFFI bind”
LibOpenDBXMap initialize.
 OpenDBX current: NBPharoOpenDBX new.
	“or to set the oldFFI bind”
 OpenDBX current: FFIOpenDBX  ffiImplementationForOS .
  

Bye! 😀

Exceptions in Python

Posted on

This post is dedicated to python, especially the handling of exceptions in the language, I take for granted that you already understand the concept, and I only concentrate on the syntax and variations that will allow the language. I will show how to create, throw, catch and test exceptions in python

Create Exceptions

class MiException(Exception):
   def__init__(self, value):
        self.value = value
   def__str__(self):
        return repr(self.value)

Throw Exceptions

if(some validation):
   #OK!
else:
   raise Exception

Catch Exceptions:

try:
    #/*code that can throw exception*/
except:
    #/*do something if the exception is launched*/

Catch Exceptions:Discriminate by type of exception

try:
    #/*code that can throw exception*/
except NameError:
   print "The variable doesn't exist"
except ValueError:
    print "The value is not a number"

Catch Exceptions:Capture several exceptions in the same except

try:
   #code that can throw exception
except (NameError, ValueError):
    print "error"

Catch Exceptions:Do something if the exception is not thrown

try:
   #code that can throw exception
except:
    print "error"
else:
    print "It is OK"

Catch Exceptions:With finally/p>

try:
    z = x / y
except ZeroDivisionError:
    print "Division for Zero"
finally:
    print "Clean..."

Test Exceptions

Test: methods without parameters


def test_afunction_throws_exception(self):
    self.assertRaises(ExpectedException, afunction)

Test: methods with parameters


def test_afunction_throws_exception(self):
    self.assertRaises(ExpectedException, afunction, arg1, arg2)

Bye! 🙂

Practical metacello – Loading

Posted on Updated on

 Hi!

In this post I’ll talk about the metacello and how to load package with this.

The planning
1) What is Metacello? And Monticello?
2) Parts of the Load
3) Groups
4) References

Begin 🙂

1) What is Metacello?

Metacello is a package management system for Monticello, similar Maven in Java, apt-get/aptitude in Debian or Ubuntu, etc.

And What is a Monticello?
Monticello is the  source code versioning used in Pharo. A versioning system tool lets you commit a new version, update to a new one, merge, diff, revert, etc. [1]

2)Parts of the Load

(ConfigurationOfSomeProject project version: '0.1') load.

 *ConfigurationOfSomeProject: is a class defined to handle a project settings, follow the convention ‘ConfigurationOf[nameOfProject]’

*version:’versionName’ is a  message to indicate which version of the project is to

*load: message to load the project

3) Groups.

Sometimes, you want to download all the modules of a project, but a group of them. For this you can send the message  load: ‘[nameOfGroup]’
i.e

(ConfigurationOfSomeProject project version: '0.1') load: ‘ExampleGroup’.

Or also, read several groups:

 

 (ConfigurationOfSomeProject project version: '0.1') load:#( ‘ExampleGroup’, ‘OtherGroup’).

4)References:

[1] Praro By Example 2 Chapter Metacello: http://pharobyexample.org/drafts/Metacello.pdf

A small example of how to use the code generated with TalkFFI

Posted on Updated on

Hi!
Well, we know generate code with talkffi, now I will show how it is used.

Planning.

1) Create a very small example code C
2) Generate code with TalkFFI
3) View de Results
4) Use the bindings

1) Example in C

-In a folder create a file ‘example.c’

-Write code, for example:

int sum(int a, int b){return a+b;}

-Create file example.h, and declare the functions that you’ll would used, in this case:

int sum(int a, int b);

-Generate dynamic library.

#compile $gcc -m32 -c example.c
#generate .so, .dll or dylib according to the system
$gcc -shared -m32 -o example.so example.o

2) Generate code with TalkFFI

Follow the steps in the previous tutorial[1]

3) View the Results.

TalkFFI generate two packages in Pharo: *-FFI-Bindings and *-FFI-Types.

*The first contains at least two class: the Map class, and the H class.

The function of the Map class is provide the utilities to comunicate with NativeBoost; and the H’s class, contain the callback functions that it define.

*The second packages contains the definition of the external structs, external enum and native boost callbacks

4) Use the bindings.

To use, you need modify the mehod libraryNameOrHandle in the class *Map with your example.so path. Then in a workspace write this.

ExampleMap inicialize.
#and call the function you need
ExampleH uniqueInstance sum: 2 b: 1.

[1] https://rochiamaya.wordpress.com/2013/07/30/create-bindings-with-talkffi/

Create Bindings with TalkFFI

Posted on Updated on

Second post of the proyect 🙂 [0]

In this case I will talk about how you use talkFFI.

TalkFFI enable automatic FFI(Foreing Function Interface) generation for Smalltalk and this is important because otherwise you would have to manually create the bind with the libraries made ​​in C that provide databases. For this example, I’ll create bindings for libgit2 library

Planning.
1) The environment
2) Install TalkFFI
3) Build-Essentials
4) LLVM+Clang
5) LibGit2
6) Run TalkFFI

1) The environment

Kubuntu 13.04 32bits and  Pharo 2.0 [1]

2) Install TalkFFI 1.3.1 in Pharo[2]

The actual version(1.4) don’t work. In the workspace write and Do it:

Gofer it
smalltalkhubUser: 'CipT' project: 'TalkFFI';
configurationOf: 'TalkFFI';
loadVersion: '1.3.1'.

3) Install build-essentials

It is a meta-package is nothing more than a “bundle package” is a package that will install other packages to which it refers. For build-esential, it has instructions to install the essential packages for programming in C / C +

sudo apt-get install build-essentials

4)LLVM+Clang:

TalkFFI uses libclang to parse unmodified C header files and generate FFI bindings to c libraries. LLVM interlayers provides a full build system Clang is a new compiler that supports C, Objective-C and C ++

Install LLVM and CLang tutoring following steps: http://clang.llvm.org/get_started.html

-Modify method LibraryNameOrHandle of class LibClangMap with your clang.so path and with your plataform

5)LibGit2

Download Libgit2 through direct download from the browser[3] or cloning the repository through Git:

$sudo apt-get install git
$git clone https://github.com/libgit2/libgit2.git

Compile LibGit2.

$mkdir build
$cd build
#only if you need install cmake
$sudo apt-get install cmake
#compile
$cmake /pathlibgit2/libgit-2
$cmake --build pathbuild/build

6)Run TalkFFI

Modify in class TalkFFIExamples the methods libgit2 to link with my paths

– Inicialize LibClangMap in the workspace

 LibClangMap initialize

-and generate code:

 TalkFFIExamples libgit2Mapping


In Pharo If it’s ok, you view a similiar message 🙂

Captura de pantalla de 2013-08-03 12:37:23

[0]https://rochiamaya.wordpress.com/2013/07/28/mi-proyect/

[1]http://www.pharo-project.org/pharo-download

[2]http://smalltalkhub.com/#!/~CipT/TalkFFI

[3]https://github.com/libgit2/libg

How to install version 1.4.6 of OpenDBX for Linux

Posted on Updated on

Hi!

This is officially  my first tutorial.

During the last days I was playing around with Pharo ( http://www.pharo-project.org/ ) due to a project that I’m  making  in this language [0].  As a first step, I had to install the OpenDBX C library that provides a unified and coherent API for software developers to manage different databases (http://www.linuxnetworks.de/doc/index.php/OpenDBX). This wasn’t  simple, and for people that isn’t used to the operating system libraries (like me) it may  be a little more difficult.

In short, let’s talk about how to install OpenDBX1.4.6  in our operating system(Linux Mint 14.1 32 bits) and its communication with Pharo2.0, and including some advice or tips.

[0]https://rochiamaya.wordpress.com/2013/07/28/mi-proyect/

Planning:

1) Requirements

2) Installing the OpenDBX library

3) Ensure everything was installed correctly

4) Interaction with Pharo 2.0

Let’s start.

1) Requirements:

As the first step, we will install all the pre-requisites needed for building, compiling and running opendbx. We will need at least one database to interact with and test that our installation was successful, I selected MySQL  but any other database is more or less the same. To do this we need

we need to install the client, server and development database packages, and create a database.

We will use the server to create the database.We’ll use the client to make requests to the server. And we’ll use the dev package which  contains the library written in C (programming language)  to communicate with OpenDBX. I installed the server, the client and the dev package with the following command in console:

$sudo apt-get install mysql-client mysql-server libmysqlclient-dev

To install OpenDBX you need to install some packages:

$sudo apt-get install autotools-dev dh-make devscripts build-essential libreadline-dev libncurses-dev

* Download OpenDBX.

I will download the source code (or code without compiling) and compile it, thus avoiding problems of architecture or Linux version for which was compiled binary and it is not compatible with our version.

http://www.linuxnetworks.de/doc/index.php/OpenDBX/Download#Latest_stable_release

2)Installing the OpenDBX library

#Create a folder called i.e. 'openDBX'
mkdir openBDX
#Copy to 'openDBX' the file you downloaded and unzip it into the same folder
cd openDBX
cp /home/theuser/Download/openDBX1.4.6.tar.gz ./
tar zvxj openDBX1.4.6.tar.gz
cd openDBX1.4.6
./configure --with-backends="mysql"
make install

 

3) To make sure everything was installed correctly, there are several things to do.

3.1) Test mysql was correctly installed:

We will create a database called ‘sodbxtest “because their test OpenDBXDriver class reference a database named in this way. Thus saved us modify methods of the class. Ditto with the user and password

#Create database
$mysqladmin -u root -p create sodbxtest
#To display the base put:
$mysql -u root  -p sodbxtest
#create user ‘sodbxtest’
$CREATE USER sodbxtest@localhost IDENTIFIED BY ‘sodbxtest’ ;
#Put password
$mysql -u sodbxtest -p
#enter and insert password sodbxtest
#Assing permissions
$GRANT ALL ON  sodbxtest.*  TO  'sodbxtest@'localhost';

3.2) Check that everything was installed correctly.

We need the libraries and we need to be accessible by applications. Then we have to install in / usr / lib. We move our libraries (the. So) to the / usr / lib / opendbx and create a symlink from / usr / lib to / usr / lib / opendbx. Steps:

– Check inside the folder ‘open’ were created  libopen.deb and libopen-backend.deb

– Check inside …/open/opendbx.1.4.6/debian/libopendbx1/usr/lib if they were created .so

– Check if in the / usr / lib libopendbx.so is the link, if that is not, we should make a symbolic link

#to crete a symbolic link yo execute de following command:
$ln -s [path to the script] ./[name direct access]
$ln -s /open/opendbx.1.4.6/debian/libopendbx1/ /usr/lib/opendbx.so

3.4) Run test  openDBX library

cd /open/opendbx/test
./odbxtest -b mysql -p3306 -d sodbxtest -u sodbxtest  -w sodbxtest
#(-b backend) (-p port)(-d database-name)(-u user)(-w password)

4) Interaction with Pharo 2.0.

4.1)Install in Pharo

Gofer it
smalltalkhubUser: 'DBXTalk' project: 'Configurations';
configurationOf: 'OpenDBXDriver';
loadVersion: 'stable'

If variable ‘stable’ doesn’t work, replace by ‘1.2’

4.2) Run Pharo from console environment variable  because we need to communicate the operating system libraries (including opendbx) with Pharo.

$LD_LIBRARY_PATH=/usr/lib/ ./pharo shared/Pharo2.0.image

4.3) Verify FFI function calls

Open  testRunner and write FFITest and run FFITest

 4.4) Run test in pharo

Open  testRunner and write OpenDBXTest run it only this, not -extras or -Encoding  if  is OK,finish!!

Captura de pantalla de 2013-07-28 17:11:12

My project

Posted on Updated on

Hi everyone , today I want to tell you a little about a project I’m doing 😀

It all started a couple of months ago when through a friend I found out the call of the Google Summer of Code (GSOC for short) [1]. For those who don’t know, is it a program to to provide support to students and open source communities. The same has different stages: tutors and studens present project ideas, students propose themselves for the ideas the are interested to participate in, tutors decide which student will develop his idea, projects go through a vote, and a limited number of projects according merit order is accepted to be developed.

All this is to tell you that I’m a student that currently participates in GSOC for ESUG [2] [3] in particular for a project in Pharo.I have as tutor  Guillermo Polito who proposed the subject  DBXTalk [4] on NativeBoost [5].

DBXtalk is a suite of tools that has as purpose to facilitate the communication done in Pharo model with different databases. DBXTalk inside OpenDBX for working with bindings, OpenDBX is a library written in C which is used  to provides a common interface for communication with multiple DB. This has some disadvantages, the main one is that openDBX is written in the C language, which makes the installation difficult because we left the Pharo environment and can have errors due to lack of units in our operating system, it takes time to set up and for non-programmers C, OpenDBX is a black box where we don’t know it’s inside and how it work with it.

 

What is ‘DBXTalk on NativeBoost’[6]?

The project is about eliminating the need to use the library OpenDBX, replacing the old FFI with NativeBoost bindings to the specific database libraries using TalkFFi to generate code. The new bindings’ll be writed in Smalltalk.

 

In the next post, I’m write about this proyect and how is it made.

[1] http://www.google-melange.com/gsoc/homepage/google/gsoc2013

[2] http://www.esug.org/

[3] http://gsoc2013.esug.org/

[4] http://dbxtalk.smallworks.com.ar/

[5] https://code.google.com/p/nativeboost/

[6] http://gsoc2013.esug.org/projects/dbxtalk-on-nativeboost

Hi!

Posted on

I introduce myself, I’m Rocio, one student Argentina systems. I’m no kind of expert or anything similar, I’m just a curious person.

What is purpose of this blog?

Mainly keeping track of the things I’m learning and to have a back up of my mind. If someone can also be useful as exposed here, I’ll be happy

Note: I don’t have a good English, so I will learn to write over the post.

Greetings 🙂