Added
Link Here
|
0 |
- |
1 |
--- src/magic_stubs.c.orig 2008-03-23 20:39:45 UTC |
|
|
2 |
+++ src/magic_stubs.c |
3 |
@@ -53,7 +53,7 @@ static void raise_magic_failure(const char * msg) |
4 |
{ |
5 |
static value * exn = NULL; |
6 |
if (exn == NULL) exn = caml_named_value("Magic.Failure"); |
7 |
- raise_with_string(*exn, (char *) msg); |
8 |
+ caml_raise_with_string(*exn, (char *) msg); |
9 |
} |
10 |
|
11 |
/* [raise_on_error] raises an exception according to the error that |
12 |
@@ -73,20 +73,20 @@ static void raise_on_error(const char* fname, const ma |
13 |
if (err_magic != NULL) { |
14 |
/* libmagic error */ |
15 |
if ((errmsg = malloc(flen + strlen(err_magic) + 1)) == NULL) |
16 |
- raise_out_of_memory(); |
17 |
+ caml_raise_out_of_memory(); |
18 |
if (exn == NULL) exn = caml_named_value("Magic.Failure"); |
19 |
strcpy(errmsg, fname); |
20 |
strcpy(errmsg + flen, err_magic); |
21 |
- verrmsg = copy_string(errmsg); |
22 |
+ verrmsg = caml_copy_string(errmsg); |
23 |
free(errmsg); /* err_magic is freed by magic_close */ |
24 |
- raise_with_arg(*exn, verrmsg); |
25 |
+ caml_raise_with_arg(*exn, verrmsg); |
26 |
} |
27 |
else { |
28 |
/* System error */ |
29 |
const int err = magic_errno(cookie); |
30 |
int len = 80; /* buffer length */ |
31 |
|
32 |
- if ((errmsg = malloc(len)) == NULL) raise_out_of_memory(); |
33 |
+ if ((errmsg = malloc(len)) == NULL) caml_raise_out_of_memory(); |
34 |
strcpy(errmsg, fname); |
35 |
#ifdef HAVE_STRERROR_R |
36 |
/* Allocate buffer [errmsg] until there is enough space for the |
37 |
@@ -95,15 +95,15 @@ static void raise_on_error(const char* fname, const ma |
38 |
/* Reallocate to a bigger size -- no need to keep the contents */ |
39 |
len *= 2; |
40 |
free(errmsg); |
41 |
- if ((errmsg = malloc(len)) == NULL) raise_out_of_memory(); |
42 |
+ if ((errmsg = malloc(len)) == NULL) caml_raise_out_of_memory(); |
43 |
strcpy(errmsg, fname); |
44 |
} |
45 |
#else |
46 |
strncat(errmsg, strerror(err), len - flen - 1); |
47 |
#endif |
48 |
- verrmsg = copy_string(errmsg); |
49 |
+ verrmsg = caml_copy_string(errmsg); |
50 |
free(errmsg); |
51 |
- raise_sys_error(verrmsg); |
52 |
+ caml_raise_sys_error(verrmsg); |
53 |
} |
54 |
|
55 |
CAMLreturn0; |
56 |
@@ -147,7 +147,7 @@ static struct custom_operations cookie_ops = { |
57 |
/* deserialize */ custom_deserialize_default |
58 |
}; |
59 |
|
60 |
-#define ALLOC_COOKIE alloc_custom(&cookie_ops, sizeof(magic_t), \ |
61 |
+#define ALLOC_COOKIE caml_alloc_custom(&cookie_ops, sizeof(magic_t), \ |
62 |
sizeof(magic_t), 40 * sizeof(magic_t)) |
63 |
|
64 |
/* |
65 |
@@ -169,22 +169,22 @@ CAMLprim value ocaml_magic_open(value flags) |
66 |
else { |
67 |
const int err = errno; /* save it */ |
68 |
|
69 |
- if ((errmsg = malloc(len)) == NULL) raise_out_of_memory(); |
70 |
+ if ((errmsg = malloc(len)) == NULL) caml_raise_out_of_memory(); |
71 |
strcpy(errmsg, "Magic.create: "); /* 14 chars */ |
72 |
#ifdef HAVE_STRERROR_R |
73 |
/* No cookie yet, so one cannot use the above generic err fun */ |
74 |
while(strerror_r(err, errmsg + 14, len - 14) < 0) { |
75 |
len *= 2; |
76 |
free(errmsg); |
77 |
- if ((errmsg = malloc(len)) == NULL) raise_out_of_memory(); |
78 |
+ if ((errmsg = malloc(len)) == NULL) caml_raise_out_of_memory(); |
79 |
strcpy(errmsg, "Magic.create: "); |
80 |
} |
81 |
#else |
82 |
strncat(errmsg, strerror(err), len - 15); |
83 |
#endif |
84 |
- verrmsg = copy_string(errmsg); |
85 |
+ verrmsg = caml_copy_string(errmsg); |
86 |
free(errmsg); |
87 |
- raise_sys_error(verrmsg); |
88 |
+ caml_raise_sys_error(verrmsg); |
89 |
} |
90 |
} |
91 |
CAMLreturn(c); |
92 |
@@ -207,11 +207,11 @@ CAMLprim value ocaml_magic_file(value c, value fname) |
93 |
const char * ans; |
94 |
const magic_t cookie = COOKIE_VAL(c); |
95 |
|
96 |
- if (cookie == NULL) invalid_argument("Magic.file"); |
97 |
+ if (cookie == NULL) caml_invalid_argument("Magic.file"); |
98 |
if ((ans = magic_file(cookie, String_val(fname))) == NULL) { |
99 |
raise_on_error("Magic.file: ", cookie); |
100 |
} |
101 |
- CAMLreturn(copy_string(ans)); |
102 |
+ CAMLreturn(caml_copy_string(ans)); |
103 |
} |
104 |
|
105 |
CAMLprim value ocaml_magic_buffer(value c, value buf, value len) |
106 |
@@ -224,7 +224,7 @@ CAMLprim value ocaml_magic_buffer(value c, value buf, |
107 |
if ((ans = magic_buffer(cookie, String_val(buf), Int_val(len))) |
108 |
== NULL) |
109 |
raise_on_error("Magic.buffer: ", cookie); |
110 |
- CAMLreturn(copy_string(ans)); |
111 |
+ CAMLreturn(caml_copy_string(ans)); |
112 |
} |
113 |
|
114 |
|