Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support hiredis >= 1.0 #8

Merged
merged 2 commits into from
Sep 1, 2024
Merged

support hiredis >= 1.0 #8

merged 2 commits into from
Sep 1, 2024

Conversation

5c30
Copy link
Contributor

@5c30 5c30 commented Dec 20, 2021

i'm on a system with hiredis 1.0.2 installed. i ran into problems with Protocol::Redis::XS (segfaults and "bizarre copy of UNKNOWN" errors from perl), so i hacked some stuff together to get it working with the newer version.

i have pretty much no idea what i'm doing in XS, so please review carefully. this change "works for me," but it's likely i've done horrible things i'm unaware of. i added #if guards around the changes to hopefully keep it working on older versions of hiredis, but haven't been able to test that.

hope it's helpful.

hiredis changed the layout of redisReplyObjectFunctions in version 1.0.0. two
new functions were added for double and boolean replies. add double and boolean
to redisTypes, and create functions for handling the replies. add them to the
list set on the redisReader.
@Grinnz
Copy link
Collaborator

Grinnz commented Dec 21, 2021

I also cannot evaluate the XS very well but will test the changes with different versions of hiredis. Thank you for the contribution.

@eleksir
Copy link

eleksir commented Jan 1, 2022

me-too :)
I've got
hiredis-1.0.0-r0 x86_64 {hiredis} (BSD-3-Clause) [installed]
on alpine linux 3.12 x86_64. During installation with cpanm I face almost same issue - module build fails at testing stage with:

Configuring Protocol-Redis-XS-0.07                                                                                                                                           
Running Makefile.PL                                                                                                                                                          
Checking if your kit is complete...                                                                                                                                          
Looks good                                                                                                                                                                   
Generating a Unix-style Makefile                                                                                                                                             
Writing Makefile for Protocol::Redis::XS                                                                                                                                     
Writing MYMETA.yml and MYMETA.json                                                                                                                                           
-> OK                                                                                                                                                                        
Checking dependencies from MYMETA.json ...                                                                                                                                   
Checking if you have XSLoader 0 ... Yes (0.30)                                                                                                                               
Checking if you have parent 0 ... Yes (0.238)                                                                                                                                
Checking if you have Test::More 0.98 ... Yes (1.302188)                                                                                                                      
Checking if you have XS::Object::Magic 0 ... Yes (0.05)                                                                                                                      
Checking if you have ExtUtils::MakeMaker 7.44 ... Yes (7.44)                                                                                                                 
Checking if you have Protocol::Redis 1.0011 ... Yes (1.0011)                                                                                                                 
Checking if you have Protocol::Redis::Test 0 ... Yes (undef)                                                                                                                 
Building and testing Protocol-Redis-XS-0.07                                                                                                                                  
cp lib/Protocol/Redis/XS.pm blib/lib/Protocol/Redis/XS.pm                                                                                                                    
Running Mkbootstrap for XS ()                                                                                                                                                
chmod 644 "XS.bs"                                                                                                                                                            
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Protocol/Redis/XS/XS.bs 644                                                                 
"/usr/bin/perl" "/usr/share/perl5/core_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/core_perl/ExtUtils/typemap' -typemap '/var/lib/aleesa-misc.new/vendor_perl/lib/perl5
mv XS.xsc XS.c                                                                                                                                                               
cc -c  -I/var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/Alien/hiredis/Install -I/usr/include/hiredis -D_FILE_OFFSET_BITS=64 -I/var/lib/aleesa-misc.
XS.xs:114:3: warning: initialization of 'void * (*)(const redisReadTask *, size_t)' {aka 'void * (*)(const redisReadTask *, long unsigned int)'} from incompatible pointer ty
  114 |   createArrayObjectSV,                                                                                                                                               
      |   ^~~~~~~~~~~~~~~~~~~                                                                                                                                                
