]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
tcl bindings: use Tcl_GetByteArrayFromObj to get the raw binary data
authorMichael Schroeder <mls@suse.de>
Tue, 25 Aug 2015 14:43:38 +0000 (16:43 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 25 Aug 2015 14:43:38 +0000 (16:43 +0200)
We do not want utf8 encoding of binary data...

bindings/solv.i

index cc721e2054fe26c99d0529b6a73ce198df65e911..f490a2d8bd321a80de9b310980e9a8bf99305996 100644 (file)
@@ -22,7 +22,22 @@ typedef struct {
 %}
 
 %typemap(in,noblock=1,fragment="SWIG_AsCharPtrAndSize") (const unsigned char *str, size_t len) (int res, char *buf = 0, size_t size = 0, int alloc = 0) {
+#if defined(SWIGTCL)
+  {
+    int bal;
+    unsigned char *ba;
+    res = SWIG_TypeError;
+    ba = Tcl_GetByteArrayFromObj($input, &bal);
+    if (ba) {
+      buf = (char *)ba;
+      size = bal;
+      res = SWIG_OK;
+      alloc = SWIG_OLDOBJ;
+    }
+  }
+#else
   res = SWIG_AsCharPtrAndSize($input, &buf, &size, &alloc);
+#endif
   if (!SWIG_IsOK(res)) {
 #if defined(SWIGPYTHON)
     const void *pybuf = 0;
@@ -946,6 +961,9 @@ typedef struct {
   int dup() {
     return $self->fp ? dup(fileno($self->fp)) : -1;
   }
+  bool write(const unsigned char *str, size_t len) {
+    return fwrite(str, len, 1, $self->fp) == 1;
+  }
   bool flush() {
     if (!$self->fp)
       return 1;