Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2018-06-15 09:02:23 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2018-06-15 09:02:23 +0300
commitcd71dd638245ad21e59e3f83229e926a285ccc45 (patch)
tree1c5fdeef0a37ebec1a1ade80ced18b27dd0482e6 /source/blender/blenlib
parentdec92e6ba1a1944c642ded967d7f65fc5d8e704a (diff)
parent27de412ca8de4edad99a46ebdb8aadd7003e42a6 (diff)
Merge branch 'blender2.8' into hair_guides
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_rand.h8
-rw-r--r--source/blender/blenlib/intern/path_util.c52
-rw-r--r--source/blender/blenlib/intern/rand.c21
3 files changed, 43 insertions, 38 deletions
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h
index 69b23b2473f..811a6ba1768 100644
--- a/source/blender/blenlib/BLI_rand.h
+++ b/source/blender/blenlib/BLI_rand.h
@@ -64,15 +64,9 @@ void BLI_rng_shuffle_array(struct RNG *rng, void *data, unsigned int elem
/** Note that skipping is as slow as generating n numbers! */
void BLI_rng_skip(struct RNG *rng, int n) ATTR_NONNULL(1);
-/** Seed for the random number generator, using noise.c hash[] */
-void BLI_srandom(unsigned int seed);
-
-/** Return a pseudo-random number N where 0<=N<(2^31) */
-int BLI_rand(void) ATTR_WARN_UNUSED_RESULT;
-
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
+/* !!!!! NOTE: DO NOT USE IT IN NEW CODE !!!!! */
float BLI_frand(void) ATTR_WARN_UNUSED_RESULT;
-void BLI_frand_unit_v3(float v[3]);
/** Return a pseudo-random (hash) float from an integer value */
float BLI_hash_frand(unsigned int seed) ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 0533126fe56..a3651de73a2 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -83,7 +83,7 @@ static bool BLI_path_is_abs(const char *name);
* \param tail Optional area to return copy of part of string following digits, or from dot if no digits.
* \param numlen Optional to return number of digits found.
*/
-int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *numlen)
+int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len)
{
uint nums = 0, nume = 0;
int i;
@@ -93,8 +93,12 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu
const uint lslash_len = lslash != NULL ? (int)(lslash - string) : 0;
uint name_end = string_len;
- while (name_end > lslash_len && string[--name_end] != '.') {} /* name ends at dot if present */
- if (name_end == lslash_len && string[name_end] != '.') name_end = string_len;
+ while (name_end > lslash_len && string[--name_end] != '.') {
+ /* name ends at dot if present */
+ }
+ if (name_end == lslash_len && string[name_end] != '.') {
+ name_end = string_len;
+ }
for (i = name_end - 1; i >= (int)lslash_len; i--) {
if (isdigit(string[i])) {
@@ -113,25 +117,35 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu
}
if (found_digit) {
- if (tail) strcpy(tail, &string[nume + 1]);
- if (head) {
- strcpy(head, string);
- head[nums] = 0;
+ const long long int ret = strtoll(&(string[nums]), NULL, 10);
+ if (ret >= INT_MIN && ret <= INT_MAX) {
+ if (tail) {
+ strcpy(tail, &string[nume + 1]);
+ }
+ if (head) {
+ strcpy(head, string);
+ head[nums] = 0;
+ }
+ if (r_num_len) {
+ *r_num_len = nume - nums + 1;
+ }
+ return (int)ret;
}
- if (numlen) *numlen = nume - nums + 1;
- return ((int)atoi(&(string[nums])));
}
- else {
- if (tail) strcpy(tail, string + name_end);
- if (head) {
- /* name_end points to last character of head,
- * make it +1 so null-terminator is nicely placed
- */
- BLI_strncpy(head, string, name_end + 1);
- }
- if (numlen) *numlen = 0;
- return 0;
+
+ if (tail) {
+ strcpy(tail, string + name_end);
+ }
+ if (head) {
+ /* name_end points to last character of head,
+ * make it +1 so null-terminator is nicely placed
+ */
+ BLI_strncpy(head, string, name_end + 1);
+ }
+ if (r_num_len) {
+ *r_num_len = 0;
}
+ return 0;
}
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 700524965f0..557f0d79270 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -268,26 +268,23 @@ void BLI_rng_skip(RNG *rng, int n)
/* initialize with some non-zero seed */
static RNG theBLI_rng = {611330372042337130};
-void BLI_srandom(unsigned int seed)
+static void ensure_rng_thread_safe(void)
{
- BLI_rng_srandom(&theBLI_rng, seed);
-}
-
-int BLI_rand(void)
-{
- return BLI_rng_get_int(&theBLI_rng);
+ /* TODO(sergey): Ideally we will get rid of all rng functions which
+ * are using global generator. But for until then we need some way to
+ * catch "bad" calls at runtime.
+ *
+ * NOTE: Lots of areas are not ported, so we keep check disabled for now.
+ */
+ // BLI_assert(BLI_thread_is_main());
}
float BLI_frand(void)
{
+ ensure_rng_thread_safe();
return BLI_rng_get_float(&theBLI_rng);
}
-void BLI_frand_unit_v3(float v[3])
-{
- BLI_rng_get_float_unit_v3(&theBLI_rng, v);
-}
-
float BLI_hash_frand(unsigned int seed)
{
RNG rng;