Message ID | 20250610115502.2483804-1-dario.binacchi@amarulasolutions.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
Hello Dario, Le 10/06/2025 à 13:55, Dario Binacchi a écrit : > It is a portable Python 3.x interpreter, written in C11. It has no > dependencies other than the C standard library, which can be easily > integrated into your C/C++ project > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > --- > > Changes v3 -> v4: > - Replace 0001-Fix-getchar-helper.patch with 0001-fix-371.patch. > > Changes v2 -> v3: > - Add package/pocketpy/0001-Fix-getchar-helper.patch. > - Add depends on !BR2_STATIC_LIBS for dlfcn.h > > Changes v1 -> v2: > - mv staging commands under POCKETPY_INSTALL_STAGING_CMDS hook. > > DEVELOPERS | 1 + > package/Config.in | 1 + > package/pocketpy/0001-fix-371.patch | 73 +++++++++++++++++++++++++++++ > package/pocketpy/Config.in | 9 ++++ > package/pocketpy/pocketpy.hash | 3 ++ > package/pocketpy/pocketpy.mk | 25 ++++++++++ > 6 files changed, 112 insertions(+) > create mode 100644 package/pocketpy/0001-fix-371.patch > create mode 100644 package/pocketpy/Config.in > create mode 100644 package/pocketpy/pocketpy.hash > create mode 100644 package/pocketpy/pocketpy.mk > > diff --git a/DEVELOPERS b/DEVELOPERS > index a7bb3bd83460..46d24afceb71 100644 > --- a/DEVELOPERS > +++ b/DEVELOPERS > @@ -811,6 +811,7 @@ F: package/armadillo/ > F: package/babeld/ > F: package/iana-assignments/ > F: package/inih/ > +F: package/pocketpy/ > F: package/sscep/ > F: package/tinyinit/ > F: package/ufs-utils/ > diff --git a/package/Config.in b/package/Config.in > index 579b5ffc87d5..9aad65488a6c 100644 > --- a/package/Config.in > +++ b/package/Config.in > @@ -968,6 +968,7 @@ if BR2_STATIC_LIBS > comment "External PHP extensions need a toolchain w/ dynamic library" > endif > endif > + source "package/pocketpy/Config.in" > source "package/python3/Config.in" > if BR2_PACKAGE_PYTHON3 > menu "External python modules" > diff --git a/package/pocketpy/0001-fix-371.patch b/package/pocketpy/0001-fix-371.patch > new file mode 100644 > index 000000000000..6d9e324ba762 > --- /dev/null > +++ b/package/pocketpy/0001-fix-371.patch > @@ -0,0 +1,73 @@ > +From e2e3bdca6e79ce7be5607397c5f0152c28c7500b Mon Sep 17 00:00:00 2001 > +From: blueloveTH <blueloveth@foxmail.com> > +Date: Sat, 7 Jun 2025 02:19:55 +0800 > +Subject: [PATCH] fix #371 > + > +Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> > +Upstream: backport from https://github.com/pocketpy/pocketpy/commit/70e824a6b695e963621664589d1d00aeb182c018 > +--- > + include/pocketpy/pocketpy.h | 2 +- > + src/interpreter/vm.c | 6 ++++-- > + src/public/modules.c | 2 +- > + 3 files changed, 6 insertions(+), 4 deletions(-) > + > +diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h > +index a44faa41a922..a6cb4f658f73 100644 > +--- a/include/pocketpy/pocketpy.h > ++++ b/include/pocketpy/pocketpy.h > +@@ -69,7 +69,7 @@ typedef struct py_Callbacks { > + /// Used by `print` to output a string. > + void (*print)(const char*); > + /// Used by `input` to get a character. > +- int (*getchar)(); > ++ int (*getchr)(); > + } py_Callbacks; > + > + /// Native function signature. > +diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c > +index 2bae82740ac7..2da28fa80730 100644 > +--- a/src/interpreter/vm.c > ++++ b/src/interpreter/vm.c > +@@ -29,6 +29,8 @@ static char* pk_default_importfile(const char* path) { > + > + static void pk_default_print(const char* data) { printf("%s", data); } > + > ++static int pk_default_getchr() { return getchar(); } > ++ > + static void py_TypeInfo__ctor(py_TypeInfo* self, > + py_Name name, > + py_Type index, > +@@ -67,7 +69,7 @@ void VM__ctor(VM* self) { > + > + self->callbacks.importfile = pk_default_importfile; > + self->callbacks.print = pk_default_print; > +- self->callbacks.getchar = getchar; > ++ self->callbacks.getchr = pk_default_getchr; > + > + self->last_retval = *py_NIL(); > + self->curr_exception = *py_NIL(); > +@@ -810,7 +812,7 @@ int py_replinput(char* buf, int max_size) { > + printf(">>> "); > + > + while(true) { > +- int c = pk_current_vm->callbacks.getchar(); > ++ int c = pk_current_vm->callbacks.getchr(); > + if(c == EOF) return -1; > + > + if(c == '\n') { > +diff --git a/src/public/modules.c b/src/public/modules.c > +index 3efb362701e2..cdfd5549461a 100644 > +--- a/src/public/modules.c > ++++ b/src/public/modules.c > +@@ -205,7 +205,7 @@ static bool builtins_input(int argc, py_Ref argv) { > + c11_sbuf buf; > + c11_sbuf__ctor(&buf); > + while(true) { > +- int c = pk_current_vm->callbacks.getchar(); > ++ int c = pk_current_vm->callbacks.getchr(); > + if(c == '\n' || c == '\r') break; > + if(c == EOF) break; > + c11_sbuf__write_char(&buf, c); > +-- > +2.43.0 > + > diff --git a/package/pocketpy/Config.in b/package/pocketpy/Config.in > new file mode 100644 > index 000000000000..b0bd0cafe008 > --- /dev/null > +++ b/package/pocketpy/Config.in > @@ -0,0 +1,9 @@ > +config BR2_PACKAGE_POCKETPY > + bool "pocketpy" > + depends on BR2_INSTALL_LIBSTDCPP > + depends on !BR2_STATIC_LIBS # dlfcn.h > + help > + pocketpy is a portable Python 3.x interpreter, > + written in C11. > + > + https://github.com/pocketpy/pocketpy > diff --git a/package/pocketpy/pocketpy.hash b/package/pocketpy/pocketpy.hash > new file mode 100644 > index 000000000000..aabd5f077a2b > --- /dev/null > +++ b/package/pocketpy/pocketpy.hash > @@ -0,0 +1,3 @@ > +# locally computed > +sha256 5e07994d66311a6b5ac032cc5243aaabe3ab318946971e7fa1cd0614934efc81 pocketpy-2.0.8.tar.gz > +sha256 d3a2bf8ca609a75941e980e62c13cf5a21aeaa4a2502822934d282fe7de5d319 LICENSE > diff --git a/package/pocketpy/pocketpy.mk b/package/pocketpy/pocketpy.mk > new file mode 100644 > index 000000000000..20a8e9ad1e20 > --- /dev/null > +++ b/package/pocketpy/pocketpy.mk > @@ -0,0 +1,25 @@ > +################################################################################ > +# > +# pocketpy > +# > +################################################################################ > + > +POCKETPY_VERSION = 2.0.8 > +POCKETPY_SITE = $(call github,pocketpy,pocketpy,v$(POCKETPY_VERSION)) > +POCKETPY_LICENSE = MIT > +POCKETPY_LICENSE_FILES = LICENSE > +POCKETPY_INSTALL_STAGING = YES > + > +POCKETPY_CONF_OPTS = -DPK_BUILD_SHARED_LIB=ON > + > +define POCKETPY_INSTALL_TARGET_CMDS > + $(INSTALL) -D -m 0755 $(@D)/libpocketpy.so* $(TARGET_DIR)/usr/lib > +endef Note: Only libpocketpy.so file is generated, it seems there is no symlink generated. For now, I keep it as is. Applied to master, thanks. Best regards, Romain > + > +define POCKETPY_INSTALL_STAGING_CMDS > + $(INSTALL) -D -m 0755 $(@D)/libpocketpy.so* $(STAGING_DIR)/usr/lib > + $(INSTALL) -m 755 -d $(STAGING_DIR)/usr/include/pocketpy > + cp -r $(@D)/include/* $(STAGING_DIR)/usr/include/pocketpy > +endef > + > +$(eval $(cmake-package)) To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
diff --git a/DEVELOPERS b/DEVELOPERS index a7bb3bd83460..46d24afceb71 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -811,6 +811,7 @@ F: package/armadillo/ F: package/babeld/ F: package/iana-assignments/ F: package/inih/ +F: package/pocketpy/ F: package/sscep/ F: package/tinyinit/ F: package/ufs-utils/ diff --git a/package/Config.in b/package/Config.in index 579b5ffc87d5..9aad65488a6c 100644 --- a/package/Config.in +++ b/package/Config.in @@ -968,6 +968,7 @@ if BR2_STATIC_LIBS comment "External PHP extensions need a toolchain w/ dynamic library" endif endif + source "package/pocketpy/Config.in" source "package/python3/Config.in" if BR2_PACKAGE_PYTHON3 menu "External python modules" diff --git a/package/pocketpy/0001-fix-371.patch b/package/pocketpy/0001-fix-371.patch new file mode 100644 index 000000000000..6d9e324ba762 --- /dev/null +++ b/package/pocketpy/0001-fix-371.patch @@ -0,0 +1,73 @@ +From e2e3bdca6e79ce7be5607397c5f0152c28c7500b Mon Sep 17 00:00:00 2001 +From: blueloveTH <blueloveth@foxmail.com> +Date: Sat, 7 Jun 2025 02:19:55 +0800 +Subject: [PATCH] fix #371 + +Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> +Upstream: backport from https://github.com/pocketpy/pocketpy/commit/70e824a6b695e963621664589d1d00aeb182c018 +--- + include/pocketpy/pocketpy.h | 2 +- + src/interpreter/vm.c | 6 ++++-- + src/public/modules.c | 2 +- + 3 files changed, 6 insertions(+), 4 deletions(-) + +diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h +index a44faa41a922..a6cb4f658f73 100644 +--- a/include/pocketpy/pocketpy.h ++++ b/include/pocketpy/pocketpy.h +@@ -69,7 +69,7 @@ typedef struct py_Callbacks { + /// Used by `print` to output a string. + void (*print)(const char*); + /// Used by `input` to get a character. +- int (*getchar)(); ++ int (*getchr)(); + } py_Callbacks; + + /// Native function signature. +diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c +index 2bae82740ac7..2da28fa80730 100644 +--- a/src/interpreter/vm.c ++++ b/src/interpreter/vm.c +@@ -29,6 +29,8 @@ static char* pk_default_importfile(const char* path) { + + static void pk_default_print(const char* data) { printf("%s", data); } + ++static int pk_default_getchr() { return getchar(); } ++ + static void py_TypeInfo__ctor(py_TypeInfo* self, + py_Name name, + py_Type index, +@@ -67,7 +69,7 @@ void VM__ctor(VM* self) { + + self->callbacks.importfile = pk_default_importfile; + self->callbacks.print = pk_default_print; +- self->callbacks.getchar = getchar; ++ self->callbacks.getchr = pk_default_getchr; + + self->last_retval = *py_NIL(); + self->curr_exception = *py_NIL(); +@@ -810,7 +812,7 @@ int py_replinput(char* buf, int max_size) { + printf(">>> "); + + while(true) { +- int c = pk_current_vm->callbacks.getchar(); ++ int c = pk_current_vm->callbacks.getchr(); + if(c == EOF) return -1; + + if(c == '\n') { +diff --git a/src/public/modules.c b/src/public/modules.c +index 3efb362701e2..cdfd5549461a 100644 +--- a/src/public/modules.c ++++ b/src/public/modules.c +@@ -205,7 +205,7 @@ static bool builtins_input(int argc, py_Ref argv) { + c11_sbuf buf; + c11_sbuf__ctor(&buf); + while(true) { +- int c = pk_current_vm->callbacks.getchar(); ++ int c = pk_current_vm->callbacks.getchr(); + if(c == '\n' || c == '\r') break; + if(c == EOF) break; + c11_sbuf__write_char(&buf, c); +-- +2.43.0 + diff --git a/package/pocketpy/Config.in b/package/pocketpy/Config.in new file mode 100644 index 000000000000..b0bd0cafe008 --- /dev/null +++ b/package/pocketpy/Config.in @@ -0,0 +1,9 @@ +config BR2_PACKAGE_POCKETPY + bool "pocketpy" + depends on BR2_INSTALL_LIBSTDCPP + depends on !BR2_STATIC_LIBS # dlfcn.h + help + pocketpy is a portable Python 3.x interpreter, + written in C11. + + https://github.com/pocketpy/pocketpy diff --git a/package/pocketpy/pocketpy.hash b/package/pocketpy/pocketpy.hash new file mode 100644 index 000000000000..aabd5f077a2b --- /dev/null +++ b/package/pocketpy/pocketpy.hash @@ -0,0 +1,3 @@ +# locally computed +sha256 5e07994d66311a6b5ac032cc5243aaabe3ab318946971e7fa1cd0614934efc81 pocketpy-2.0.8.tar.gz +sha256 d3a2bf8ca609a75941e980e62c13cf5a21aeaa4a2502822934d282fe7de5d319 LICENSE diff --git a/package/pocketpy/pocketpy.mk b/package/pocketpy/pocketpy.mk new file mode 100644 index 000000000000..20a8e9ad1e20 --- /dev/null +++ b/package/pocketpy/pocketpy.mk @@ -0,0 +1,25 @@ +################################################################################ +# +# pocketpy +# +################################################################################ + +POCKETPY_VERSION = 2.0.8 +POCKETPY_SITE = $(call github,pocketpy,pocketpy,v$(POCKETPY_VERSION)) +POCKETPY_LICENSE = MIT +POCKETPY_LICENSE_FILES = LICENSE +POCKETPY_INSTALL_STAGING = YES + +POCKETPY_CONF_OPTS = -DPK_BUILD_SHARED_LIB=ON + +define POCKETPY_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/libpocketpy.so* $(TARGET_DIR)/usr/lib +endef + +define POCKETPY_INSTALL_STAGING_CMDS + $(INSTALL) -D -m 0755 $(@D)/libpocketpy.so* $(STAGING_DIR)/usr/lib + $(INSTALL) -m 755 -d $(STAGING_DIR)/usr/include/pocketpy + cp -r $(@D)/include/* $(STAGING_DIR)/usr/include/pocketpy +endef + +$(eval $(cmake-package))
It is a portable Python 3.x interpreter, written in C11. It has no dependencies other than the C standard library, which can be easily integrated into your C/C++ project Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> --- Changes v3 -> v4: - Replace 0001-Fix-getchar-helper.patch with 0001-fix-371.patch. Changes v2 -> v3: - Add package/pocketpy/0001-Fix-getchar-helper.patch. - Add depends on !BR2_STATIC_LIBS for dlfcn.h Changes v1 -> v2: - mv staging commands under POCKETPY_INSTALL_STAGING_CMDS hook. DEVELOPERS | 1 + package/Config.in | 1 + package/pocketpy/0001-fix-371.patch | 73 +++++++++++++++++++++++++++++ package/pocketpy/Config.in | 9 ++++ package/pocketpy/pocketpy.hash | 3 ++ package/pocketpy/pocketpy.mk | 25 ++++++++++ 6 files changed, 112 insertions(+) create mode 100644 package/pocketpy/0001-fix-371.patch create mode 100644 package/pocketpy/Config.in create mode 100644 package/pocketpy/pocketpy.hash create mode 100644 package/pocketpy/pocketpy.mk