summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstderr64 <stderr64@null.net>2025-10-28 18:11:09 +0200
committerstderr64 <stderr64@null.net>2025-10-28 18:11:09 +0200
commit557bf9c01fd78848167c1db8327aed259c5b3690 (patch)
treee58d1d10861e2586353f3a14193609134314d34f
parent56346d0b8041caa99ce1ac57becff11e78fd561e (diff)
downloadexperiments-557bf9c01fd78848167c1db8327aed259c5b3690.tar.gz
experiments-557bf9c01fd78848167c1db8327aed259c5b3690.tar.zst
Added some stuff
-rwxr-xr-xall_unicode_chars/unicharsbin0 -> 16576 bytes
-rw-r--r--cpp_unicode_test/stdstring_unicode.cpp33
-rw-r--r--cpp_unicode_test/unicodechars.txt1
-rwxr-xr-xcpp_unicode_test/writemisc.pl25
-rwxr-xr-xkvrocks_filler/filler.pl75
-rw-r--r--php_kvrocks/kvrocks.php31
-rw-r--r--php_kvrocks/kvrocks2.php10
-rw-r--r--python_cdll_multithread/Makefile8
-rwxr-xr-xpython_cdll_multithread/cdll.py49
-rw-r--r--python_cdll_multithread/libpcdlltest.c54
10 files changed, 286 insertions, 0 deletions
diff --git a/all_unicode_chars/unichars b/all_unicode_chars/unichars
new file mode 100755
index 0000000..4fc91c2
--- /dev/null
+++ b/all_unicode_chars/unichars
Binary files differ
diff --git a/cpp_unicode_test/stdstring_unicode.cpp b/cpp_unicode_test/stdstring_unicode.cpp
new file mode 100644
index 0000000..d60679c
--- /dev/null
+++ b/cpp_unicode_test/stdstring_unicode.cpp
@@ -0,0 +1,33 @@
+#include <cstdlib>
+#include <cstdio>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <unistd.h>
+
+int main( int argc, char *args[] ){
+ unsigned char *fcontents = NULL;
+ std::fstream *charfile = new std::fstream( reinterpret_cast<const char*>("./unicodechars.txt"), std::ios::in );
+ if ( charfile->fail() ){
+ std::cerr << "Failed to open file\n";
+ exit( EXIT_FAILURE );
+ }
+ charfile->seekg( 0, std::ios::end );
+ ssize_t fsize = static_cast<ssize_t>(charfile->tellg());
+ charfile->seekg( 0, std::ios::beg );
+ fcontents = static_cast<unsigned char*>(calloc(fsize, sizeof(unsigned char)));
+ if ( fcontents == NULL ){
+ std::cerr << "calloc failed\n";
+ exit( EXIT_FAILURE );
+ }
+ charfile->read( reinterpret_cast<char*>(fcontents), fsize );
+ charfile->close();
+ delete charfile;
+ fsize = 0;
+ std::string *uchars = new std::string( "" );
+ uchars->assign( reinterpret_cast<char*>(fcontents) );
+ free( fcontents );
+ std::cout << uchars->c_str() << "\n";
+ delete uchars;
+ exit( EXIT_SUCCESS );
+}
diff --git a/cpp_unicode_test/unicodechars.txt b/cpp_unicode_test/unicodechars.txt
new file mode 100644
index 0000000..1012c1d
--- /dev/null
+++ b/cpp_unicode_test/unicodechars.txt
@@ -0,0 +1 @@
+☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟⛠⛡⛢⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾
diff --git a/cpp_unicode_test/writemisc.pl b/cpp_unicode_test/writemisc.pl
new file mode 100755
index 0000000..43ba4ec
--- /dev/null
+++ b/cpp_unicode_test/writemisc.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use IO::File;
+
+my $charcode = 0x2600;
+
+my $out_string = "";
+
+for ( ; $charcode < 0x26FF; $charcode++ ){
+ $out_string .= chr( $charcode );
+}
+
+$out_string .= "\n";
+
+undef $charcode;
+
+open( my $ofile, ">:encoding(UTF-8)", "unicodechars.txt" ) or die "Failed to open file for writing";;
+
+print( $ofile $out_string );
+
+undef $ofile;
+undef $out_string;
+
+print( "Finished writing to file\n" );
+
+exit( 0 );
diff --git a/kvrocks_filler/filler.pl b/kvrocks_filler/filler.pl
new file mode 100755
index 0000000..2efdc23
--- /dev/null
+++ b/kvrocks_filler/filler.pl
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+use IO::Socket;
+
+print( "Connecting..\n" );
+
+my $sck = IO::Socket->new(
+ "PeerHost" => "127.0.0.1",
+ "PeerPort" => 6000,
+ "Blocking" => 1,
+ "Proto" => "tcp",
+ "Domain" => IO::Socket::AF_INET,
+ "Type" => IO::Socket::SOCK_STREAM
+) or die "Failed to create socket";
+
+print( "Connected\n" );
+
+my @chars = split( / /, "q w e r t y i o p a s d f g h j k l z x c v b n m" );
+my $jlen = scalar( @chars );
+
+srand();
+
+my $junk = "";
+
+sub gen_junk{
+ $junk = "";
+ for ( my $jc = 0; $jc < 100; $jc++ ){
+ $junk .= $chars[rand($jlen)];
+ }
+ return $junk;
+}
+
+my $kname = "";
+
+sub gen_key_name{
+ $kname = "";
+ for ( my $kchars = 0; $kchars < 20; $kchars++ ){
+ $kname .= $chars[rand($jlen)];
+ }
+ return $kname;
+}
+
+sub kv_add{
+ print( "Command:\n*3\r\n\$3\r\nset\r\n\$".length($_[0])."\r\n".$_[0]."\r\n\$".length($_[1])."\r\n".$_[1]."\r\n" );
+ $sck->send( "*3\r\n\$3\r\nset\r\n\$".length($_[0])."\r\n".$_[0]."\r\n\$".length($_[1])."\r\n".$_[1]."\r\n" ) or die "Failed to add key";
+}
+
+sub start_multi{
+ $sck->send( "MULTI\r\n" ) or die "Failed to start multi";
+ return;
+}
+
+sub end_multi{
+ $sck->send( "EXEC\r\n" );
+ return;
+}
+
+print( "Adding keys\n" );
+
+start_multi();
+
+for ( my $gc = 0; $gc < 2000000; $gc++ ){
+ print( "Adding key number ".$gc."\n" );
+ kv_add( gen_key_name(), gen_junk() );
+}
+
+end_multi();
+
+print( "Finished adding keys\n" );
+
+$sck->shutdown( SHUT_RDWR );
+
+undef $chars;
+undef $jlen;
+undef $sck;
+exit( 0 );
diff --git a/php_kvrocks/kvrocks.php b/php_kvrocks/kvrocks.php
new file mode 100644
index 0000000..d40a773
--- /dev/null
+++ b/php_kvrocks/kvrocks.php
@@ -0,0 +1,31 @@
+<?php
+if ( !extension_loaded('sockets') )
+ die( 'the damn sockets extension is not loaded' );
+$sck = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
+if ( $sck === false )
+ die( 'Failed to create socket' );
+if ( !socket_connect($sck, '127.0.0.1', 6000) ){
+ socket_close( $sck );
+ die( 'Failed to connect to kvrocks' );
+}
+if ( socket_send($sck, "GET stderr64_data\r\n", strlen("GET stderr64_data\r\n"), 0) == false ){
+ socket_close( $sck );
+ die(' Failed to send retrieval command' );
+}
+$recv_data = 'tmp';
+$avb = socket_recv( $sck, $recv_data, 2048, MSG_PEEK );
+echo strval($avb).' bytes:<br>';
+if ( socket_recv($sck, $recv_data, $avb, MSG_WAITALL) === false ){
+ socket_close( $sck );
+ die( 'Failed to recv data' );
+}
+socket_shutdown( $sck );
+socket_close( $sck );
+$ddata = json_decode( explode("\r\n", $recv_data)[1], true );
+var_dump( $ddata );
+echo '<br>Cookies: '.strval($ddata['cookies']).'<br>group: '.$ddata['group'].'<br>';
+unset( $ddata );
+unset( $recv_dec );
+unset( $recv_data );
+exit( 0 );
+?>
diff --git a/php_kvrocks/kvrocks2.php b/php_kvrocks/kvrocks2.php
new file mode 100644
index 0000000..0d821cd
--- /dev/null
+++ b/php_kvrocks/kvrocks2.php
@@ -0,0 +1,10 @@
+<?php
+$sck = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
+socket_connect( $sck, '127.0.0.1', 6000 );
+socket_write( $sck, 'GET stderr64_data\r\n', strlen('GET stderr64_data\r\n') );
+$rd = socket_read( $sck, 255 );
+socket_shutdown( $sck );
+socket_close( $sck );
+var_dump( json_decode($rd, true) );
+exit( 0 );
+?>
diff --git a/python_cdll_multithread/Makefile b/python_cdll_multithread/Makefile
new file mode 100644
index 0000000..45040bf
--- /dev/null
+++ b/python_cdll_multithread/Makefile
@@ -0,0 +1,8 @@
+CC=gcc
+CFLAGS=-O2 -march=x86-64-v3 -fPIC -shared
+
+rel:
+ $(CC) ${CFLAGS} ./libpcdlltest.c -o libpcdlltest.so -lpthread
+
+clean:
+ rm ./libpcdlltest.so
diff --git a/python_cdll_multithread/cdll.py b/python_cdll_multithread/cdll.py
new file mode 100755
index 0000000..eb76d35
--- /dev/null
+++ b/python_cdll_multithread/cdll.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python3 -u
+import sys;
+import time;
+from ctypes import *;
+
+testlib = CDLL( "./libpcdlltest.so" );
+
+print( testlib );
+
+testlib.testfunc.restype = c_void_p;
+testlib.testfunc2.restype = c_void_p;
+testlib.testfunc3.restype = c_char_p;
+testlib.cleanup_buffer.restype = c_void_p;
+
+print( "Executing first test function (simple message from C code)" );
+
+testlib.testfunc();
+
+print( "Executing test function 2 (pass python value to it)" );
+
+pvar = create_string_buffer( bytes("test message", "utf8") );
+testlib.testfunc2( pvar );
+del pvar;
+
+print( "Executing test function 3 (return value from C code)" );
+
+test_value = testlib.testfunc3().decode("utf8");
+print( f"Returned value: {test_value}" );
+del test_value;
+
+print( "Executing buffer cleanup functiion" );
+
+testlib.cleanup_buffer();
+
+print( "Starting C thread" );
+
+testlib.threadstarter();
+
+print( "Printing garbage from python code" );
+
+for pcount in range(0, 40):
+ print( f"Count is now in python {pcount}" );
+ time.sleep( 1 );
+
+print( "All tests done" );
+
+del testlib;
+
+sys.exit( 0 );
diff --git a/python_cdll_multithread/libpcdlltest.c b/python_cdll_multithread/libpcdlltest.c
new file mode 100644
index 0000000..6bc10ea
--- /dev/null
+++ b/python_cdll_multithread/libpcdlltest.c
@@ -0,0 +1,54 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <pthread.h>
+
+char *t3_buffer = NULL;
+
+__attribute__((visibility("default"))) extern void *testfunc(){
+ fputs( "Yes, it worked, testfunc executed\n", stdout );
+ return NULL;
+}
+
+__attribute__((visibility("default"))) extern void *testfunc2( char *testvalue ){
+ fprintf( stdout, "Value passed from python: %s\n", (const char*)testvalue );
+ return NULL;
+}
+
+__attribute__((visibility("default"))) extern char *testfunc3(){
+ t3_buffer = (char*)calloc( strlen("test") + 1, sizeof(char) );
+ assert( t3_buffer != NULL );
+ snprintf( t3_buffer, (strlen("test") * sizeof(char)) + 1, "test" );
+ return t3_buffer;
+}
+
+__attribute__((visibility("default"))) extern void *cleanup_buffer(){
+ if ( t3_buffer == NULL )
+ return NULL;
+ free( t3_buffer );
+ t3_buffer = NULL;
+ fputs( "Buffer freed\n", stdout );
+ return NULL;
+}
+
+__attribute__((visibility("hidden"))) extern void *thread_func( void *uptr ){
+ uint32_t loop_counter = 0;
+ for ( ; loop_counter < 30; loop_counter++ ){
+ fprintf( stdout, "Loop counter is now %i\n", loop_counter );
+ sleep( 1 );
+ }
+ return NULL;
+}
+
+__attribute__((visibility("default"))) extern void *threadstarter(){
+ pthread_t tid = 0;
+ if ( pthread_create(&tid, NULL, &thread_func, NULL) == -1 )
+ return NULL;
+ return NULL;
+}