Skip to content

Commit 168175b

Browse files
committed
Merge pull request #22 from pombredanne/develop
Refactored patch extraction tests and fix #21
2 parents 1203d5a + 23e6be8 commit 168175b

File tree

199 files changed

+81808
-2408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+81808
-2408
lines changed

src/extractcode/patch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def extract(location, target_dir):
5959
This treats a patch file as if it were an archive containing one file for
6060
each patch applied to a file to be patched.
6161
"""
62-
pi = patch_info(location)
63-
for source, target, text in pi:
62+
for source, target, text in patch_info(location):
6463
# prefer the target path for writing the patch text to a subfile
6564
# unless target is /dev/null (a deletion)
6665
if '/dev/null' in target:
@@ -90,7 +89,7 @@ def extract(location, target_dir):
9089
# recursive extraction
9190
subfile_path = base_subfile_path + extractcode.EXTRACT_SUFFIX
9291
with open(subfile_path, 'wb') as subfile:
93-
subfile.write(text)
92+
subfile.write(u'\n'.join(text))
9493

9594

9695
def is_patch(location, include_extracted=False):
@@ -136,8 +135,8 @@ def patch_info(location):
136135
"""
137136
Return a list of tuples of (src_path, target_path, patch_text) for each
138137
patch segment of a patch file at location.
139-
140-
Return an empty list if the file is not a patch file or cannot be parsed.
138+
139+
Raise an exception if the file is not a patch file or cannot be parsed.
141140
"""
142141
patchset = pythonpatch.fromfile(location)
143142
if not patchset:
@@ -147,5 +146,6 @@ def patch_info(location):
147146
for ptch in patchset.items:
148147
src = fileutils.as_posixpath(ptch.source.strip())
149148
tgt = fileutils.as_posixpath(ptch.target.strip())
150-
text = '\n'.join((l.strip() for l in patch_text(ptch) if l))
149+
text = [unicode(l.strip(), encoding='utf-8', errors='replace')
150+
for l in patch_text(ptch) if l]
151151
yield src, tgt, text
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
[('ElectricFence-2.0.5/eftest.c.ewt',
2-
'ElectricFence-2.0.5/eftest.c',
3-
'--- ElectricFence-2.0.5/eftest.c.ewt\n+++ ElectricFence-2.0.5/eftest.c\n@@ -24,7 +24,7 @@\nextern int\tEF_PROTECT_BELOW;\nextern int\tEF_ALIGNMENT;\n\n-static jmp_buf\tenv;\n+static sigjmp_buf\tenv;\n\n/*\n* There is still too little standardization of the arguments and return\n@@ -40,13 +40,13 @@\n)\n{\nsignal(PAGE_PROTECTION_VIOLATED_SIGNAL, SIG_DFL);\n-\tlongjmp(env, 1);\n+\tsiglongjmp(env, 1);\n}\n\nstatic int\ngotSegmentationFault(int (*test)(void))\n{\n-\tif ( setjmp(env) == 0 ) {\n+\tif ( sigsetjmp(env, 1) == 0 ) {\nint\t\t\tstatus;\n\nsignal(PAGE_PROTECTION_VIOLATED_SIGNAL')]
1+
[
2+
[
3+
"ElectricFence-2.0.5/eftest.c.ewt",
4+
"ElectricFence-2.0.5/eftest.c",
5+
[
6+
"--- ElectricFence-2.0.5/eftest.c.ewt",
7+
"+++ ElectricFence-2.0.5/eftest.c",
8+
"@@ -24,7 +24,7 @@",
9+
"extern int\tEF_PROTECT_BELOW;",
10+
"extern int\tEF_ALIGNMENT;",
11+
"",
12+
"-static jmp_buf\tenv;",
13+
"+static sigjmp_buf\tenv;",
14+
"",
15+
"/*",
16+
"* There is still too little standardization of the arguments and return",
17+
"@@ -40,13 +40,13 @@",
18+
")",
19+
"{",
20+
"signal(PAGE_PROTECTION_VIOLATED_SIGNAL, SIG_DFL);",
21+
"-\tlongjmp(env, 1);",
22+
"+\tsiglongjmp(env, 1);",
23+
"}",
24+
"",
25+
"static int",
26+
"gotSegmentationFault(int (*test)(void))",
27+
"{",
28+
"-\tif ( setjmp(env) == 0 ) {",
29+
"+\tif ( sigsetjmp(env, 1) == 0 ) {",
30+
"int\t\t\tstatus;",
31+
"",
32+
"signal(PAGE_PROTECTION_VIOLATED_SIGNAL"
33+
]
34+
]
35+
]
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
[('ElectricFence-2.1/print.c.jj',
2-
'ElectricFence-2.1/print.c',
3-
"--- ElectricFence-2.1/print.c.jj\n+++ ElectricFence-2.1/print.c\n@@ -99,7 +99,7 @@ vprint(const char * pattern, va_list arg\nbreak;\ncase 'c':\n{\n-\t\t\t\t\tchar\tc = va_arg(args, char);\n+\t\t\t\t\tchar\tc = va_arg(args, int);\n\n(void) write(2, &c, 1);\n}")]
1+
[
2+
[
3+
"ElectricFence-2.1/print.c.jj",
4+
"ElectricFence-2.1/print.c",
5+
[
6+
"--- ElectricFence-2.1/print.c.jj",
7+
"+++ ElectricFence-2.1/print.c",
8+
"@@ -99,7 +99,7 @@ vprint(const char * pattern, va_list arg",
9+
"break;",
10+
"case 'c':",
11+
"{",
12+
"-\t\t\t\t\tchar\tc = va_arg(args, char);",
13+
"+\t\t\t\t\tchar\tc = va_arg(args, int);",
14+
"",
15+
"(void) write(2, &c, 1);",
16+
"}"
17+
]
18+
]
19+
]
Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,68 @@
1-
[('ElectricFence-2.2.2/page.c.jj',
2-
'ElectricFence-2.2.2/page.c',
3-
'--- ElectricFence-2.2.2/page.c.jj\n+++ ElectricFence-2.2.2/page.c\n@@ -160,8 +160,9 @@ Page_DenyAccess(void * address, size_t s\nvoid\nPage_Delete(void * address, size_t size)\n{\n-\tif ( munmap((caddr_t)address, size) < 0 )\n-\t\tPage_DenyAccess(address, size);\n+\tPage_DenyAccess(address, size);\n+\t/* Tell the kernel we will never need it again. */\n+\tmadvise(address, size, MADV_DONTNEED);\n}\n\n#if defined(_SC_PAGESIZE)'),
4-
('ElectricFence-2.2.2/efence.c.jj',
5-
'ElectricFence-2.2.2/efence.c',
6-
'--- ElectricFence-2.2.2/efence.c.jj\n+++ ElectricFence-2.2.2/efence.c\n@@ -626,10 +626,7 @@ memalign(size_t alignment, size_t userSi\naddress += internalSize - bytesPerPage;\n\n/* Set up the "dead" page. */\n-\t\tif ( EF_PROTECT_FREE )\n-\t\t\tPage_Delete(address, bytesPerPage);\n-\t\telse\n-\t\t\tPage_DenyAccess(address, bytesPerPage);\n+\t\tPage_Delete(address, bytesPerPage);\n\n/* Figure out what address to give the user. */\naddress -= userSize;\n@@ -643,11 +640,8 @@ memalign(size_t alignment, size_t userSi\naddress = (char *)fullSlot->internalAddress;\n\n/* Set up the "dead" page. */\n-\t\tif ( EF_PROTECT_FREE )\n-\t\t\tPage_Delete(address, bytesPerPage);\n-\t\telse\n-\t\t\tPage_DenyAccess(address, bytesPerPage);\n-\n+\t\tPage_Delete(address, bytesPerPage);\n+\naddress += bytesPerPage;\n\n/* Set up the "live" page. */\n@@ -777,10 +771,7 @@ free(void * address)\n* in the hope that the swap space attached to those pages will be\n* released as well.\n*/\n-\tif ( EF_PROTECT_FREE )\n-\t Page_Delete(slot->internalAddress, slot->internalSize);\n-\telse\n-\t Page_DenyAccess(slot->internalAddress, slot->internalSize);\n+\tPage_Delete(slot->internalAddress, slot->internalSize);\n\npreviousSlot = slotForInternalAddressPreviousTo(slot->internalAddress);\nnextSlot = slotForInternalAddress(')]
1+
[
2+
[
3+
"ElectricFence-2.2.2/page.c.jj",
4+
"ElectricFence-2.2.2/page.c",
5+
[
6+
"--- ElectricFence-2.2.2/page.c.jj",
7+
"+++ ElectricFence-2.2.2/page.c",
8+
"@@ -160,8 +160,9 @@ Page_DenyAccess(void * address, size_t s",
9+
"void",
10+
"Page_Delete(void * address, size_t size)",
11+
"{",
12+
"-\tif ( munmap((caddr_t)address, size) < 0 )",
13+
"-\t\tPage_DenyAccess(address, size);",
14+
"+\tPage_DenyAccess(address, size);",
15+
"+\t/* Tell the kernel we will never need it again. */",
16+
"+\tmadvise(address, size, MADV_DONTNEED);",
17+
"}",
18+
"",
19+
"#if defined(_SC_PAGESIZE)"
20+
]
21+
],
22+
[
23+
"ElectricFence-2.2.2/efence.c.jj",
24+
"ElectricFence-2.2.2/efence.c",
25+
[
26+
"--- ElectricFence-2.2.2/efence.c.jj",
27+
"+++ ElectricFence-2.2.2/efence.c",
28+
"@@ -626,10 +626,7 @@ memalign(size_t alignment, size_t userSi",
29+
"address += internalSize - bytesPerPage;",
30+
"",
31+
"/* Set up the \"dead\" page. */",
32+
"-\t\tif ( EF_PROTECT_FREE )",
33+
"-\t\t\tPage_Delete(address, bytesPerPage);",
34+
"-\t\telse",
35+
"-\t\t\tPage_DenyAccess(address, bytesPerPage);",
36+
"+\t\tPage_Delete(address, bytesPerPage);",
37+
"",
38+
"/* Figure out what address to give the user. */",
39+
"address -= userSize;",
40+
"@@ -643,11 +640,8 @@ memalign(size_t alignment, size_t userSi",
41+
"address = (char *)fullSlot->internalAddress;",
42+
"",
43+
"/* Set up the \"dead\" page. */",
44+
"-\t\tif ( EF_PROTECT_FREE )",
45+
"-\t\t\tPage_Delete(address, bytesPerPage);",
46+
"-\t\telse",
47+
"-\t\t\tPage_DenyAccess(address, bytesPerPage);",
48+
"-",
49+
"+\t\tPage_Delete(address, bytesPerPage);",
50+
"+",
51+
"address += bytesPerPage;",
52+
"",
53+
"/* Set up the \"live\" page. */",
54+
"@@ -777,10 +771,7 @@ free(void * address)",
55+
"* in the hope that the swap space attached to those pages will be",
56+
"* released as well.",
57+
"*/",
58+
"-\tif ( EF_PROTECT_FREE )",
59+
"-\t Page_Delete(slot->internalAddress, slot->internalSize);",
60+
"-\telse",
61+
"-\t Page_DenyAccess(slot->internalAddress, slot->internalSize);",
62+
"+\tPage_Delete(slot->internalAddress, slot->internalSize);",
63+
"",
64+
"previousSlot = slotForInternalAddressPreviousTo(slot->internalAddress);",
65+
"nextSlot = slotForInternalAddress("
66+
]
67+
]
68+
]
Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,84 @@
1-
[('ElectricFence-2.2.2/efence.c.jj',
2-
'ElectricFence-2.2.2/efence.c',
3-
'--- ElectricFence-2.2.2/efence.c.jj\n+++ ElectricFence-2.2.2/efence.c\n@@ -174,6 +174,15 @@ static int\t\tinternalUse = 0;\nstatic int\t\tnoAllocationListProtection = 0;\n\n#ifdef USE_SEMAPHORE\n+\n+#include <stdbool.h>\n+\n+#pragma weak sem_init\n+#pragma weak sem_post\n+#pragma weak sem_wait\n+\n+static int\t\tpthread_initialization = 0;\n+\n/*\n* EF_sem is a semaphore used to allow one thread at a time into\n* these routines.\n@@ -274,7 +283,7 @@ initialize(void)\nEF_Print(version);\n\n#ifdef USE_SEMAPHORE\n-\tif (sem_init(&EF_sem, 0, 1) >= 0) {\n+\tif (sem_init != NULL && !pthread_initialization && sem_init(&EF_sem, 0, 1) >= 0) {\nsemEnabled = 1;\n}\n#endif\n@@ -397,6 +406,21 @@ initialize(void)\nrelease();\n}\n\n+#ifdef USE_SEMAPHORE\n+void\n+__libc_malloc_pthread_startup (bool first_time)\n+{\n+\tif (first_time) {\n+\t\tpthread_initialization = 1;\n+\t\tinitialize ();\n+\t} else {\n+\t\tpthread_initialization = 0;\n+\t\tif (!semEnabled && sem_init != NULL && sem_init(&EF_sem, 0, 1) >= 0)\n+\t\t\tsemEnabled = 1;\n+\t}\n+}\n+#endif\n+\n/*\n* allocateMoreSlots is called when there are only enough slot structures\n* left to support the allocation of a single malloc buffer.'),
4-
('ElectricFence-2.2.2/Makefile.jj',
5-
'ElectricFence-2.2.2/Makefile',
6-
'--- ElectricFence-2.2.2/Makefile.jj\n+++ ElectricFence-2.2.2/Makefile\n@@ -1,6 +1,6 @@\nPIC= -fPIC\nCFLAGS= -g -DUSE_SEMAPHORE $(PIC)\n-LIBS= -lpthread\n+LIBS=\n\nprefix=/usr\nBIN_INSTALL_DIR= $(prefix)/bin\n@@ -54,8 +54,8 @@ libefence.a: $(OBJECTS)\n$(AR) crv libefence.a $(OBJECTS)\n\nlibefence.so.0.0: $(OBJECTS)\n-\tgcc -g -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \\\n-\t\t$(OBJECTS) -lpthread -lc\n+\tgcc -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \\\n+\t\t$(CFLAGS) $(OBJECTS)\n\ntstheap: libefence.a tstheap.o\n- rm -f tstheap')]
1+
[
2+
[
3+
"ElectricFence-2.2.2/efence.c.jj",
4+
"ElectricFence-2.2.2/efence.c",
5+
[
6+
"--- ElectricFence-2.2.2/efence.c.jj",
7+
"+++ ElectricFence-2.2.2/efence.c",
8+
"@@ -174,6 +174,15 @@ static int\t\tinternalUse = 0;",
9+
"static int\t\tnoAllocationListProtection = 0;",
10+
"",
11+
"#ifdef USE_SEMAPHORE",
12+
"+",
13+
"+#include <stdbool.h>",
14+
"+",
15+
"+#pragma weak sem_init",
16+
"+#pragma weak sem_post",
17+
"+#pragma weak sem_wait",
18+
"+",
19+
"+static int\t\tpthread_initialization = 0;",
20+
"+",
21+
"/*",
22+
"* EF_sem is a semaphore used to allow one thread at a time into",
23+
"* these routines.",
24+
"@@ -274,7 +283,7 @@ initialize(void)",
25+
"EF_Print(version);",
26+
"",
27+
"#ifdef USE_SEMAPHORE",
28+
"-\tif (sem_init(&EF_sem, 0, 1) >= 0) {",
29+
"+\tif (sem_init != NULL && !pthread_initialization && sem_init(&EF_sem, 0, 1) >= 0) {",
30+
"semEnabled = 1;",
31+
"}",
32+
"#endif",
33+
"@@ -397,6 +406,21 @@ initialize(void)",
34+
"release();",
35+
"}",
36+
"",
37+
"+#ifdef USE_SEMAPHORE",
38+
"+void",
39+
"+__libc_malloc_pthread_startup (bool first_time)",
40+
"+{",
41+
"+\tif (first_time) {",
42+
"+\t\tpthread_initialization = 1;",
43+
"+\t\tinitialize ();",
44+
"+\t} else {",
45+
"+\t\tpthread_initialization = 0;",
46+
"+\t\tif (!semEnabled && sem_init != NULL && sem_init(&EF_sem, 0, 1) >= 0)",
47+
"+\t\t\tsemEnabled = 1;",
48+
"+\t}",
49+
"+}",
50+
"+#endif",
51+
"+",
52+
"/*",
53+
"* allocateMoreSlots is called when there are only enough slot structures",
54+
"* left to support the allocation of a single malloc buffer."
55+
]
56+
],
57+
[
58+
"ElectricFence-2.2.2/Makefile.jj",
59+
"ElectricFence-2.2.2/Makefile",
60+
[
61+
"--- ElectricFence-2.2.2/Makefile.jj",
62+
"+++ ElectricFence-2.2.2/Makefile",
63+
"@@ -1,6 +1,6 @@",
64+
"PIC= -fPIC",
65+
"CFLAGS= -g -DUSE_SEMAPHORE $(PIC)",
66+
"-LIBS= -lpthread",
67+
"+LIBS=",
68+
"",
69+
"prefix=/usr",
70+
"BIN_INSTALL_DIR= $(prefix)/bin",
71+
"@@ -54,8 +54,8 @@ libefence.a: $(OBJECTS)",
72+
"$(AR) crv libefence.a $(OBJECTS)",
73+
"",
74+
"libefence.so.0.0: $(OBJECTS)",
75+
"-\tgcc -g -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \\",
76+
"-\t\t$(OBJECTS) -lpthread -lc",
77+
"+\tgcc -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \\",
78+
"+\t\t$(CFLAGS) $(OBJECTS)",
79+
"",
80+
"tstheap: libefence.a tstheap.o",
81+
"- rm -f tstheap"
82+
]
83+
]
84+
]

tests/extractcode/data/patch/patches/dnsmasq_2.63-1.diff.expected

Lines changed: 2111 additions & 57 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)