Skip to content

Commit

Permalink
Postfix for #8197: Add generated files for OO API for C language to d…
Browse files Browse the repository at this point in the history
…istribution; Use macros instead functions, removed static library
  • Loading branch information
AlexPeshkoff committed Sep 5, 2024
1 parent 446b436 commit 3a993ad
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6,788 deletions.
2 changes: 0 additions & 2 deletions builds/install/arch-specific/linux/makeInstallImage.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ copyFiles() {

#include (.h .pas files)
cp $BuiltFBDir/include/*.h ${TargetDir}@FB_INCDIR@
# cp $BuiltFBDir/include/firebird/impl/iberror_c.h ${TargetDir}@FB_INCDIR@/firebird/impl
cp $BuiltFBDir/include/firebird/*.h ${TargetDir}@FB_INCDIR@/firebird
tar -C $BuiltFBDir/include/firebird -cf - impl | tar -C ${TargetDir}@FB_INCDIR@/firebird -x
if [ "$CLIENT_ONLY_FLG" = "N" ]; then
Expand All @@ -262,7 +261,6 @@ copyFiles() {
if [ "$CLIENT_ONLY_FLG" = "N" ]; then
cp -f $BuiltFBDir/lib/libib_util.so ${TargetDir}@FB_LIBDIR@/libib_util.so
fi
copyIfExists $BuiltFBDir/lib/libfb_c_api.a ${TargetDir}@FB_LIBDIR@

if [ "$TomMathBuild" = "Y" ]; then
makeDirs @FB_LIBDIR@/.tm
Expand Down
2 changes: 1 addition & 1 deletion builds/install/posix-common/posixLibrary.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ createLinksInSystemLib() {
origDirLinksInSystemLib=`pwd`

cd @FB_LIBDIR@
Libraries=`echo libfbclient.@SHRLIB_EXT@* libib_util.@SHRLIB_EXT@ libfb_c_api.a`
Libraries=`echo libfbclient.@SHRLIB_EXT@* libib_util.@SHRLIB_EXT@`

cd /
for l in $Libraries
Expand Down
21 changes: 4 additions & 17 deletions builds/posix/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ API_PAS_FILE=$(INCLD_ROOT)/gen/Firebird.pas
API_C_HEADER=fb_c_api.h
API_C_H_FILE=$(FIREBIRD)/include/firebird/$(API_C_HEADER)
API_C_TMP_FILE=$(TMP_ROOT)/fb_c_api.tmp
API_C_IMPL_FILE=$(INCLD_ROOT)/gen/fb_c_api.c
API_C_TEMPLATE=$(IDL_ROOT)/fb_c_api.hdr
API_C_LIBRARY=$(LIB)/libfb_c_api.a
API_C_TMP_OBJ=$(TMP_ROOT)/fb_c_api.obj
MISC=$(SRC_ROOT)/misc
PAS_ROOT=$(MISC)/pascal
PASCAL_SOURCES=$(wildcard $(PAS_ROOT)/*)
Expand All @@ -136,20 +133,17 @@ RPL_AWK_SRC=$(MISC)/def_awk.c
RPL_GREP=$(GEN_ROOT)/isc_grep
RPL_GREP_SRC=$(MISC)/isc_grep.c

updateCloopInterfaces : $(API_H_FILE) $(API_PAS_FILE)
updateCloopInterfaces : $(API_H_FILE) $(API_PAS_FILE) $(API_C_H_FILE)

$(API_H_FILE): $(IDL_FILE)
$(CLOOP) $< c++ $@ IDL_FB_INTERFACES_H Firebird I

$(API_C_TMP_FILE): $(IDL_FILE)
$(CLOOP) $< c-header $@ FB_C_API_H I
$(CLOOP) $< c-header $@ FB_C_API_H I macro

$(API_C_H_FILE): $(API_C_TEMPLATE) $(API_C_TMP_FILE)
cat $(API_C_TEMPLATE) $(API_C_TMP_FILE) >$(API_C_H_FILE)

$(API_C_IMPL_FILE): $(IDL_FILE)
$(CLOOP) $< c-impl $@ $(API_C_HEADER) I

#
# This way firebird.pas can be created not using own mini-utilities.
# They were added to be able to build on windows, this code is left for reference.
Expand Down Expand Up @@ -707,13 +701,13 @@ $(COMPAT_SQL): $(SRC_COMPAT_SQL)
# all the rest we need to build
#

.PHONY: message_file tzdata gbak_files api_c_library
.PHONY: message_file tzdata gbak_files

FDB_FILES := $(SECURITY_FDB) $(FIREBIRD)/examples/empbuild/employee.fdb
GBAK_FILES := $(FDB_FILES:.fdb=.gbak)
GBAK_FILES := $(subst Native,$(TARGET),$(GBAK_FILES))

rest: tzdata api_c_library
rest: message_file tzdata

cross_rest: tzdata
$(MAKE) $(BUILD_FILE)
Expand All @@ -739,13 +733,6 @@ $(BUILD_FILE): $(BUILD_Objects)

gbak_files: $(GBAK_FILES)

api_c_library: $(API_C_LIBRARY)

$(API_C_LIBRARY): $(API_C_IMPL_FILE) $(API_C_H_FILE) $(FIREBIRD_MSG) # use $(FIREBIRD_MSG) as timemark for iberror_c.h
$(CC) $(WCFLAGS) -I$(FIREBIRD)/include -c $(API_C_IMPL_FILE) -o $(API_C_TMP_OBJ)
-$(RM) $@
$(STATICLIB_LINK) $@ $(API_C_TMP_OBJ)


#---------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/01.create.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* MODULE: 01.create.c
* DESCRIPTION: Minimal sample of using interfaces from plain C.
*
* Run something like this to build: cc 01.create.c -lfb_c_api -lfbclient
* Run something like this to build: cc 01.create.c -lfbclient
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
Expand Down
69 changes: 56 additions & 13 deletions extern/cloop/src/cloop/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,16 @@ void CppGenerator::generate()


CHeaderGenerator::CHeaderGenerator(const string& filename, const string& prefix, Parser* parser,
const string& headerGuard)
const string& headerGuard, const std::string& parMacro)
: CBasedGenerator(filename, prefix, false),
parser(parser),
headerGuard(headerGuard)
headerGuard(headerGuard),
macro(false)
{
if (parMacro.length() > 0 && parMacro != "macro")
throw runtime_error("Last (#6) param should be exactly 'macro' or missing");

macro = parMacro.length() > 0;
}

void CHeaderGenerator::generate()
Expand Down Expand Up @@ -824,26 +829,64 @@ void CHeaderGenerator::generate()
{
Method* method = *j;

fprintf(out, "CLOOP_EXTERN_C %s %s%s_%s(%sstruct %s%s* self",
convertType(method->returnTypeRef).c_str(),
prefix.c_str(),
interface->name.c_str(),
method->name.c_str(),
(method->isConst ? "const " : ""),
prefix.c_str(),
interface->name.c_str());
if (macro)
{
fprintf(out, "#define %s%s_%s(self",
prefix.c_str(),
interface->name.c_str(),
method->name.c_str());
}
else
{
fprintf(out, "CLOOP_EXTERN_C %s %s%s_%s(%sstruct %s%s* self",
convertType(method->returnTypeRef).c_str(),
prefix.c_str(),
interface->name.c_str(),
method->name.c_str(),
(method->isConst ? "const " : ""),
prefix.c_str(),
interface->name.c_str());
}

for (vector<Parameter*>::iterator k = method->parameters.begin();
k != method->parameters.end();
++k)
{
Parameter* parameter = *k;

fprintf(out, ", %s %s",
convertType(parameter->typeRef).c_str(), parameter->name.c_str());
if (macro)
{
fprintf(out, ", %s",
parameter->name.c_str());
}
else
{
fprintf(out, ", %s %s",
convertType(parameter->typeRef).c_str(), parameter->name.c_str());
}
}

fprintf(out, ");\n");
if (macro)
{
fprintf(out, ") %s(self)->vtable->%s(self",

This comment has been minimized.

Copy link
@asfernandes

asfernandes Sep 8, 2024

Member

Should not self passed as first argument also be changed to (self)?

This comment has been minimized.

Copy link
@aafemt

aafemt Sep 8, 2024

Contributor

No. It is already naturally delimited by argument syntax.

method->returnTypeRef.token.type != Token::TYPE_VOID ? "(" : "",
method->name.c_str());

for (vector<Parameter*>::iterator k = method->parameters.begin();
k != method->parameters.end();
++k)
{
Parameter* parameter = *k;

fprintf(out, ", (%s)",
parameter->name.c_str());
}

fprintf(out, ")%s\n",
method->returnTypeRef.token.type != Token::TYPE_VOID ? ")" : "");
}
else
fprintf(out, ");\n");
}

fprintf(out, "\n");
Expand Down
3 changes: 2 additions & 1 deletion extern/cloop/src/cloop/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ class CHeaderGenerator : public CBasedGenerator
{
public:
CHeaderGenerator(const std::string& filename, const std::string& prefix, Parser* parser,
const std::string& headerGuard);
const std::string& headerGuard, const std::string& macro);

public:
virtual void generate();

private:
Parser* parser;
std::string headerGuard;
bool macro;
};


Expand Down
7 changes: 5 additions & 2 deletions extern/cloop/src/cloop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ static void run(int argc, const char* argv[])
else if (outFormat == "c-header")
{
if (argc < 6)
throw runtime_error(paramError("c-header", "headerGuard prefix"));
throw runtime_error(paramError("c-header", "headerGuard prefix [macro]"));

string headerGuard(argv[4]);
string prefix(argv[5]);
string macro;
if (argc == 7)
macro = argv[6];

generator.reset(new CHeaderGenerator(outFilename, prefix, &parser, headerGuard));
generator.reset(new CHeaderGenerator(outFilename, prefix, &parser, headerGuard, macro));
}
else if (outFormat == "c-impl")
{
Expand Down
Loading

0 comments on commit 3a993ad

Please sign in to comment.