Ada bindings for HamsterDB
Ada Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

HamsterDB_Ada is a library project which provides Ada bindings for the HamsterDB project.

How do I download it?

Use git: git clone git://

How do I build it?

Simply make, then make install. This should build a library based off of the provided Ada interface and copy the relevant files to your system. The installed library has the same version number as the HamsterDB it's generated from.

How is it used?

In an Ada project, you will have access to the HamsterDB package. This provides all of the functions and most of the types, typedefs and macros available in ham/hamsterdb.h and ham/types.h.

For the most part, the Ada interface is the same as the C interface. However, empty structures have not been converted. This means that those functions which take an opaque pointer in C, take a System.Address in Ada.

Also, all functions have had the ham_ prefix removed, with one notable exception: ham_new. Ada simply won't support a function named new, so ham_new is left as-is.

Here's an example, lifted from the HamsterDB tutorial and converted to Ada:

with HamsterDB;
with Ada.Text_IO; use Ada.Text_IO;
with System;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;

procedure HDM is
    db : System.Address := System.Null_Address;
    st : HamsterDB.status_t;
    name : chars_ptr := New_String("test.db");
    st := HamsterDB.Ham_New(db'Address);
    if st /= HamsterDB.HAM_SUCCESS then
        Put_Line("ham_new failed: " & 
        st := HamsterDB.Create_Ex(db, name, 0, 0664, null);
        if st /= HamsterDB.HAM_SUCCESS then
            Put_Line("ham_create_ex failed: " &
        end if;
        st := HamsterDB.Delete(db);
        if st /= HamsterDB.HAM_SUCCESS then
            Put_Line("ham_delete failed: " &
        end if;

    end if;

end HDM;

To compile, you need to link to both libhamsterdb and libhamsterdb_ada.

What's left to do?

A few things:

  • Refactor the transformation script. It's a bit spagetti at the moment.
  • Provide documentation; it's not really necessary, but would be nice to have.
  • Make the build/install system more portable.

Advanced Stuff

If you want to generate your own Ada interface for HamsterDB for whatever reason, (e.g. linking to a different version of HamsterDB), then there's a pretty easy way.

  • make include
  • Alter the version number in support/
  • make
  • make install

It's really, really important that you check the generated Ada spec. Generating it from a different version of HamsterDB than the one provided can result in some weird and incorrect code. You may have to alter the script, which is responsible for taking the raw output from g++ and making it "better".