hb_CompileFromBuf() and compiling code at runtime

405 views
Skip to first unread message

Klas Engwall

unread,
Jun 3, 2014, 7:22:54 PM6/3/14
to harbou...@googlegroups.com
Hi everyone,

A recent thread with subject "control structures (if, while, etc...)
within a pcode" discussed compiling code at runtime using codeblocks or
the hb_CompileFromBuf() function. In that thread I mentioned, based on
what I had found in the changelog and old newsgroup messages, that the
GPL license would apply on code using that function since it, in turn,
uses the compiler, which is GPL only. It seems that what I said there
needs to be slightly modified.

To begin with, this can be found in the changelog:
--------------------------
2012-10-17 09:56 UTC+0200 Viktor Szakats (harbour syenar.net)
* utils/hbmk2/hbmk2.prg
+ added note about the requirement of GPL license next to all
hb_compile()/hb_compileFromBuf() calls.
--------------------------

And the comment in hbmk2.prg says:
--------------------------
/* We can use this function as this is a GPL licenced application */
--------------------------
It exists in several places in the hbmk2 source code where files are
read from disk and compiled with hb_CompileFromBuf()

That seems clear enough, but there is a thread about .hrb files in the
harbour-devel newsgroup where a comment from Viktor says something
slightly different:

https://groups.google.com/forum/#!searchin/harbour-devel/.HRB$20Files$20-$20Some$20Clarifications$20-$20Feature$20Requests/harbour-devel/VmzpxhA4frM/S4LPR4ThvagJ

And Viktor's comment says:
--------------------------
"Using .hrb files or including .hrb files don't have
any licensing implications. Just use them.

The only thing that's not allowed for closed source
apps, is to accept .prg and compile it to .hrb. Unless
you bundle harbour.exe with your app and make an
external call to do the compilation."
--------------------------

The important words seem to be "accept .prg and compile it". So, based
on that comment, it seems that a code snippet that is built at runtime
and compiled with hb_CompileFromBuf() should be OK in a closed source
application but not an existing code snippet in a .prg file that is read
into a buffer and compiled at runtime (but then again, if it is
precompiled to .hrb it is OK just like it would be with a dll).

If my interpretation is correct, I believe that this covers the
situation originally described by Diego Risi, where he wanted to build a
codeblock like this at runtime (although the syntax would be slightly
different):
--------------------------
bBlock := &('{ || if .t.'+chr(13)+chr(10)+;
'qout("test OK")'+chr(13)+chr(10)+'endif }')
--------------------------

Anyone with a different interpretation?

For those who have not read the harbour-devel newsgroup today: In
response to a feature request from Diego there was a post by Alexander
Kresin, who, many years ago, was involved in writing the code that runs
.hrb files. This is what he suggested, slightly modified by yours truly
for readability and to demonstrate passing arguments and returning results:

--------------------------
REQUEST QOUT
FUNCTION Main
Local cBuf, buf

cBuf := 'Function A1( nVal )' + hb_eol() +;
'if .t.' + hb_eol() +;
'qout("test > OK")' + hb_eol() +;
'endif' + hb_eol() +;
'Return nVal * 2' + hb_eol()

buf := hb_compileFromBuf( cBuf, "harbour", "/n" )
? hb_hrbRun( buf, 123 ) // Pass argument 123

RETURN nil
--------------------------

Regards,
Klas

elch

unread,
Jun 3, 2014, 10:18:14 PM6/3/14
to harbou...@googlegroups.com

Hi Klas,


my 2 cents as non lawyer

i believe, we have to distinguish between the use of the macro operator '&' and this new to me hb_compile*().

With the macro operator we are not able to create a new 'real' function, we only combine/ group ready compiled functions calls

( maybe our ones or Harbour ones, and maybe with control structures like IIF() ).


With your hb_compileFromBuf() example, it looks like real compiling something new, which we then can execute by its name 'A1()' ?


In opposite to Viktor i fear there is a trapdoor:

Example: if i make a run call to (GPL) picture displayer, this could be regularly replaced by another picture displayer - so my app does not rely on one specific GPL app.

But with what a Harbour compiler call would be replaceable ? - and more if this is a central part of my app, and without it won't work?


And fom Wikipedia ( section: Communicating and bundling with non-GPL program )

By contrast [..] command-line arguments are communication mechanisms normally used between two separate programs.

So when they are used for communication, the modules normally are separate programs.

But if the semantics of the communication are intimate enough, exchanging complex internal data structures, that too could be a basis to consider the two parts as combined into a larger program.

[ which makes my app to a GPL app ]

..

