Changeset 71 for trunk/src/python
- Timestamp:
- Sep 27, 2005 9:49:42 AM (17 years ago)
- Location:
- trunk/src/python
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/PyRpUnits.cc
r68 r71 5 5 6 6 typedef struct { 7 8 7 PyObject_HEAD 8 RpUnits* rp_unit; 9 9 } RpUnitsObject; 10 11 // static PyTypeObject RpUnitsObjectType;12 13 /* Xxo methods */14 /*15 * moved this below because forward declaration of RpUnitsObjectType16 * was causing compiler errors ???17 *18 static RpUnitsObject*19 newRpUnitsObject(PyObject *arg)20 {21 RpUnitsObject* self;22 self = PyObject_New(RpUnitsObject, &RpUnitsObjectType);23 if (self == NULL)24 return NULL;25 self->rp_unit = NULL;26 return self;27 }28 */29 10 30 11 static void … … 36 17 // delete(self->rp_unit); 37 18 } 38 39 PyObject_Del(self); 19 PyObject_Del(self); 40 20 } 41 21 } … … 118 98 {"getExponent", (PyCFunction)RpUnitsObject_getExponent, METH_NOARGS, 119 99 "Return the exponent of the RpUnitsObject" }, 120 121 122 123 100 {"convert", (PyCFunction)RpUnitsObject_convert, METH_VARARGS, 101 "convert a value from one RpUnits Object to another" }, 102 {"makeBasis", (PyCFunction)RpUnitsObject_makeBasis, METH_VARARGS, 103 "return the basis value of the value provided" }, 124 104 125 105 {NULL} /* Sentinel */ … … 127 107 128 108 static PyTypeObject RpUnitsObjectType = { 129 130 131 132 0,/*ob_size*/133 "RpUnits.RpUnitsObject",/*tp_name*/134 sizeof(RpUnitsObject),/*tp_basicsize*/135 0,/*tp_itemsize*/136 137 (destructor)RpUnitsObject_dealloc,/*tp_dealloc*/138 0,/*tp_print*/139 0,/*tp_getattr*/140 0,/*tp_setattr*/141 0,/*tp_compare*/142 0,/*tp_repr*/143 0,/*tp_as_number*/144 0,/*tp_as_sequence*/145 0,/*tp_as_mapping*/146 0,/*tp_hash*/147 0, /*tp_call*/148 0, /*tp_str*/149 0, /*tp_getattro*/150 0, /*tp_setattro*/151 0, /*tp_as_buffer*/152 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 153 "RpUnits Object", /*tp_doc*/154 0, /*tp_traverse*/155 0, /*tp_clear*/156 0, /*tp_richcompare*/157 0, /*tp_weaklistoffset*/158 0, /*tp_iter*/159 0, /*tp_iternext*/160 RpUnitsObject_methods, /* tp_methods */161 0, /*tp_members*/162 0, /*tp_getset*/163 0, /*tp_base*/164 0, /*tp_dict*/165 0, /*tp_descr_get*/166 0, /*tp_descr_set*/167 0, /*tp_dictoffset*/168 0, /*tp_init*/169 0, /*tp_alloc*/170 // RpUnitsObject_new, 171 0, /*tp_new*/172 0, /*tp_free*/173 0, /*tp_is_gc*/109 /* The ob_type field must be initialized in the module init function 110 * to be portable to Windows without using C++. */ 111 PyObject_HEAD_INIT(NULL) 112 0, /*ob_size*/ 113 "RpUnits.RpUnitsObject", /*tp_name*/ 114 sizeof(RpUnitsObject), /*tp_basicsize*/ 115 0, /*tp_itemsize*/ 116 /* methods */ 117 (destructor)RpUnitsObject_dealloc, /*tp_dealloc*/ 118 0, /*tp_print*/ 119 0, /*tp_getattr*/ 120 0, /*tp_setattr*/ 121 0, /*tp_compare*/ 122 0, /*tp_repr*/ 123 0, /*tp_as_number*/ 124 0, /*tp_as_sequence*/ 125 0, /*tp_as_mapping*/ 126 0, /*tp_hash*/ 127 0, /*tp_call*/ 128 0, /*tp_str*/ 129 0, /*tp_getattro*/ 130 0, /*tp_setattro*/ 131 0, /*tp_as_buffer*/ 132 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 133 "RpUnits Object", /*tp_doc*/ 134 0, /*tp_traverse*/ 135 0, /*tp_clear*/ 136 0, /*tp_richcompare*/ 137 0, /*tp_weaklistoffset*/ 138 0, /*tp_iter*/ 139 0, /*tp_iternext*/ 140 RpUnitsObject_methods, /* tp_methods */ 141 0, /*tp_members*/ 142 0, /*tp_getset*/ 143 0, /*tp_base*/ 144 0, /*tp_dict*/ 145 0, /*tp_descr_get*/ 146 0, /*tp_descr_set*/ 147 0, /*tp_dictoffset*/ 148 0, /*tp_init*/ 149 0, /*tp_alloc*/ 150 // RpUnitsObject_new, /*tp_new*/ 151 0, /*tp_new*/ 152 0, /*tp_free*/ 153 0, /*tp_is_gc*/ 174 154 }; 175 155 … … 177 157 newRpUnitsObject(PyObject *arg) 178 158 { 179 180 181 182 183 184 159 RpUnitsObject* self; 160 self = PyObject_New(RpUnitsObject, &RpUnitsObjectType); 161 if (self == NULL) 162 return NULL; 163 self->rp_unit = NULL; 164 return self; 185 165 } 186 166 … … 248 228 RpUnits_define(PyObject *self, PyObject *args) 249 229 { 250 230 RpUnitsObject* newRpUnit; 251 231 RpUnitsObject* basis = NULL; 252 232 char* unitsName; … … 260 240 } 261 241 262 263 264 265 242 newRpUnit = newRpUnitsObject(args); 243 244 if (newRpUnit == NULL) 245 return NULL; 266 246 267 247 … … 280 260 } 281 261 282 262 return (PyObject *)newRpUnit; 283 263 } 284 264 … … 288 268 289 269 if ((PyObject*)fxnPtr != NULL) { 290 /*291 retVal = PyObject_CallFunctionObjArgs( (PyObject*)fxnPtr,292 (PyObject*)args,293 NULL );294 */295 296 270 retVal = PyObject_CallObject((PyObject*)fxnPtr,(PyObject*)args); 297 271 } … … 311 285 RpUnits_defineConv(PyObject *self, PyObject *args) 312 286 { 313 314 287 RpUnitsObject* fromUnit = NULL; 288 RpUnitsObject* toUnit = NULL; 315 289 PyObject* forwConvFxnStr = NULL; 316 290 PyObject* backConvFxnStr = NULL; … … 373 347 } 374 348 375 349 return (PyObject *)newRpUnit; 376 350 } 377 351 … … 386 360 { 387 361 char* searchUnits = NULL; 388 362 RpUnits* foundUnits = NULL; 389 363 RpUnitsObject* returnUnits = NULL; 390 364 … … 502 476 static PyMethodDef RpUnits_Methods[] = { 503 477 504 478 {"define", RpUnits_define, METH_VARARGS, 505 479 RpUnits_define_doc}, 506 480 507 481 {"defineConv", RpUnits_defineConv, METH_VARARGS, 508 482 RpUnits_defineConv_doc}, 509 483 510 484 {"find", RpUnits_find, METH_VARARGS, 511 485 RpUnits_find_doc}, 512 486 513 487 {"makeMetric", RpUnits_makeMetric, METH_VARARGS, 514 488 RpUnits_makeMetric_doc}, 515 489 516 490 {"convert", (PyCFunction)RpUnits_convert, METH_VARARGS|METH_KEYWORDS, 517 491 RpUnits_convert_doc}, 518 492 519 {NULL, NULL}/* sentinel */493 {NULL, NULL} /* sentinel */ 520 494 }; 521 495 … … 525 499 526 500 PyMODINIT_FUNC 527 initRpUnits(void) 528 { 529 PyObject *m; 530 531 /* Finalize the type object including setting type of the new type 532 * object; doing it here is required for portability to Windows 533 * without requiring C++. */ 534 if (PyType_Ready(&RpUnitsObjectType) < 0) 535 return; 536 537 /* Create the module and add the functions */ 538 m = Py_InitModule3("RpUnits", RpUnits_Methods, module_doc); 539 540 /* Add some symbolic constants to the module */ 541 if (ErrorObject == NULL) { 542 ErrorObject = PyErr_NewException("RpUnits.error", NULL, NULL); 543 if (ErrorObject == NULL) 544 return; 545 } 546 Py_INCREF(ErrorObject); 547 PyModule_AddObject(m, "error", ErrorObject); 548 501 initUnits(void) 502 { 503 PyObject *m; 504 505 /* Finalize the type object including setting type of the new type 506 * object; doing it here is required for portability to Windows 507 * without requiring C++. */ 508 if (PyType_Ready(&RpUnitsObjectType) < 0) 509 return; 510 511 /* Create the module and add the functions */ 512 m = Py_InitModule3("Units", RpUnits_Methods, module_doc); 513 514 /* Add some symbolic constants to the module */ 515 if (ErrorObject == NULL) { 516 ErrorObject = PyErr_NewException("RpUnits.error", NULL, NULL); 517 if (ErrorObject == NULL) 518 return; 519 } 520 Py_INCREF(ErrorObject); 521 PyModule_AddObject(m, "error", ErrorObject); 549 522 550 523 // add some standard units definitions and conversions. 551 524 552 525 RpUnits::addPresets("all"); 553 554 555 } 526 }
Note: See TracChangeset
for help on using the changeset viewer.