RsBundle  Check-in [30e5f0f086]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use `const_cstr` for C-string literals.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 30e5f0f08672b74a49581e77419e9e5061e17c44
User & Date: fifr 2017-03-16 20:51:51.129
Context
2017-03-17
09:28
Remove dependency on `libc`, use `const_cstr` instead. check-in: d86db8c998 user: fifr tags: trunk
2017-03-16
20:51
Use `const_cstr` for C-string literals. check-in: 30e5f0f086 user: fifr tags: trunk
15:06
Remove build script. check-in: 8a75c0bcc8 user: fifr tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to Cargo.toml.
1
2
3
4
5
6
7
8
9

10
11
12
13
[package]
name = "bundle"
version = "0.3.0"
authors = ["Frank Fischer <frank-fischer@shadow-soft.de>"]

[dependencies]
libc = "^0.2.6"
quick-error = "^1.1.0"
log = "^0.3.6"

cplex-sys = { version = "^0.1", path = "../cplex-sys" }

[dev-dependencies]
env_logger = "^0.4.1"









>




1
2
3
4
5
6
7
8
9
10
11
12
13
14
[package]
name = "bundle"
version = "0.3.0"
authors = ["Frank Fischer <frank-fischer@shadow-soft.de>"]

[dependencies]
libc = "^0.2.6"
quick-error = "^1.1.0"
log = "^0.3.6"
const-cstr = "^0.1"
cplex-sys = { version = "^0.1", path = "../cplex-sys" }

[dev-dependencies]
env_logger = "^0.4.1"
Changes to src/lib.rs.
15
16
17
18
19
20
21


22
23
24
25
26
27
28
//

//! Proximal bundle method implementation.

#[macro_use]
extern crate quick_error;
extern crate libc;



#[macro_use]
extern crate log;

/// Type used for real numbers throughout the library.
pub type Real = f64;








>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//

//! Proximal bundle method implementation.

#[macro_use]
extern crate quick_error;
extern crate libc;
#[macro_use]
extern crate const_cstr;

#[macro_use]
extern crate log;

/// Type used for real numbers throughout the library.
pub type Real = f64;

Changes to src/mcf/solver.rs.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    fn drop(&mut self) {
        unsafe {
            CPXNETfreeprob(env(), &mut self.net);
            CPXfclose(self.logfile);
        }
    }
}

fn clit(s: &'static str) -> *const c_char {
    s.as_ptr() as *const c_char
}


impl Solver {
    pub fn new(nnodes: usize) -> Result<Solver> {
        let mut status: c_int;
        let mut net = ptr::null_mut();
        let logfile;

        unsafe {
            #[cfg_attr(feature = "cargo-clippy", allow(never_loop))]
            loop {
                logfile = CPXfopen(clit("mcf.cpxlog"), clit("w"));
                if logfile.is_null() {
                    return Err(Error::Cplex(CplexError {
                        code: 0,
                        msg: "Can't open log-file".to_string(),
                    }));
                }
                status = CPXsetlogfile(env(), logfile);
                if status != 0 {
                    break;
                }

                net = CPXNETcreateprob(env(), &mut status, clit("mcf"));
                if status != 0 {
                    break;
                }
                status = CPXNETaddnodes(env(), net, nnodes as c_int, ptr::null(), ptr::null());
                if status != 0 {
                    break;
                }







<
<
<
<
<










|











|







48
49
50
51
52
53
54





55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    fn drop(&mut self) {
        unsafe {
            CPXNETfreeprob(env(), &mut self.net);
            CPXfclose(self.logfile);
        }
    }
}






impl Solver {
    pub fn new(nnodes: usize) -> Result<Solver> {
        let mut status: c_int;
        let mut net = ptr::null_mut();
        let logfile;

        unsafe {
            #[cfg_attr(feature = "cargo-clippy", allow(never_loop))]
            loop {
                logfile = CPXfopen(const_cstr!("mcf.cpxlog").as_ptr(), const_cstr!("w").as_ptr());
                if logfile.is_null() {
                    return Err(Error::Cplex(CplexError {
                        code: 0,
                        msg: "Can't open log-file".to_string(),
                    }));
                }
                status = CPXsetlogfile(env(), logfile);
                if status != 0 {
                    break;
                }

                net = CPXNETcreateprob(env(), &mut status, const_cstr!("mcf").as_ptr());
                if status != 0 {
                    break;
                }
                status = CPXNETaddnodes(env(), net, nnodes as c_int, ptr::null(), ptr::null());
                if status != 0 {
                    break;
                }