<ruffni>aaaand what's a Guile way to create a hash for binary data (i.e. file data)? md5sum would do <RhodiumToad>that's a harder one. not sure there's any built-in crypto functions. you could access an existing md5 library via the FFI *RhodiumToad not guix user <ruffni>`guix search md5` yields a package named "guile-hashing".. i think i'll go with that :) <RhodiumToad>yeah but that requires ugly contortions to get the filename into the command <lampilelo>then use open-pipe*, with ffi or wrapper libraries you'll probably need to pipe files directly to the digest function *RhodiumToad successfully computes md5("foo") using the ffi <lampilelo>i'd probably extend my nettle wrapper if i needed to hash some files <ruffni>which library does your md5() come from? <RhodiumToad>though freebsd has a libmd, but there's some symbol renaming going on there to avoid clashing with libcrypto <ruffni>hmm.. i'll give the ffi a try soon, this should be faster than the guile-only code in guile-hashing, right? <RhodiumToad>blugh. you can create applicable structs in goops, but you can't create them with metaclasses, unless you pry off some cover plates using (@@) <RhodiumToad>in particular it's not sufficient for your metaclass to inherit from <applicable-struct-class> <lloda>i kinda miss (define-syntax (id s) ...) <lloda>(define-syntax id (lambda (s) ...)) <lloda>it wasn't removed, i don't think it has ever worked *lloda too scared of psyntax.scm <lampilelo>for now i'm just a beginner when it comes to hygienic macros <vijaymarupudi>daviid: Some data from using glib's main loop in g-golf for a neovim remote plugin, it works wonderfully! However, it seems like 21% of the program time in tight loops is spent in char-upper-case? and char-lower-case?. <vijaymarupudi>daviid: Not a blocker for me btw, just sharing in case you were curious :) ***sneek_ is now known as sneek
<ruffni>i'm having troubles calling sha-1 through FFI with an open port. can i inject the open-file port directly as a pointer to sha1? https://dpaste.org/xf5x <dsmith-work>Hmm. a git clean and autogen .... make check worked fine. (With an (exit 77) in standalone/test-out-of-memory because bullseye libgc) <dsmith-work>ruffni: You will need to read the contents of your file and pass that in. Right now, looks like you are instead passing the scheme port datastructure. <RhodiumToad>ruffni: I have some mostly working examples that I can put up in a bit <ruffni>yeah, i was wondering exactly *how* you got your md5 call working :) <lampilelo>ruffni: a port is not a bytevector you can pass by pointer to an external function, what you need to do is read from the port to a bytevector and then pass its pointer to the function, although SHA1() won't do it for a file because you'd need to load the whole of it to memory <lampilelo>you'd need to use SHA1_Update and pass it parts of the file in a loop <ruffni>RhodiumToad: so you're writing a full-fledged, FFI based frontend for libcrypto? <ruffni>lampilelo: thanks for the clarification! <lampilelo>also the third argument for SHA1() is a pointer to your output buffer, so what you want to do is create a bytevector with length of SHA_DIGEST_LENGTH and pass its pointer to the function <lampilelo>you should read the section about FFI from the guile manual <ruffni>i am :) stupidly though i only read "Void Pointers" instead of the whole title of section 6.19.6 and skipped it <RhodiumToad>(let ((h (make <hash-state> algo: 'algo))) (call-with-input-file "filename" (cut update h <>)) (as-bytes h)) <RhodiumToad>and even things like ((make <hash-algo> algo: 'md5) (string->utf8 "foo")) <RhodiumToad>this is not really cleaned up, it's not an actual module and the error handling is ... sketchy <lampilelo>oh so that's why you were talking about @@ and goops before <RhodiumToad>I wanted the <hash-algo> instances to be both kind-of-singletons (can only make one of each algorithm, and trying to make more just returns the existing one), <RhodiumToad>and also have them be applicable-structs, where applying the algorithm to a bytevector returns the hash <RhodiumToad>all the applicable-struct stuff can be removed without much trouble <ruffni>am i missing something or is #:kwarg equivalent to kwarg: when srfi-88 is loaded? <lampilelo>(begin (use-modules (srfi srfi-88)) (eq? #:kwarg kwarg:)) => #t <RhodiumToad>it's because I like to distinguish between keyword-used-as-keyword (init-keyword:) from keyword-used-as-value (#:algo) <RhodiumToad>I find #: ugly for keywords used as keywords, which is why I use srfi-88 <daviid>RhodiumToad: dpaste ... isn't tor friendly ... <RhodiumToad>that strips out the applicable-struct stuff and some of the other undocumented goops tricks (like calling (next-method) with explicit args) <ruffni>daviid: any suggestions for a friendlier alternative? <daviid> Error 1020 ... Access denied ... This website is using a security service to protect itself from online attacks. <daviid>ruffni: at least 3, debian, gnome and sourcehut <daviid>RhodiumToad: i was interested to follow your goops app-struct endeavor ... <RhodiumToad>just inheriting <applicable-struct> works if you don't specify a metaclass, but if you do specify one, it doesn't work without the line commented "ugh!" <RhodiumToad>(it looks like the vtable-flag-applicable-vtable class flag is for whatever reason not inherited, seems like it should be) <ruffni>RhodiumToad: are the <hash-algo> instances now singletons? is that why you defined your own metaclass -- realized through (make-hash-table)? <RhodiumToad>(make <hash-algo> algo: whatever) returns the existing object if one exists rather than making a new one <ruffni>i think i get it! what a wonderful opportunity to learn about GOOPS metaclasses. thank you! <RhodiumToad><hash-algo> is a class, and so it would normally be an instance of <class>, so the (make) would normally resolve to (make (_ <class>) ...) <RhodiumToad>but by making <hash-algo> an instance of something derived from <class>, we can specialize (make) for (make (_ <hash-algo-class>) ...) and make it do something different <RhodiumToad>make and make-instance are the same generic under the hood, so we only need to define one of them <ruffni>and is this (next-method) trick documented somewhere? i only find references to no-next-method <RhodiumToad>the documentation just says (next-method) calls the next method with the same args as the current one <RhodiumToad>but it so happens that (next-method ...) works to call it with a completely new set of args <RhodiumToad>that last part is not documented, I believe I learned it here <RhodiumToad>(probably the first time I played with applicable-structs) <ruffni>(next-method) in this case call's the superclasses (initialize initargs) ? <RhodiumToad>in any method, (next-method) calls the next-most-closely matching method from the list of matching methods <daviid>fwiw, there're called (the list of) applicable method(s)