In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`

Lemures Lemniscati
Hi!

In `lua.h`, `LUA_VERSION_RELEASE_NUM`  does not reflect `LUA_VERSION_RELEASE`,
and `LUA_VERSION_NUM` is hard-coded although it can be calculated from  `LUA_VERSION_MAJOR` and  `LUA_VERSION_MINOR`.

Here is a patch to fix them (a base64-encoded data is enclosed also, in case TABs are converted to spaces).

Regards,

Lem

---------------- cut here ----------------
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lemures Lemniscati <[hidden email]>
Date: Tue, 12 Jan 2021 20:17:59 +0900
Subject: [PATCH] Fix LUA_VERSION_RELEASE_NUM and LUA_VERSION_NUM

* Fix LUA_VERSION_RELEASE_NUM, so that it reflects LUA_VERSION_RELEASE
* Modify LUA_VERSION_NUM, so that it reflects LUA_VERSION_MAJOR and _MINOR

diff --git a/lua.h b/lua.h
index c9d64d7f..bef92eae 100644
--- a/lua.h
+++ b/lua.h
@@ -20,8 +20,8 @@
 #define LUA_VERSION_MINOR "4"
 #define LUA_VERSION_RELEASE "2"
 
-#define LUA_VERSION_NUM 504
-#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0)
+#define LUA_VERSION_NUM (LUA_VERSION_MAJOR * 100 + LUA_VERSION_MINOR)
+#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + LUA_VERSION_RELEASE)
 
 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE


---------------- cut here ----------------
#!/bin/sh
/usr/bin/env base64 -d << __END__ > 0001-Fix-LUA_VERSION_RELEASE_NUM-and-LUA_VERSION_NUM.patch
RnJvbSAwMDAwMDAwMDAwMD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SBMVUFfVkVSU0lPTgkiTHVhICIgTFVBX1ZFUlNJT05fTUFKT1IgIi4iIExVQV9WRVJTSU9OX01J
Tk9SCiAjZGVmaW5lIExVQV9SRUxFQVNFCUxVQV9WRVJTSU9OICIuIiBMVUFfVkVSU0lPTl9SRUxF
QVNFCg==
__END__

Reply | Threaded
Open this post in threaded view
|

Re: In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`

Thorkil Naur
Hello,

On Tue, Jan 12, 2021 at 09:06:41PM +0900, Lemures Lemniscati wrote:
> ...
> -#define LUA_VERSION_NUM 504
> -#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0)
> +#define LUA_VERSION_NUM (LUA_VERSION_MAJOR * 100 + LUA_VERSION_MINOR)
> +#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + LUA_VERSION_RELEASE)

For lua-5.4.2, this causes:

> lua.h:27:59: error: invalid operands to binary * (have ‘char *’ and ‘int’)
>    27 | #define LUA_VERSION_NUM                (LUA_VERSION_MAJOR * 100 + LUA_VERSION_MINOR)
>       |                                                           ^
> lapi.c:148:10: note: in expansion of macro ‘LUA_VERSION_NUM’
>   148 |   return LUA_VERSION_NUM;
>       |          ^~~~~~~~~~~~~~~
> lapi.c:149:1: warning: control reaches end of non-void function [-Wreturn-type]
>   149 | }
>       | ^

>  ...

LUA_VERSION_MAJOR is a string:

>  #define LUA_VERSION_MAJOR "5"

So using it as a number in C is an error.

Best
Thorkil
Reply | Threaded
Open this post in threaded view
|

