| 79 | } |
| 80 | |
| 81 | unsafe fn copy_grouping(group: *const libc::c_char, vm: &VirtualMachine) -> PyListRef { |
| 82 | let mut group_vec: Vec<PyObjectRef> = Vec::new(); |
| 83 | if group.is_null() { |
| 84 | return vm.ctx.new_list(group_vec); |
| 85 | } |
| 86 | |
| 87 | unsafe { |
| 88 | let mut ptr = group; |
| 89 | while ![0, libc::c_char::MAX].contains(&*ptr) { |
| 90 | let val = vm.ctx.new_int(*ptr); |
| 91 | group_vec.push(val.into()); |
| 92 | ptr = ptr.add(1); |
| 93 | } |
| 94 | } |
| 95 | // https://github.com/python/cpython/blob/677320348728ce058fa3579017e985af74a236d4/Modules/_localemodule.c#L80 |
| 96 | if !group_vec.is_empty() { |
| 97 | group_vec.push(vm.ctx.new_int(0).into()); |
| 98 | } |
| 99 | vm.ctx.new_list(group_vec) |
| 100 | } |
| 101 | |
| 102 | unsafe fn pystr_from_raw_cstr(vm: &VirtualMachine, raw_ptr: *const libc::c_char) -> PyResult { |
| 103 | let slice = unsafe { CStr::from_ptr(raw_ptr) }; |