~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/gen_utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: gen_utils.c,v 1.48 2006/12/27 05:04:20 campbellbarton Exp $
 
2
 * $Id: gen_utils.c,v 1.56 2007/03/11 04:05:45 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
25
25
 *
26
26
 * This is a new part of Blender.
27
27
 *
28
 
 * Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Ken Hughes
 
28
 * Contributor(s): Michel Selten, Willian P. Germano, Alex Mole, Ken Hughes,
 
29
 * Campbell Barton
29
30
 *
30
31
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
31
32
*/
44
45
 
45
46
#include "constant.h"
46
47
 
47
 
//---------------------- EXPP_FloatsAreEqual -------------------------
48
 
//Floating point comparisons 
49
 
//floatStep = number of representable floats allowable in between
50
 
// float A and float B to be considered equal.
 
48
/*---------------------- EXPP_FloatsAreEqual -------------------------
 
49
  Floating point comparisons 
 
50
  floatStep = number of representable floats allowable in between
 
51
   float A and float B to be considered equal. */
51
52
int EXPP_FloatsAreEqual(float A, float B, int floatSteps)
52
53
{
53
54
        int a, b, delta;
63
64
                return 1;
64
65
    return 0;
65
66
}
66
 
//---------------------- EXPP_VectorsAreEqual -------------------------
67
 
//Builds on EXPP_FloatsAreEqual to test vectors
 
67
/*---------------------- EXPP_VectorsAreEqual -------------------------
 
68
  Builds on EXPP_FloatsAreEqual to test vectors */
68
69
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps){
69
70
 
70
71
        int x;
74
75
        }
75
76
        return 1;
76
77
}
77
 
//---------------------- EXPP_GetModuleConstant -------------------------
78
 
//Helper function for returning a module constant
 
78
/*---------------------- EXPP_GetModuleConstant -------------------------
 
79
  Helper function for returning a module constant */
79
80
PyObject *EXPP_GetModuleConstant(char *module, char *constant)
80
81
{
81
82
        PyObject *py_module = NULL, *py_dict = NULL, *py_constant = NULL;
83
84
        /*Careful to pass the correct Package.Module string here or
84
85
        * else you add a empty module somewhere*/
85
86
        py_module = PyImport_AddModule(module);
86
 
        if(!py_module){   //null = error returning module
 
87
        if(!py_module){   /*null = error returning module*/
87
88
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
88
89
                        "error encountered with returning module constant..." ) );
89
90
        }
90
 
        py_dict = PyModule_GetDict(py_module); //never fails
 
91
        py_dict = PyModule_GetDict(py_module); /*never fails*/
91
92
 
92
93
        py_constant = PyDict_GetItemString(py_dict, constant);
93
 
        if(!py_constant){   //null = key not found
 
94
        if(!py_constant){   /*null = key not found*/
94
95
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
95
96
                        "error encountered with returning module constant..." ) );
96
97
        }
133
134
        return ( strcmp( string1, string2 ) == 0 );
134
135
}
135
136
 
136
 
/*****************************************************************************/
137
 
/* Description: This function returns the name of the given ID struct    */
138
 
/*               without the Object type identifying characters prepended.   */
139
 
/*****************************************************************************/
140
 
char *GetIdName( ID * id )
141
 
{
142
 
        return ( ( id->name ) + 2 );
143
 
}
144
 
 
145
 
/*****************************************************************************/
146
 
/* Description: This function returns the ID of the object with given name   */
147
 
/*              from a given list.                                          */
148
 
/*****************************************************************************/
149
 
ID *GetIdFromList( ListBase * list, char *name )
150
 
{
151
 
        ID *id = list->first;
152
 
 
153
 
        while( id ) {
154
 
                if( strcmp( name, id->name + 2 ) == 0 )
155
 
                        break;
156
 
                id = id->next;
157
 
        }
158
 
 
159
 
        return id;
160
 
}
161
 
 
162
 
/*****************************************************************************/
163
 
/* Description: This function sets the fake user status of the ID            */
164
 
/* returns an int error, so from getsetattrs                                 */
165
 
/*****************************************************************************/
166
 
int SetIdFakeUser( ID * id, PyObject *value)
167
 
{
168
 
        int param;
169
 
        param = PyObject_IsTrue( value );
170
 
        if( param == -1 )
171
 
                return EXPP_ReturnIntError( PyExc_TypeError,
172
 
                                "expected int argument in range [0,1]" );
173
 
        
174
 
        if (param) {
175
 
                if (!(id->flag & LIB_FAKEUSER)) {
176
 
                        id->flag |= LIB_FAKEUSER;
177
 
                        id_us_plus(id);
178
 
                }
179
 
        } else {
180
 
                if (id->flag & LIB_FAKEUSER) {
181
 
                        id->flag &= ~LIB_FAKEUSER;
182
 
                        id->us--;
183
 
                }
184
 
        }
185
 
        return 0;
186
 
}
187
 
 
188
 
 
189
137
 
190
138
/*****************************************************************************/
191
139
/* Description: These functions set an internal string with the given type   */
204
152
        return -1;
205
153
}
206
154
 
207
 
 
208
155
int EXPP_intError(PyObject *type, const char *format, ...)
209
156
{
210
157
        PyObject *error;
218
165
        Py_DECREF(error);
219
166
        return -1;
220
167
}
221
 
//Like EXPP_ReturnPyObjError but takes a printf format string and multiple arguments
 
168
/*Like EXPP_ReturnPyObjError but takes a printf format string and multiple arguments*/
222
169
PyObject *EXPP_objError(PyObject *type, const char *format, ...)
223
170
{
224
171
        PyObject *error;
443
390
        char *eventname = NULL;
444
391
        int i, event = 0;
445
392
 
 
393
        list = PyList_New( 0 );
 
394
 
 
395
        if( !PyArg_ParseTuple( args, "s", &eventname ) )
 
396
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
397
                                              "expected event name (string) as argument" );
 
398
 
446
399
        /* actually !scriptlink shouldn't happen ... */
447
400
        if( !slink || !slink->totscript )
448
 
                return EXPP_incr_ret( Py_None );
449
 
 
450
 
        if( !PyArg_ParseTuple( args, "s", &eventname ) )
451
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
452
 
                                              "expected event name (string) as argument" );
453
 
 
454
 
        list = PyList_New( 0 );
 
401
                return list;
 
402
        
455
403
        if( !list )
456
404
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
457
405
                                              "couldn't create PyList!" );