RPA Toolkit
dev
authormstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Sat, 10 Jul 2010 12:24:44 +0000 (05:24 -0700)
committermstoilov <mstoilov@b0bb84a5-424d-4f98-af44-3ef3f117eb03>
Sat, 10 Jul 2010 12:24:44 +0000 (05:24 -0700)
git-svn-id: svn+ssh://svn.crossrain.com/svn/rpase/trunk/rtk@122 b0bb84a5-424d-4f98-af44-3ef3f117eb03

16 files changed:
arch/linux/x86_64/rtypes.h [new file with mode: 0644]
buildtemplate/linux/robject.mk [new file with mode: 0644]
buildtemplate/linux/x86_64/Makefile [new file with mode: 0644]
rlib/build/linux/rlib.mk [new file with mode: 0644]
rlib/build/linux/x86_64/Makefile [new file with mode: 0644]
rlib/rmem.c [new file with mode: 0644]
rlib/rmem.h [new file with mode: 0644]
robject/Makefile [new file with mode: 0644]
robject/build/linux/robject.mk [new file with mode: 0644]
robject/build/linux/x86_64/Makefile [new file with mode: 0644]
robject/robject.c [new file with mode: 0644]
robject/robject.h [new file with mode: 0644]
tests/Makefile [new file with mode: 0644]
tests/build/linux/robject-tests.mk [new file with mode: 0644]
tests/build/linux/x86_64/Makefile [new file with mode: 0644]
tests/robject-ver.c [new file with mode: 0644]