[ http://en.wikipedia.org/wiki/GNU_General_Public_License ]


best regards

Rolf

Francesco Perillo

unread,
Jun 3, 2014, 11:40:52 PM6/3/14
to harbou...@googlegroups.com

Viktor wrote that since hbmk2 is GPL, he could use HB_compile* functions.
If hbmk2 was closed source he should have called harbour.exe

vszakats

unread,
Jun 4, 2014, 5:35:39 AM6/4/14
to harbou...@googlegroups.com
Hi Klas and all,

I'm can't see any contradiction in what I wrote in the past.
To to put it simply, if you have a .prg source (be it generated, 
or as-is on disk, it doesn't matter), you have to call hb_Compile[FromBuf]() 
to convert it to pcode in order to execute it. To make that call, 
the caller code must be GPL. The other option is to make an 
external call to harbour executable to do the .prg -> .hrb conversion, 
or to distribute .hrb files.

[ All this is so to disallow creating a closed-source, Harbour 
derivative compiler. ]

Macros are just fine (and BTW you can use IIF() and 
HB_FORNEXT() in such macros), and using HB_HRB*() 
functions are also fine regardless of the license.

--Viktor

Klas Engwall

unread,
Jun 4, 2014, 3:39:29 PM6/4/14
to harbou...@googlegroups.com
Hi Viktor,

> I'm can't see any contradiction in what I wrote in the past.
> To to put it simply, if you have a .prg source (be it generated,
> or as-is on disk, it doesn't matter), you have to call
> hb_Compile[FromBuf]()
> to convert it to pcode in order to execute it. To make that call,
> the caller code must be GPL. The other option is to make an
> external call to harbour executable to do the .prg -> .hrb conversion,
> or to distribute .hrb files.

That is how I had understood it before yesterday (and I also said in the
previous thread about codeblocks and compiling at runtime about a week ago).

The doubts came up when Alexander Kresin yesterday suggested
hb_CompileFromBuf() plus hb_HrbRun() as a solution to Diego Risi's
feature request regarding a way to handle code like the following:

local cBlock := &('{ || if .t.'+chr(13)+chr(10)+;
' qout("test OK")'+chr(13)+chr(10)+'endif }')

So we are back where we started, and in the end Alexander's suggestion
is only useful in the few cases where the application programmer is
prepared to release his code under GPL, and it is not in reality a
solution to what Diego requested.

Thanks for jumping in.

Regards,
Klas

Amos

unread,
Jun 4, 2014, 4:16:59 PM6/4/14
to harbou...@googlegroups.com
Hello everyone,

isn't the question if these functions are covered by the Harbour exception, which is: 

"The exception is that, if you link the Harbour libraries with other 
files to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public License.
Your use of that executable is in no way restricted on account of
linking the Harbour library code into it."

Here is an explanation regarding the exception from the FAQ: http://harbour.github.io/faq/harbour17.html

The only thing which I find not clear is what exactly "Harbour libraries" are. But as the source code of hb_compile* function includes this exception I would believe the libraries made from this source code are covered by it. Or am I missing something here?

Regards
Amos

Klas Engwall

unread,
Jun 4, 2014, 5:30:38 PM6/4/14
to harbou...@googlegroups.com
Hi Amos,

> isn't the question if these functions are covered by the Harbour
> exception, which is:
>
> "The exception is that, if you link the Harbour libraries with other
> files to produce an executable, this does not by itself cause the
> resulting executable to be covered by the GNU General Public License.
> Your use of that executable is in no way restricted on account of
> linking the Harbour library code into it."
>
> Here is an explanation regarding the exception from the FAQ:
> http://harbour.github.io/faq/harbour17.html
>
> The only thing which I find not clear is what exactly "Harbour
> libraries" are. But as the source code of hb_compile* function includes
> this exception I would believe the libraries made from this source code
> are covered by it. Or am I missing something here?

Confusing, isn't it? :-)

But the explanation to that is that when the hb_Compile*() functions in
hbcmplib.c were rewritten from scratch by Przemek in 2007, he added the
"Harbour exception" to the license, but the code called *by* those
functions is still the original GPL only code.

If Przemek finds the time, he is planning to rewrite the remaining parts
of the compiler and release those parts too with the Harbour exception
(but that is a big job). You can read about it in his post in the
harbour-devel newsgroup today:

https://groups.google.com/d/msg/harbour-devel/SQb-VLE2C6o/4vIyi5M-H3AJ

Regards,
Klas

Amos

unread,
Jun 5, 2014, 3:36:10 PM6/5/14
to harbou...@googlegroups.com
Hi Klas,

Yes it is, thanks for the link - now I understand the issue!

Regards
Amos
Reply all
Reply to author
Forward
0 new messages