Skip to content

Commit d3079a1

Browse files
Fix bare raw pointers (switch to *const T)
1 parent e4dac5c commit d3079a1

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

pkg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ struct pcre_extra;
116116
117117
#[link(name = \"pcre\")]
118118
extern {{
119-
static pcre_free: extern \"C\" fn(ptr: *c_void);
119+
static pcre_free: extern \"C\" fn(ptr: *const c_void);
120120
121-
fn pcre_compile(pattern: *c_char, options: options, errptr: *mut *c_char, erroffset: *mut c_int, tableptr: *c_uchar) -> *pcre;
122-
fn pcre_exec(code: *pcre, extra: *pcre_extra, subject: *c_char, length: c_int, startoffset: c_int, options: options, ovector: *mut c_int, ovecsize: c_int) -> c_int;
123-
fn pcre_version() -> *c_char;
121+
fn pcre_compile(pattern: *const c_char, options: options, errptr: *mut *const c_char, erroffset: *mut c_int, tableptr: *const c_uchar) -> *const pcre;
122+
fn pcre_exec(code: *const pcre, extra: *const pcre_extra, subject: *const c_char, length: c_int, startoffset: c_int, options: options, ovector: *mut c_int, ovecsize: c_int) -> c_int;
123+
fn pcre_version() -> *const c_char;
124124
}}
125125
126126
fn main () {{
@@ -130,7 +130,7 @@ fn main () {{
130130
131131
let pattern = \"^\\\\d+\\\\.\\\\d+\";
132132
pattern.with_c_str(|pattern_c_str| {{
133-
let mut err: *c_char = ptr::null();
133+
let mut err: *const c_char = ptr::null();
134134
let mut erroffset: c_int = 0;
135135
let code = pcre_compile(pattern_c_str, 0, &mut err, &mut erroffset, ptr::null());
136136
if code.is_null() {{
@@ -155,7 +155,7 @@ fn main () {{
155155
print!(\"{{}}\", version_str.as_slice().slice_to(*ovector.get(1) as uint));
156156
}});
157157
158-
pcre_free(code as *c_void);
158+
pcre_free(code as *const c_void);
159159
}});
160160
}}
161161
}}

src/pcre/detail/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub static PCRE_INFO_NAMEENTRYSIZE: fullinfo_field = 7;
3737
pub static PCRE_INFO_NAMECOUNT: fullinfo_field = 8;
3838
pub static PCRE_INFO_NAMETABLE: fullinfo_field = 9;
3939

40-
pub unsafe fn pcre_compile(pattern: *c_char, options: &EnumSet<::CompileOption>, tableptr: *c_uchar) -> Result<*mut pcre, (Option<String>, c_int)> {
40+
pub unsafe fn pcre_compile(pattern: *const c_char, options: &EnumSet<::CompileOption>, tableptr: *const c_uchar) -> Result<*mut pcre, (Option<String>, c_int)> {
4141
assert!(pattern.is_not_null());
4242
let converted_options = options.iter().fold(0, |converted_options, option| converted_options | (option as compile_options)) | PCRE_UTF8 | PCRE_NO_UTF8_CHECK;
43-
let mut err: *c_char = ptr::null();
43+
let mut err: *const c_char = ptr::null();
4444
let mut erroffset: c_int = 0;
4545
let code = native::pcre_compile(pattern, converted_options, &mut err, &mut erroffset, tableptr);
4646

@@ -64,7 +64,7 @@ pub unsafe fn pcre_compile(pattern: *c_char, options: &EnumSet<::CompileOption>,
6464
}
6565
}
6666

67-
pub unsafe fn pcre_exec(code: *pcre, extra: *::PcreExtra, subject: *c_char, length: c_int, startoffset: c_int, options: &EnumSet<::ExecOption>, ovector: *mut c_int, ovecsize: c_int) -> c_int {
67+
pub unsafe fn pcre_exec(code: *const pcre, extra: *const ::PcreExtra, subject: *const c_char, length: c_int, startoffset: c_int, options: &EnumSet<::ExecOption>, ovector: *mut c_int, ovecsize: c_int) -> c_int {
6868
assert!(code.is_not_null());
6969
assert!(ovecsize >= 0 && ovecsize % 3 == 0);
7070
let converted_options = options.iter().fold(0, |converted_options, option| converted_options | (option as compile_options)) | PCRE_NO_UTF8_CHECK;
@@ -86,7 +86,7 @@ pub unsafe fn pcre_free_study(extra: *mut ::PcreExtra) {
8686
native::pcre_free_study(extra);
8787
}
8888

89-
pub unsafe fn pcre_fullinfo(code: *pcre, extra: *::PcreExtra, what: fullinfo_field, where: *mut c_void) {
89+
pub unsafe fn pcre_fullinfo(code: *const pcre, extra: *const ::PcreExtra, what: fullinfo_field, where: *mut c_void) {
9090
assert!(code.is_not_null());
9191
let rc = native::pcre_fullinfo(code, extra, what, where);
9292
if rc < 0 && rc != PCRE_ERROR_NULL {
@@ -105,10 +105,10 @@ pub unsafe fn pcre_refcount(code: *mut ::detail::pcre, adjust: c_int) -> c_int {
105105
native::pcre_refcount(code, adjust)
106106
}
107107

108-
pub unsafe fn pcre_study(code: *::detail::pcre, options: &EnumSet<::StudyOption>) -> *mut ::PcreExtra {
108+
pub unsafe fn pcre_study(code: *const ::detail::pcre, options: &EnumSet<::StudyOption>) -> *mut ::PcreExtra {
109109
assert!(code.is_not_null());
110110
let converted_options = options.iter().fold(0, |converted_options, option| converted_options | (option as study_options));
111-
let mut err: *c_char = ptr::null();
111+
let mut err: *const c_char = ptr::null();
112112
let extra = native::pcre_study(code, converted_options, &mut err);
113113
// "The third argument for pcre_study() is a pointer for an error message. If
114114
// studying succeeds (even if no data is returned), the variable it points to is

src/pcre/detail/native.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use libc::{c_char, c_int, c_uchar, c_void};
1212
extern {
1313
pub static pcre_free: extern "C" fn(ptr: *mut c_void);
1414

15-
pub fn pcre_compile(pattern: *c_char, options: ::detail::compile_options, errptr: *mut *c_char, erroffset: *mut c_int, tableptr: *c_uchar) -> *mut ::detail::pcre;
16-
pub fn pcre_exec(code: *::detail::pcre, extra: *::PcreExtra, subject: *c_char, length: c_int, startoffset: c_int, options: ::detail::exec_options, ovector: *mut c_int, ovecsize: c_int) -> c_int;
15+
pub fn pcre_compile(pattern: *const c_char, options: ::detail::compile_options, errptr: *mut *const c_char, erroffset: *mut c_int, tableptr: *const c_uchar) -> *mut ::detail::pcre;
16+
pub fn pcre_exec(code: *const ::detail::pcre, extra: *const ::PcreExtra, subject: *const c_char, length: c_int, startoffset: c_int, options: ::detail::exec_options, ovector: *mut c_int, ovecsize: c_int) -> c_int;
1717
pub fn pcre_free_study(extra: *mut ::PcreExtra);
18-
pub fn pcre_fullinfo(code: *::detail::pcre, extra: *::PcreExtra, what: ::detail::fullinfo_field, where: *mut c_void) -> c_int;
18+
pub fn pcre_fullinfo(code: *const ::detail::pcre, extra: *const ::PcreExtra, what: ::detail::fullinfo_field, where: *mut c_void) -> c_int;
1919
// Note: libpcre's pcre_refcount() function is not thread-safe.
2020
pub fn pcre_refcount(code: *mut ::detail::pcre, adjust: c_int) -> c_int;
21-
pub fn pcre_study(code: *::detail::pcre, options: ::detail::study_options, errptr: *mut *c_char) -> *mut ::PcreExtra;
22-
pub fn pcre_version() -> *c_char;
21+
pub fn pcre_study(code: *const ::detail::pcre, options: ::detail::study_options, errptr: *mut *const c_char) -> *mut ::PcreExtra;
22+
pub fn pcre_version() -> *const c_char;
2323
}

src/pcre/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct CompilationError {
110110
#[deriving(Show)]
111111
pub struct Pcre {
112112

113-
code: *detail::pcre,
113+
code: *const detail::pcre,
114114

115115
extra: *mut PcreExtra,
116116

@@ -127,7 +127,7 @@ pub struct PcreExtra {
127127
study_data: *mut c_void,
128128
match_limit_: c_ulong,
129129
callout_data: *mut c_void,
130-
tables: *c_uchar,
130+
tables: *const c_uchar,
131131
match_limit_recursion_: c_ulong,
132132
mark: *mut *mut c_uchar,
133133
executable_jit: *mut c_void
@@ -148,9 +148,9 @@ pub struct Match<'a> {
148148
/// Iterator type for iterating matches within a subject string.
149149
pub struct MatchIterator<'a> {
150150

151-
code: *detail::pcre,
151+
code: *const detail::pcre,
152152

153-
extra: *PcreExtra,
153+
extra: *const PcreExtra,
154154

155155
capture_count: c_int,
156156

@@ -353,22 +353,22 @@ impl Pcre {
353353
pattern.with_c_str(|pattern_c_str| {
354354
unsafe {
355355
// Use the default character tables.
356-
let tableptr: *c_uchar = ptr::null();
356+
let tableptr: *const c_uchar = ptr::null();
357357
match detail::pcre_compile(pattern_c_str, options, tableptr) {
358358
Err((opt_err, erroffset)) => Err(CompilationError {
359359
opt_err: opt_err,
360360
erroffset: erroffset
361361
}),
362362
Ok(mut_code) => {
363-
let code = mut_code as *detail::pcre;
363+
let code = mut_code as *const detail::pcre;
364364
assert!(code.is_not_null());
365365
// Take a reference.
366366
detail::pcre_refcount(code as *mut detail::pcre, 1);
367367

368368
let extra: *mut PcreExtra = ptr::mut_null();
369369

370370
let mut capture_count: c_int = 0;
371-
detail::pcre_fullinfo(code, extra as *PcreExtra, detail::PCRE_INFO_CAPTURECOUNT,
371+
detail::pcre_fullinfo(code, extra as *const PcreExtra, detail::PCRE_INFO_CAPTURECOUNT,
372372
&mut capture_count as *mut c_int as *mut c_void);
373373

374374
Ok(Pcre {
@@ -492,7 +492,7 @@ impl Pcre {
492492

493493
unsafe {
494494
subject.with_c_str_unchecked(|subject_c_str| -> Option<Match<'a>> {
495-
let rc = detail::pcre_exec(self.code, self.extra as *PcreExtra, subject_c_str, subject.len() as c_int, startoffset as c_int, options, ovector.as_mut_ptr(), ovecsize as c_int);
495+
let rc = detail::pcre_exec(self.code, self.extra as *const PcreExtra, subject_c_str, subject.len() as c_int, startoffset as c_int, options, ovector.as_mut_ptr(), ovecsize as c_int);
496496
if rc >= 0 {
497497
Some(Match {
498498
subject: subject,
@@ -519,8 +519,8 @@ impl Pcre {
519519
None
520520
} else {
521521
let slice: Slice<c_uchar> = Slice {
522-
data: self.mark_ as *c_uchar,
523-
len: libc::strlen(self.mark_ as *c_char) as uint
522+
data: self.mark_ as *const c_uchar,
523+
len: libc::strlen(self.mark_ as *const c_char) as uint
524524
};
525525
Some(mem::transmute(slice))
526526
}
@@ -551,7 +551,7 @@ impl Pcre {
551551
let ovecsize = (self.capture_count_ + 1) * 3;
552552
MatchIterator {
553553
code: { detail::pcre_refcount(self.code as *mut detail::pcre, 1); self.code },
554-
extra: self.extra as *PcreExtra,
554+
extra: self.extra as *const PcreExtra,
555555
capture_count: self.capture_count_,
556556
subject: subject,
557557
subject_cstring: subject.to_c_str_unchecked(), // the subject string can contain NUL bytes
@@ -566,7 +566,7 @@ impl Pcre {
566566
pub fn name_count(&self) -> uint {
567567
unsafe {
568568
let mut name_count: c_int = 0;
569-
detail::pcre_fullinfo(self.code, self.extra as *PcreExtra, detail::PCRE_INFO_NAMECOUNT, &mut name_count as *mut c_int as *mut c_void);
569+
detail::pcre_fullinfo(self.code, self.extra as *const PcreExtra, detail::PCRE_INFO_NAMECOUNT, &mut name_count as *mut c_int as *mut c_void);
570570
name_count as uint
571571
}
572572
}
@@ -580,17 +580,17 @@ impl Pcre {
580580
pub fn name_table(&self) -> TreeMap<String, Vec<uint>> {
581581
unsafe {
582582
let name_count = self.name_count();
583-
let mut tabptr: *c_uchar = ptr::null();
584-
detail::pcre_fullinfo(self.code, self.extra as *PcreExtra, detail::PCRE_INFO_NAMETABLE, &mut tabptr as *mut *c_uchar as *mut c_void);
583+
let mut tabptr: *const c_uchar = ptr::null();
584+
detail::pcre_fullinfo(self.code, self.extra as *const PcreExtra, detail::PCRE_INFO_NAMETABLE, &mut tabptr as *mut *const c_uchar as *mut c_void);
585585
let mut name_entry_size: c_int = 0;
586-
detail::pcre_fullinfo(self.code, self.extra as *PcreExtra, detail::PCRE_INFO_NAMEENTRYSIZE, &mut name_entry_size as *mut c_int as *mut c_void);
586+
detail::pcre_fullinfo(self.code, self.extra as *const PcreExtra, detail::PCRE_INFO_NAMEENTRYSIZE, &mut name_entry_size as *mut c_int as *mut c_void);
587587

588588
let mut name_table: TreeMap<String, Vec<uint>> = TreeMap::new();
589589

590590
let mut i = 0u;
591591
while i < name_count {
592592
let n: uint = (ptr::read(tabptr) as uint << 8) | (ptr::read(tabptr.offset(1)) as uint);
593-
let name_cstring = c_str::CString::new(tabptr.offset(2) as *c_char, false);
593+
let name_cstring = c_str::CString::new(tabptr.offset(2) as *const c_char, false);
594594
let name: String = name_cstring.as_str().unwrap().to_owned();
595595
// TODO Avoid the double lookup.
596596
// https://github.com/mozilla/rust/issues/9068

0 commit comments

Comments
 (0)