Rev 33: Copy _my_memrchr from the _dirstate_helpers so that this will compile and run on win32 in http://bzr.arbash-meinel.com/plugins/index2

John Arbash Meinel john at arbash-meinel.com
Thu Jul 3 18:12:49 BST 2008


At http://bzr.arbash-meinel.com/plugins/index2

------------------------------------------------------------
revno: 33
revision-id: john at arbash-meinel.com-20080703171239-p0yr682smdn1jb3v
parent: john at arbash-meinel.com-20080703171207-a315ypnhybt1r6vk
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: index2
timestamp: Thu 2008-07-03 12:12:39 -0500
message:
  Copy _my_memrchr from the _dirstate_helpers so that this will compile and run on win32
-------------- next part --------------
=== modified file '_parse_btree_c.pyx'
--- a/_parse_btree_c.pyx	2008-07-03 06:11:19 +0000
+++ b/_parse_btree_c.pyx	2008-07-03 17:12:39 +0000
@@ -44,10 +44,25 @@
 
 cdef extern from "string.h":
     void *memchr(void *s, int c, size_t n)
-    void *memrchr(void *s, int c, size_t n)
+    # void *memrchr(void *s, int c, size_t n)
     int strncmp(char *s1, char *s2, size_t n)
 
 
+cdef void* _my_memrchr(void *s, int c, size_t n):
+    # memrchr seems to be a GNU extension, so we have to implement it ourselves
+    # It is not present in any win32 standard library
+    cdef char *pos
+    cdef char *start
+
+    start = <char*>s
+    pos = start + n - 1
+    while pos >= start:
+        if pos[0] == c:
+            return <void*>pos
+        pos = pos - 1
+    return NULL
+
+
 cdef class BTreeLeafParser:
 
     cdef object bytes
@@ -138,7 +153,7 @@
 
         key = self.extract_key(last)
         # find the value area
-        temp_ptr = <char*>memrchr(self.start, c'\0', last - self.start)
+        temp_ptr = <char*>_my_memrchr(self.start, c'\0', last - self.start)
         if temp_ptr == NULL:
             # Invalid line
             return -1



More information about the bazaar-commits mailing list