diff --git a/arch/linux/x86_64/rtypes.h b/arch/linux/x86_64/rtypes.h
new file mode 100644 (file)
index 0000000..01efc97
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef _RTYPES_H_
+#define _RTYPES_H_
+
+/*
+ * Common types. These types should be the same for most of the architectures.
+ */
+typedef long rlong;
+typedef int rint;
+typedef short rshort;
+typedef char rchar;
+typedef unsigned long rulong;
+typedef unsigned int ruint;
+typedef unsigned short rushort;
+typedef unsigned char ruchar;
+typedef double rdouble;
+typedef float rfloat;
+typedef rint rboolean;
+typedef void *rpointer;
+typedef const void *rconstpointer;
+
+
+/* 
+ * Architecture dependent types. These types have to be redifined 
+ * for every architecture
+ */
+typedef signed char rint8;
+typedef unsigned char ruint8;
+typedef signed short rint16;
+typedef unsigned short ruint16;
+typedef signed int rint32;
+typedef unsigned int ruint32;
+typedef signed long rint64;
+typedef unsigned long ruint64;
+typedef unsigned long rword;
+
+
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((rpointer)0)
+#endif
+#endif
+
+#endif
+
diff --git a/buildtemplate/linux/robject.mk b/buildtemplate/linux/robject.mk
new file mode 100644 (file)
index 0000000..e8a6135
--- /dev/null
@@ -0,0 +1,38 @@
+ROBJECT_SRCDIR = $(SRCDIR)/robject
+ROBJECT_LIB = $(OUTDIR)/librobject.a
+ROBJECT_SO = $(OUTDIR)/librobject.so.1.0
+
+ROBJECT_OBJECTS =      \
+       $(OUTDIR)/robject.o \
+
+
+ifeq ($(OS), linux)
+all: $(OUTDIR) $(ROBJECT_LIB) $(ROBJECT_SO)
+else
+all: $(OUTDIR) $(ROBJECT_LIB)
+endif
+
+
+$(OUTDIR)/%.o: $(ROBJECT_SRCDIR)/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(ROBJECT_SRCDIR)/$*.c
+
+$(ROBJECT_LIB): $(ROBJECT_OBJECTS)
+       $(AR) -cr $@ $^
+
+$(ROBJECT_SO): $(ROBJECT_OBJECTS)
+       $(CC) $(LDFLAGS) -shared -Wl,-soname,librobject.so -o $@ $^
+
+$(OUTDIR):
+       @mkdir $(OUTDIR)
+
+distclean: clean
+       @rm -f .depend
+       @rm -rf $(OUTDIR)
+
+clean:
+       @rm -f $(ROBJECT_LIB)
+       @rm -f $(ROBJECT_SO)
+       @rm -f $(ROBJECT_OBJECTS)
+       @rm -f *~
+       @rm -f $(SRCDIR)/*~
+
diff --git a/buildtemplate/linux/x86_64/Makefile b/buildtemplate/linux/x86_64/Makefile
new file mode 100644 (file)
index 0000000..6351e13
--- /dev/null
@@ -0,0 +1,25 @@
+SRCDIR = ../../..
+ARCHDIR = $(shell basename $(shell pwd))
+OUTDIR = out
+OS = $(shell uname | tr "[:upper:]" "[:lower:]")
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR)
+
+CC = gcc
+AR = ar
+LD = ld
+
+ifeq ($(BLDCFG), release)
+CFLAGS := -fPIC -O3
+else
+CFLAGS := -fPIC -O0 -ggdb -Wall 
+endif
+
+ifeq ($(CCBLD), yes)
+CFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+CFLAGS += $(MACH) $(INCLUDE)
+LDFLAGS := $(MACH)
+
+
+include ../robject.mk
diff --git a/rlib/build/linux/rlib.mk b/rlib/build/linux/rlib.mk
new file mode 100644 (file)
index 0000000..86d8e21
--- /dev/null
@@ -0,0 +1,38 @@
+RLIB_SRCDIR = $(SRCDIR)/rlib
+RLIB_LIB = $(OUTDIR)/librlib.a
+RLIB_SO = $(OUTDIR)/librlib.so.1.0
+
+RLIB_OBJECTS = \
+       $(OUTDIR)/rmem.o \
+
+
+ifeq ($(OS), linux)
+all: $(OUTDIR) $(RLIB_LIB) $(RLIB_SO)
+else
+all: $(OUTDIR) $(RLIB_LIB)
+endif
+
+
+$(OUTDIR)/%.o: $(RLIB_SRCDIR)/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(RLIB_SRCDIR)/$*.c
+
+$(RLIB_LIB): $(RLIB_OBJECTS)
+       $(AR) -cr $@ $^
+
+$(RLIB_SO): $(RLIB_OBJECTS)
+       $(CC) $(LDFLAGS) -shared -Wl,-soname,librlib.so -o $@ $^
+
+$(OUTDIR):
+       @mkdir $(OUTDIR)
+
+distclean: clean
+       @rm -f .depend
+       @rm -rf $(OUTDIR)
+
+clean:
+       @rm -f $(RLIB_LIB)
+       @rm -f $(RLIB_SO)
+       @rm -f $(RLIB_OBJECTS)
+       @rm -f *~
+       @rm -f $(SRCDIR)/*~
+
diff --git a/rlib/build/linux/x86_64/Makefile b/rlib/build/linux/x86_64/Makefile
new file mode 100644 (file)
index 0000000..b2c8b7a
--- /dev/null
@@ -0,0 +1,25 @@
+SRCDIR = ../../../..
+ARCHDIR = $(shell basename $(shell pwd))
+OUTDIR = out
+OS = $(shell uname | tr "[:upper:]" "[:lower:]")
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR)
+
+CC = gcc
+AR = ar
+LD = ld
+
+ifeq ($(BLDCFG), release)
+CFLAGS := -fPIC -O3
+else
+CFLAGS := -fPIC -O0 -ggdb -Wall 
+endif
+
+ifeq ($(CCBLD), yes)
+CFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+CFLAGS += $(MACH) $(INCLUDE)
+LDFLAGS := $(MACH)
+
+
+include ../rlib.mk
diff --git a/rlib/rmem.c b/rlib/rmem.c
new file mode 100644 (file)
index 0000000..ce35783
--- /dev/null
@@ -0,0 +1,85 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "rmem.h"
+
+long int g_allocmem = 0;
+long int g_maxmem = 0;
+
+
+rpointer r_malloc(unsigned long size)
+{
+#ifdef RPA_DEBUG_MEM
+       rword *mem = NULL;
+       size += sizeof(rword);
+       mem = (rword*)malloc((size_t)(size));
+       *((rword*)mem) = size;
+       g_allocmem += size;
+       if (g_maxmem < g_allocmem)
+               g_maxmem = g_allocmem;
+       mem += 1;
+       return (void*)mem;
+#else
+       return malloc((size_t)size);
+#endif
+}
+
+
+void *r_zmalloc(unsigned long size) {
+       void *mem;
+
+       if ((mem = r_malloc(size)))
+               r_memset(mem, 0, size);
+       return mem;
+}
+
+void r_free(void *ptr)
+{
+#ifdef RPA_DEBUG_MEM
+       rword *mem = (void*)(((rword*)ptr) - 1);
+       rword size;
+       if (!ptr)
+               return;
+       size = *mem;
+       g_allocmem -= size;
+//     fprintf(stdout, "%p (%ld de-allocated)\n", (void*)mem, size);
+       free((void*)mem);
+#else
+       free(ptr);
+#endif
+}
+
+
+void *r_realloc(void *ptr, unsigned long size)
+{
+#ifdef RPA_DEBUG_MEM
+       rword *mem = (void*)(((rword*)ptr) - 1);
+       rword csize;
+       if (!ptr)
+               return r_malloc(size);
+       csize = *mem;
+       g_allocmem -= csize;
+       size += sizeof(long);
+       mem = (rword*)realloc((void*)mem, (size_t)(size));
+       *mem = size;
+       g_allocmem += size;
+       if (g_maxmem < g_allocmem)
+               g_maxmem = g_allocmem;
+       mem += 1;
+       return (void*)mem;
+#else
+       return realloc(ptr, (size_t)size);
+#endif
+}
+
+
+void *r_memset(void *s, int c, unsigned long n)
+{
+       return memset(s, c, (size_t)n);
+}
+
+
+void *r_memcpy(void *dest, const void *src, unsigned long n)
+{
+       return memcpy(dest, src, (size_t)n);
+}
diff --git a/rlib/rmem.h b/rlib/rmem.h
new file mode 100644 (file)
index 0000000..8d5eccc
--- /dev/null
@@ -0,0 +1,27 @@
+
+#ifndef _RMEM_H_
+#define _RMEM_H_
+
+
+#include "rtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern long int g_r_allocmem;
+extern long int g_r_maxmem;
+
+
+void *r_malloc(unsigned long size);
+void *r_zmalloc(unsigned long size);
+void r_free(void *ptr);
+void *r_realloc(void *ptr, unsigned long size);
+void *r_memset(void *s, int c, unsigned long n);
+void *r_memcpy(void *dest, const void *src, unsigned long n);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/robject/Makefile b/robject/Makefile
new file mode 100644 (file)
index 0000000..578f5a2
--- /dev/null
@@ -0,0 +1,26 @@
+OS := $(shell uname | tr "[:upper:]" "[:lower:]")
+
+ifeq ($(ARCH),)
+ARCH := $(shell uname -m)
+endif
+
+ifeq ($(ARCH), i386)
+ARCHDIR := x86
+else ifeq ($(ARCH), i586)
+ARCHDIR := x86
+else ifeq ($(ARCH), i686)
+ARCHDIR := x86
+else
+ARCHDIR := x86_64
+endif
+
+all:
+       make -C build/$(OS)/$(ARCHDIR)
+
+
+clean:
+       make -C build/$(OS)/$(ARCHDIR) clean
+
+
+distclean:
+       make -C build/$(OS)/$(ARCHDIR) distclean
diff --git a/robject/build/linux/robject.mk b/robject/build/linux/robject.mk
new file mode 100644 (file)
index 0000000..e8a6135
--- /dev/null
@@ -0,0 +1,38 @@
+ROBJECT_SRCDIR = $(SRCDIR)/robject
+ROBJECT_LIB = $(OUTDIR)/librobject.a
+ROBJECT_SO = $(OUTDIR)/librobject.so.1.0
+
+ROBJECT_OBJECTS =      \
+       $(OUTDIR)/robject.o \
+
+
+ifeq ($(OS), linux)
+all: $(OUTDIR) $(ROBJECT_LIB) $(ROBJECT_SO)
+else
+all: $(OUTDIR) $(ROBJECT_LIB)
+endif
+
+
+$(OUTDIR)/%.o: $(ROBJECT_SRCDIR)/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(ROBJECT_SRCDIR)/$*.c
+
+$(ROBJECT_LIB): $(ROBJECT_OBJECTS)
+       $(AR) -cr $@ $^
+
+$(ROBJECT_SO): $(ROBJECT_OBJECTS)
+       $(CC) $(LDFLAGS) -shared -Wl,-soname,librobject.so -o $@ $^
+
+$(OUTDIR):
+       @mkdir $(OUTDIR)
+
+distclean: clean
+       @rm -f .depend
+       @rm -rf $(OUTDIR)
+
+clean:
+       @rm -f $(ROBJECT_LIB)
+       @rm -f $(ROBJECT_SO)
+       @rm -f $(ROBJECT_OBJECTS)
+       @rm -f *~
+       @rm -f $(SRCDIR)/*~
+
diff --git a/robject/build/linux/x86_64/Makefile b/robject/build/linux/x86_64/Makefile
new file mode 100644 (file)
index 0000000..633cc60
--- /dev/null
@@ -0,0 +1,25 @@
+SRCDIR = ../../../..
+ARCHDIR = $(shell basename $(shell pwd))
+OUTDIR = out
+OS = $(shell uname | tr "[:upper:]" "[:lower:]")
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR)
+
+CC = gcc
+AR = ar
+LD = ld
+
+ifeq ($(BLDCFG), release)
+CFLAGS := -fPIC -O3
+else
+CFLAGS := -fPIC -O0 -ggdb -Wall 
+endif
+
+ifeq ($(CCBLD), yes)
+CFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+CFLAGS += $(MACH) $(INCLUDE)
+LDFLAGS := $(MACH)
+
+
+include ../robject.mk
diff --git a/robject/robject.c b/robject/robject.c
new file mode 100644 (file)
index 0000000..b6d1798
--- /dev/null
@@ -0,0 +1,20 @@
+#include "robject.h"
+
+
+const char *r_object_version()
+{
+       return "0.51";
+}
+
+
+rint r_object_major_version()
+{
+       return 0;
+}
+
+
+rint r_object_minor_version()
+{
+       return 51;
+}
+
diff --git a/robject/robject.h b/robject/robject.h
new file mode 100644 (file)
index 0000000..ebf8e2e
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef _ROBJECT_H_
+#define _ROBJECT_H_
+
+#include "rtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+rint r_object_major_version();
+rint r_object_minor_version();
+
+typedef enum _RVariantType {
+       R_TYPE_NONE = 0,
+       R_TYPE_LONG,
+       R_TYPE_INT,
+       R_TYPE_SHORT,
+       R_TYPE_CHAR,
+       R_TYPE_STRING,
+       R_TYPE_POINTER,
+} RVariantType;
+       
+
+typedef struct _RString {
+       rchar *ptr;
+       rulong size;
+} RString;
+
+
+typedef struct _RVariant {
+       RVariantType type;
+       union {
+               rlong v_long;
+               rint v_int;
+               rshort v_short;
+               rchar v_char;
+               rpointer v_pointer;
+               RString v_string;
+       } data;
+} RVariant;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..578f5a2
--- /dev/null
@@ -0,0 +1,26 @@
+OS := $(shell uname | tr "[:upper:]" "[:lower:]")
+
+ifeq ($(ARCH),)
+ARCH := $(shell uname -m)
+endif
+
+ifeq ($(ARCH), i386)
+ARCHDIR := x86
+else ifeq ($(ARCH), i586)
+ARCHDIR := x86
+else ifeq ($(ARCH), i686)
+ARCHDIR := x86
+else
+ARCHDIR := x86_64
+endif
+
+all:
+       make -C build/$(OS)/$(ARCHDIR)
+
+
+clean:
+       make -C build/$(OS)/$(ARCHDIR) clean
+
+
+distclean:
+       make -C build/$(OS)/$(ARCHDIR) distclean
diff --git a/tests/build/linux/robject-tests.mk b/tests/build/linux/robject-tests.mk
new file mode 100644 (file)
index 0000000..89cea9f
--- /dev/null
@@ -0,0 +1,32 @@
+ROBJECT_SRCDIR = $(SRCDIR)/robject
+TESTS_SRCDIR = $(SRCDIR)/tests
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR) -I$(ROBJECT_SRCDIR)
+LIBS = -L$(ROBJECT_SRCDIR)/build/$(OS)/$(ARCHDIR)/out -lrobject --static
+
+
+
+ROBJECT_OBJECTS =      \
+       $(OUTDIR)/robject.o \
+
+
+TESTS  = \
+       $(OUTDIR)/robject-ver \
+
+all : $(OUTDIR) $(TESTS)
+
+$(OUTDIR)/%: $(TESTS_SRCDIR)/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$* $(TESTS_SRCDIR)/$*.c $(LIBS) $(INCLUDE)
+
+
+$(OUTDIR):
+       @mkdir $(OUTDIR)
+
+distclean: clean
+       @rm -f .depend
+       @rm -rf $(OUTDIR)
+
+clean:
+       @rm -f $(TESTS)
+       @rm -f *~
+       @rm -f $(SRCDIR)/*~
+
diff --git a/tests/build/linux/x86_64/Makefile b/tests/build/linux/x86_64/Makefile
new file mode 100644 (file)
index 0000000..f18f6f3
--- /dev/null
@@ -0,0 +1,25 @@
+ARCHDIR = x86_64
+OUTDIR = out
+OS = $(shell uname | tr "[:upper:]" "[:lower:]")
+SRCDIR = ../../../..
+
+
+CC = gcc
+AR = ar
+ifeq ($(BLDCFG), release)
+CFLAGS = -O3 -fPIC 
+else
+CFLAGS = -fPIC -ggdb -O0 -Wall 
+endif
+
+ifeq ($(CCBLD), yes)
+CFLAGS += -fprofile-arcs -ftest-coverage
+endif
+
+CFLAGS += $(MACH) $(INCLUDE)
+
+CFLAGS := $(CFLAGS)
+LDFLAGS = $(MACH)
+
+
+include ../robject-tests.mk
diff --git a/tests/robject-ver.c b/tests/robject-ver.c
new file mode 100644 (file)
index 0000000..c6f252a
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+#include "robject.h"
+
+typedef struct _RTestStruct {
+       int i;
+       char a;
+       char b;
+} RTestStruct;
+
+int main(int argc, char *argv[])
+{
+       RTestStruct t;
+
+       fprintf(stdout, 
+                       "It works. Major: %d, Minor: %d, sizeof(t) = %lu\n", 
+                       r_object_major_version(), 
+                       r_object_minor_version(),
+                       sizeof(t));
+       return 0;
+}