XS.xs:114:3: note: (near initialization for 'perlRedisFunctions.createArray')                                                                                                
XS.xs:116:3: warning: initialization of 'void * (*)(const redisReadTask *, double,  char *, size_t)' {aka 'void * (*)(const redisReadTask *, double,  char *, long unsigned i
  116 |   createNilObjectSV,                                                                                                                                                 
      |   ^~~~~~~~~~~~~~~~~                                                                                                                                                  
XS.xs:116:3: note: (near initialization for 'perlRedisFunctions.createDouble')                                                                                               
XS.xs:117:3: warning: initialization of 'void * (*)(const redisReadTask *)' from incompatible pointer type 'void (*)(void *)' [-Wincompatible-pointer-types]                 
  117 |   freeReplyObjectSV                                                                                                                                                  
      |   ^~~~~~~~~~~~~~~~~                                                                                                                                                  
XS.xs:117:3: note: (near initialization for 'perlRedisFunctions.createNil')                                                                                                  
rm -f blib/arch/auto/Protocol/Redis/XS/XS.so                                                                                                                                 
LD_RUN_PATH="/usr/lib" cc  -shared -Os -fomit-frame-pointer -L/usr/local/lib -fstack-protector-strong  XS.o  -o blib/arch/auto/Protocol/Redis/XS/XS.so  \                    
   -lhiredis   \
                                                                                                                                                                             
chmod 755 blib/arch/auto/Protocol/Redis/XS/XS.so                                                                                                                             
Manifying 1 pod document                                                                                                                                                     
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Protocol/Redis/XS/XS.bs 644                                                                 
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t          
    # Looks like you planned 43 tests but ran 13.                                                                                                                            
                                                                                                                                                                             
#   Failed test 'Protocol::Redis APIv1 ok'                                                                                                                                   
#   at /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/Protocol/Redis/Test.pm line 51.                                                                                        
Bizarre copy of UNKNOWN in scalar assignment at /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/Protocol/Redis/Test.pm line 119.                                              
# Looks like your test exited with 255 just after 2.                                                                                                                         
t/redis.t ..                                                                                                                                                                 
Dubious, test returned 255 (wstat 65280, 0xff00)                                                                                                                             
Failed 1/2 subtests                                                                                                                                                          
t/xs.t ..... ok                                                                                                                                                              
                                                                                                                                                                             
Test Summary Report                                                                                                                                                          
-------------------                                                                                                                                                          
t/redis.t (Wstat: 65280 Tests: 2 Failed: 1)                                                                                                                                  
  Failed test:  2                                                                                                                                                            
  Non-zero exit status: 255                                                                                                                                                  
Files=2, Tests=8,  0 wallclock secs ( 0.04 usr  0.01 sys +  0.19 cusr  0.03 csys =  0.27 CPU)                                                                                
Result: FAIL                                                                                                                                                                 
Failed 1/2 test programs. 1/8 subtests failed.                                                                                                                               
make: *** [Makefile:1080: test_dynamic] Error 255                                                                                                                            
-> FAIL Testing Protocol-Redis-XS-0.07 failed but installing it anyway.                                                                                                      
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/Protocol/Redis/XS/XS.bs 644                                                                 
Manifying 1 pod document                                                                                                                                                     
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree                                                                              
Installing /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/auto/Protocol/Redis/XS/XS.so                                                             
Installing /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/Protocol/Redis/XS.pm                                                                     
Installing /var/lib/aleesa-misc.new/vendor_perl/man/man3/Protocol::Redis::XS.3pm                                                                                             
Appending installation info to /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/perllocal.pod                                                        
-> OK                                                                                                                                                                        
Successfully installed Protocol-Redis-XS-0.07                                                                                                                                
Installing /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/.meta/Protocol-Redis-XS-0.07/install.json                                                
Installing /var/lib/aleesa-misc.new/vendor_perl/lib/perl5/x86_64-linux-thread-multi/.meta/Protocol-Redis-XS-0.07/MYMETA.json

In "production" i did not encounter any segfaults, but it looks like because I'm using redis as pub-sub only.

Anyway i think that tests must complete successfully, that is their purpose, right?

@Grinnz
Copy link
Collaborator

Grinnz commented Aug 29, 2024

Had to go digging a bit as this is not indicated in the hiredis changelog, but the changes to perlRedisFunctions are necessary because of the RESP3 support added in redis/hiredis#697 . They look okay to me but I'd be more comfortable if someone with knowledge of Perl NVs in particular could review createDoubleObjectSV, the specification of the double type that will be received can be found at https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md#Simple-Types

Suggested by @mauke as sv_setnv will clear the string value that was just set. This will return a PVNV dualvar which stringifies to the format of the double originally parsed from the Redis reply string.
@Grinnz Grinnz merged commit 63dfb93 into dgl:master Sep 1, 2024
@Grinnz
Copy link
Collaborator

Grinnz commented Sep 1, 2024

Thank you! This should allow building against hiredis 1.0+, full support for RESP3 should come later and under a different API specification. #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants