Only leak blobs that are bound, and only in glretrace.
def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
if function.name in self.array_pointer_function_names and arg.name == 'pointer':
- print ' %s = static_cast<%s>(%s.toPointer());' % (lvalue, arg_type, rvalue)
+ print ' %s = static_cast<%s>(%s.toPointer(true));' % (lvalue, arg_type, rvalue)
return
if function.name in self.draw_elements_function_names and arg.name == 'indices':
}
Blob::~Blob() {
- // TODO: Don't leak blobs. Blobs are often bound and accessed during many
- // calls, so we can't delete them here.
- //delete [] buf;
+ // Blobs are often bound and referred during many calls, so we can't delete
+ // them here in that case.
+ //
+ // Once bound there is no way to know when they were unbound, which
+ // effectively means we have to leak them. A better solution would be to
+ // keep a list of bound pointers, and defer the destruction to when the
+ // trace in question has been fully processed.
+ if (!bound) {
+ delete [] buf;
+ }
}
void * Blob ::toPointer(void) const { return buf; }
void * Pointer::toPointer(void) const { return (void *)value; }
+void * Value ::toPointer(bool bind) { assert(0); return NULL; }
+void * Null ::toPointer(bool bind) { return NULL; }
+void * Blob ::toPointer(bool bind) { if (bind) bound = true; return buf; }
+void * Pointer::toPointer(bool bind) { return (void *)value; }
+
// pointer cast
unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; }
virtual double toDouble(void) const;
virtual void *toPointer(void) const;
+ virtual void *toPointer(bool bind);
virtual unsigned long long toUIntPtr(void) const;
virtual const char *toString(void) const;
virtual float toFloat(void) const;
virtual double toDouble(void) const;
void *toPointer(void) const;
+ void *toPointer(bool bind);
unsigned long long toUIntPtr(void) const;
const char *toString(void) const;
void visit(Visitor &visitor);
Blob(size_t _size) {
size = _size;
buf = new char[_size];
+ bound = false;
}
~Blob();
bool toBool(void) const;
void *toPointer(void) const;
+ void *toPointer(bool bind);
void visit(Visitor &visitor);
size_t size;
char *buf;
+ bool bound;
};
bool toBool(void) const;
void *toPointer(void) const;
+ void *toPointer(bool bind);
unsigned long long toUIntPtr(void) const;
void visit(Visitor &visitor);
};