Re: In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`

Lemures Lemniscati
On Tue, 12 Jan 2021 13:39:32 +0100, Thorkil Naur
>
> LUA_VERSION_MAJOR is a string:
>
> >  #define LUA_VERSION_MAJOR "5"
>
> So using it as a number in C is an error.
>
> Best
> Thorkil

Oh, I'm very embarrassed for my carelessness...
Thank you for reply, Thorkil.

Here is a another patch, and it builds successfully.

Regards,

Lem



---------------- cut here ----------------
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lemures Lemniscati <[hidden email]>
Date: Tue, 12 Jan 2021 21:49:40 +0900
Subject: [PATCH] Fix LUA_VERSION_RELEASE_NUM and LUA_VERSION_NUM


diff --git a/lua.h b/lua.h
index c9d64d7f..336fc77c 100644
--- a/lua.h
+++ b/lua.h
@@ -20,8 +20,8 @@
 #define LUA_VERSION_MINOR "4"
 #define LUA_VERSION_RELEASE "2"
 
-#define LUA_VERSION_NUM 504
-#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0)
+#define LUA_VERSION_RELEASE_NUM 50402
+#define LUA_VERSION_NUM (LUA_VERSION_RELEASE_NUM / 100)
 
 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE

---------------- cut here ----------------
#!/bin/sh
/usr/bin/env base64 -d << __END__ \
> 0001-Fix-LUA_VERSION_RELEASE_NUM-and-LUA_VERSION_NUM.patch
RnJvbSAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBMZW11cmVzIExlbW5pc2NhdGkgPGxlbXVyZXMubGVtbmlzY2F0
aUBnbWFpbC5jb20+CkRhdGU6IFR1ZSwgMTIgSmFuIDIwMjEgMjE6NDk6NDAgKzA5MDAKU3ViamVj
dDogW1BBVENIXSBGaXggTFVBX1ZFUlNJT05fUkVMRUFTRV9OVU0gYW5kIExVQV9WRVJTSU9OX05V
TQoKCmRpZmYgLS1naXQgYS9sdWEuaCBiL2x1YS5oCmluZGV4IGM5ZDY0ZDdmLi4zMzZmYzc3YyAx
MDA2NDQKLS0tIGEvbHVhLmgKKysrIGIvbHVhLmgKQEAgLTIwLDggKzIwLDggQEAKICNkZWZpbmUg
TFVBX1ZFUlNJT05fTUlOT1IJIjQiCiAjZGVmaW5lIExVQV9WRVJTSU9OX1JFTEVBU0UJIjIiCiAK
LSNkZWZpbmUgTFVBX1ZFUlNJT05fTlVNCQkJNTA0Ci0jZGVmaW5lIExVQV9WRVJTSU9OX1JFTEVB
U0VfTlVNCQkoTFVBX1ZFUlNJT05fTlVNICogMTAwICsgMCkKKyNkZWZpbmUgTFVBX1ZFUlNJT05f
UkVMRUFTRV9OVU0JNTA0MDIKKyNkZWZpbmUgTFVBX1ZFUlNJT05fTlVNCQkoTFVBX1ZFUlNJT05f
UkVMRUFTRV9OVU0gLyAxMDApCiAKICNkZWZpbmUgTFVBX1ZFUlNJT04JIkx1YSAiIExVQV9WRVJT
SU9OX01BSk9SICIuIiBMVUFfVkVSU0lPTl9NSU5PUgogI2RlZmluZSBMVUFfUkVMRUFTRQlMVUFf
VkVSU0lPTiAiLiIgTFVBX1ZFUlNJT05fUkVMRUFTRQo=
__END__
Reply | Threaded
Open this post in threaded view
|

Derive LUA_VERSION_MAJOR from LUA_VERSION_MAJOR_NUM etc. [Re: In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`]

Thorkil Naur
In reply to this post by Lemures Lemniscati
Hello,

The following code demonstrates a technique for reducing redundancy in
defining LUA_VERSION etc.:

> #include <stdio.h>
>
> #define Stringize0( x ) #x
> #define Stringize( x ) Stringize0( x )
>
> #define LUA_VERSION_MAJOR_NUM 5
> #define LUA_VERSION_MAJOR Stringize( LUA_VERSION_MAJOR_NUM )
> #define LUA_VERSION_MINOR_NUM 4
> #define LUA_VERSION_MINOR Stringize( LUA_VERSION_MINOR_NUM )
> #define LUA_VERSION_NUM LUA_VERSION_MAJOR_NUM * 100 + LUA_VERSION_MINOR_NUM
> #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
>
> int main( int argc, char *argv[] ) {
>   printf( "LUA_VERSION_MAJOR_NUM=%d\n", LUA_VERSION_MAJOR_NUM );
>   printf( "LUA_VERSION_MAJOR=<%s>\n", LUA_VERSION_MAJOR );
>   printf( "LUA_VERSION_MINOR_NUM=%d\n", LUA_VERSION_MINOR_NUM );
>   printf( "LUA_VERSION_MINOR=<%s>\n", LUA_VERSION_MINOR );
>   printf( "LUA_VERSION_NUM=%d\n", LUA_VERSION_NUM );
>   printf( "LUA_VERSION=<%s>\n", LUA_VERSION );
> }

Running this program produces the output:

> LUA_VERSION_MAJOR_NUM=5
> LUA_VERSION_MAJOR=<5>
> LUA_VERSION_MINOR_NUM=4
> LUA_VERSION_MINOR=<4>
> LUA_VERSION_NUM=504
> LUA_VERSION=<Lua 5.4>

Whether the added obscurity by using this technique is worth the reduced
redundancy is not for me to decide.

Best
Thorkil