Changeset 54
- Timestamp:
- 12/12/06 17:10:59 (2 years ago)
- Files:
-
- trunk/examples/rawexample/rawexample.d (modified) (1 diff)
- trunk/infrastructure/pyd/class_wrap.d (modified) (6 diffs)
- trunk/infrastructure/pyd/def.d (modified) (3 diffs)
- trunk/infrastructure/pyd/exception.d (modified) (1 diff)
- trunk/infrastructure/pyd/func_wrap.d (modified) (1 diff)
- trunk/infrastructure/pyd/make_object.d (modified) (1 diff)
- trunk/infrastructure/pyd/pydobject.d (modified) (10 diffs)
- trunk/infrastructure/pyd/struct_wrap.d (modified) (1 diff)
- trunk/infrastructure/python/2.4/python.d (modified) (5 diffs)
- trunk/infrastructure/python/2.5/python.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/rawexample/rawexample.d
r53 r54 62 62 extern(C) 63 63 export void initrawexample() { 64 PyObject* m = Py_InitModule("rawexample", rawexample_methods );64 PyObject* m = Py_InitModule("rawexample", rawexample_methods.ptr); 65 65 66 66 Base_type.ob_type = PyType_Type_p; trunk/infrastructure/pyd/class_wrap.d
r52 r54 262 262 // It's possible that appending the empty item invalidated the 263 263 // pointer in the type struct, so we renew it here. 264 wrapped_class_type!(T).tp_methods = list ;264 wrapped_class_type!(T).tp_methods = list.ptr; 265 265 } 266 266 … … 291 291 pragma(msg, "class.prop: " ~ name); 292 292 static PyGetSetDef empty = { null, null, null, null, null }; 293 wrapped_prop_list!(T)[length-1].name = name ~ \0;293 wrapped_prop_list!(T)[length-1].name = (name ~ \0).ptr; 294 294 wrapped_prop_list!(T)[length-1].get = 295 295 &wrapped_get!(T, fn).func; … … 304 304 // pointer in the type struct, so we renew it here. 305 305 wrapped_class_type!(T).tp_getset = 306 wrapped_prop_list!(T) ;306 wrapped_prop_list!(T).ptr; 307 307 } 308 308 … … 379 379 type.ob_type = PyType_Type_p(); 380 380 type.tp_basicsize = (wrapped_class_object!(T)).sizeof; 381 type.tp_doc = name ~ " objects" ~ \0;381 type.tp_doc = (name ~ " objects" ~ \0).ptr; 382 382 type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; 383 383 //type.tp_repr = &wrapped_repr!(T).repr; 384 type.tp_methods = wrapped_method_list!(T) ;385 type.tp_name = module_name ~ "." ~ name ~ \0;384 type.tp_methods = wrapped_method_list!(T).ptr; 385 type.tp_name = (module_name ~ "." ~ name ~ \0).ptr; 386 386 387 387 // Numerical operator overloads … … 431 431 } 432 432 Py_INCREF(cast(PyObject*)&type); 433 PyModule_AddObject(Pyd_Module_p(modulename), name , cast(PyObject*)&type);433 PyModule_AddObject(Pyd_Module_p(modulename), name.ptr, cast(PyObject*)&type); 434 434 is_wrapped!(T) = true; 435 435 wrapped_classes[typeid(T)] = true; … … 471 471 return obj; 472 472 } else { 473 PyErr_SetString(PyExc_RuntimeError, "Type " ~ typeid(T).toString() ~ " is not wrapped by Pyd.");473 PyErr_SetString(PyExc_RuntimeError, ("Type " ~ typeid(T).toString() ~ " is not wrapped by Pyd.").ptr); 474 474 return null; 475 475 } trunk/infrastructure/pyd/def.d
r52 r54 87 87 PyMethodDef[]* list = &module_methods[modulename]; 88 88 89 (*list)[length-1].ml_name = name ~ \0;89 (*list)[length-1].ml_name = (name ~ \0).ptr; 90 90 (*list)[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; 91 91 (*list)[length-1].ml_flags = METH_VARARGS; … … 99 99 PyObject* module_init(char[] name) { 100 100 //_loadPythonSupport(); 101 pyd_modules[""] = Py_InitModule( name ~ \0, module_methods[""].ptr);101 pyd_modules[""] = Py_InitModule((name ~ \0).ptr, module_methods[""].ptr); 102 102 return pyd_modules[""]; 103 103 } … … 107 107 */ 108 108 PyObject* add_module(char[] name) { 109 pyd_modules[name] = Py_InitModule( name ~ \0, module_methods[name].ptr);109 pyd_modules[name] = Py_InitModule((name ~ \0).ptr, module_methods[name].ptr); 110 110 return pyd_modules[name]; 111 111 } trunk/infrastructure/pyd/exception.d
r46 r54 77 77 // Python exception. 78 78 catch (Exception e) { 79 PyErr_SetString(PyExc_RuntimeError, "D Exception: " ~ e.classinfo.name ~ ": " ~ e.msg ~ \0);79 PyErr_SetString(PyExc_RuntimeError, ("D Exception: " ~ e.classinfo.name ~ ": " ~ e.msg ~ \0).ptr); 80 80 return error_code!(T)(); 81 81 } 82 82 // Some other D object was thrown. Deal with it. 83 83 catch (Object o) { 84 PyErr_SetString(PyExc_RuntimeError, "thrown D Object: " ~ o.classinfo.name ~ ": " ~ o.toString() ~ \0);84 PyErr_SetString(PyExc_RuntimeError, ("thrown D Object: " ~ o.classinfo.name ~ ": " ~ o.toString() ~ \0).ptr); 85 85 return error_code!(T)(); 86 86 } trunk/infrastructure/pyd/func_wrap.d
r52 r54 85 85 str ~= " (" ~ toString(gotArgs) ~ " given)"; 86 86 87 PyErr_SetString(PyExc_TypeError, str ~ \0);87 PyErr_SetString(PyExc_TypeError, (str ~ \0).ptr); 88 88 } 89 89 trunk/infrastructure/pyd/make_object.d
r52 r54 165 165 return t; 166 166 } 167 PyErr_SetString(PyExc_RuntimeError, "D conversion function _py failed with type " ~ typeid(T).toString());167 PyErr_SetString(PyExc_RuntimeError, ("D conversion function _py failed with type " ~ typeid(T).toString()).ptr); 168 168 return null; 169 169 } trunk/infrastructure/pyd/pydobject.d
r49 r54 91 91 /// Same as _hasattr(this, attr_name) in Python. 92 92 bool hasattr(char[] attr_name) { 93 return PyObject_HasAttrString(m_ptr, attr_name ~ \0) == 1;93 return PyObject_HasAttrString(m_ptr, (attr_name ~ \0).ptr) == 1; 94 94 } 95 95 … … 101 101 /// Same as _getattr(this, attr_name) in Python. 102 102 PydObject getattr(char[] attr_name) { 103 return new PydObject(PyObject_GetAttrString(m_ptr, attr_name ~ \0));103 return new PydObject(PyObject_GetAttrString(m_ptr, (attr_name ~ \0).ptr)); 104 104 } 105 105 … … 113 113 */ 114 114 void setattr(char[] attr_name, PydObject v) { 115 if (PyObject_SetAttrString(m_ptr, attr_name ~ \0, v.m_ptr) == -1)115 if (PyObject_SetAttrString(m_ptr, (attr_name ~ \0).ptr, v.m_ptr) == -1) 116 116 handle_exception(); 117 117 } … … 129 129 */ 130 130 void delattr(char[] attr_name) { 131 if (PyObject_DelAttrString(m_ptr, attr_name ~ \0) == -1)131 if (PyObject_DelAttrString(m_ptr, (attr_name ~ \0).ptr) == -1) 132 132 handle_exception(); 133 133 } … … 227 227 PydObject method(char[] name, PydObject args=null) { 228 228 // Get the method PydObject 229 PyObject* m = PyObject_GetAttrString(m_ptr, name ~ \0);229 PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ \0).ptr); 230 230 PyObject* self_tuple, args_tuple, result; 231 231 // If this method doesn't exist (or other error), throw exception … … 254 254 PydObject method(char[] name, PydObject args, PydObject kw) { 255 255 // Get the method PydObject 256 PyObject* m = PyObject_GetAttrString(m_ptr, name ~ \0);256 PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ \0).ptr); 257 257 PyObject* self_tuple, args_tuple, result; 258 258 // If this method doesn't exist (or other error), throw exception. … … 328 328 */ 329 329 PydObject opIndex(char[] key) { 330 return new PydObject(PyMapping_GetItemString(m_ptr, key ~ \0));330 return new PydObject(PyMapping_GetItemString(m_ptr, (key ~ \0).ptr)); 331 331 } 332 332 /// Equivalent to o[_i] in Python; usually only makes sense for sequences. … … 345 345 */ 346 346 void opIndexAssign(PydObject value, char[] key) { 347 if (PyMapping_SetItemString(m_ptr, key ~ \0, value.m_ptr) == -1)347 if (PyMapping_SetItemString(m_ptr, (key ~ \0).ptr, value.m_ptr) == -1) 348 348 handle_exception(); 349 349 } … … 367 367 */ 368 368 void delItem(char[] key) { 369 if (PyMapping_DelItemString(m_ptr, key ~ \0) == -1)369 if (PyMapping_DelItemString(m_ptr, (key ~ \0).ptr) == -1) 370 370 handle_exception(); 371 371 } … … 739 739 /// Same as opIn_r 740 740 bool hasKey(char[] key) { 741 int result = PyMapping_HasKeyString(m_ptr, key ~ \0);741 int result = PyMapping_HasKeyString(m_ptr, (key ~ \0).ptr); 742 742 if (result == -1) handle_exception(); 743 743 return result == 1; trunk/infrastructure/pyd/struct_wrap.d
r52 r54 71 71 static PyGetSetDef empty = {null, null, null, null, null}; 72 72 alias wrapped_prop_list!(T*) list; 73 list[length-1].name = name ~ \0;73 list[length-1].name = (name ~ \0).ptr; 74 74 list[length-1].get = &wrapped_member!(T*, M, offset).get; 75 75 list[length-1].set = &wrapped_member!(T*, M, offset).set; trunk/infrastructure/python/2.4/python.d
r45 r54 1192 1192 // Will the D layout for a 1-PyObject* array be the same as the C layout? 1193 1193 // I think the D array will be larger. 1194 PyObject *ob_item[1]; 1194 PyObject *_ob_item[1]; 1195 PyObject** ob_item() { 1196 return _ob_item.ptr; 1197 } 1195 1198 } 1196 1199 … … 3148 3151 // Will the D layout for a 1-obj array be the same as the C layout? I 3149 3152 // think the D array will be larger. 3150 PyObject *ob_item[1]; 3153 PyObject *_ob_item[1]; 3154 PyObject** ob_item() { 3155 return _ob_item.ptr; 3156 } 3151 3157 } 3152 3158 … … 3301 3307 PyObject *eval(char[] code) { 3302 3308 PyObject *pyGlobals = PyEval_GetGlobals(); /* borrowed ref */ 3303 PyObject *res = PyRun_String( code ~ \0, Py_eval_input,3309 PyObject *res = PyRun_String((code ~ \0).ptr, Py_eval_input, 3304 3310 pyGlobals, pyGlobals 3305 3311 ); /* New ref, or NULL on error. */ … … 3319 3325 if (Ptr is null) { 3320 3326 PyObject* sys_modules = PyImport_GetModuleDict(); 3321 Ptr = PyDict_GetItemString(sys_modules, name ~ \0);3327 Ptr = PyDict_GetItemString(sys_modules, (name ~ \0).ptr); 3322 3328 } 3323 3329 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); … … 3331 3337 typeof(Ptr) lazy_load(alias from, alias Ptr, char[] name) () { 3332 3338 if (Ptr is null) { 3333 Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), name ~ \0);3339 Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), (name ~ \0).ptr); 3334 3340 } 3335 3341 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); trunk/infrastructure/python/2.5/python.d
r45 r54 1237 1237 // Will the D layout for a 1-PyObject* array be the same as the C layout? 1238 1238 // I think the D array will be larger. 1239 PyObject *ob_item[1]; 1239 PyObject *_ob_item[1]; 1240 PyObject** ob_item() { 1241 return _ob_item.ptr; 1242 } 1240 1243 } 1241 1244 … … 3443 3446 // Will the D layout for a 1-obj array be the same as the C layout? I 3444 3447 // think the D array will be larger. 3445 PyObject *ob_item[1]; 3448 PyObject *_ob_item[1]; 3449 PyObject** ob_item() { 3450 return _ob_item.ptr; 3451 } 3446 3452 } 3447 3453 … … 3596 3602 PyObject *eval(char[] code) { 3597 3603 PyObject *pyGlobals = PyEval_GetGlobals(); /* borrowed ref */ 3598 PyObject *res = PyRun_String( code ~ \0, Py_eval_input,3604 PyObject *res = PyRun_String((code ~ \0).ptr, Py_eval_input, 3599 3605 pyGlobals, pyGlobals 3600 3606 ); /* New ref, or NULL on error. */ … … 3614 3620 if (Ptr is null) { 3615 3621 PyObject* sys_modules = PyImport_GetModuleDict(); 3616 Ptr = PyDict_GetItemString(sys_modules, name ~ \0);3622 Ptr = PyDict_GetItemString(sys_modules, (name ~ \0).ptr); 3617 3623 } 3618 3624 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); … … 3626 3632 typeof(Ptr) lazy_load(alias from, alias Ptr, char[] name) () { 3627 3633 if (Ptr is null) { 3628 Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), name ~ \0);3634 Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), (name ~ \0).ptr); 3629 3635 } 3630 3636 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!");
